Source Code Cross Referenced for MySwingJMenu.java in  » Web-Framework » webonswing » examples » swingdemos » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Web Framework » webonswing » examples.swingdemos 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package examples.swingdemos;
002:
003:        import java.awt.*;
004:        import java.awt.event.*;
005:
006:        import javax.swing.*;
007:
008:        public class MySwingJMenu extends JApplet implements  ActionListener {
009:
010:            JMenu objJMenuFile;
011:            JMenu objJMenuEdit;
012:            JMenu objJMenuAction;
013:
014:            JLabel lblMsg;
015:
016:            //-----------------------------------------------------------------------
017:            public void init() {
018:                //-----------------------------------------------------------------------
019:
020:                Container objContainer = super .getContentPane();
021:                objContainer.setBackground(Color.white);
022:
023:                buildJMenuFile();
024:                buildJMenuEdit();
025:                buildJMenuAction();
026:
027:                //zzz Need to add: CheckboxMenuItem
028:
029:                JMenuBar objJMenuBar = new JMenuBar();
030:
031:                super .setJMenuBar(objJMenuBar);
032:                objJMenuBar.add(objJMenuFile);
033:                objJMenuBar.add(objJMenuEdit);
034:                objJMenuBar.add(objJMenuAction);
035:
036:                lblMsg = new JLabel("Messages displayed here.");
037:
038:                objContainer.add(lblMsg);
039:
040:            }
041:
042:            //-----------------------------------------------------------------------
043:            private void buildJMenuFile() {
044:                //-----------------------------------------------------------------------
045:
046:                JMenuItem objJMenuItem;
047:
048:                objJMenuFile = new JMenu("File");
049:
050:                objJMenuItem = new JMenuItem("New"); //New
051:                objJMenuItem.addActionListener(this );
052:                objJMenuFile.add(objJMenuItem);
053:
054:                objJMenuItem = new JMenuItem("Open"); //Open...
055:                objJMenuItem.addActionListener(this );
056:                objJMenuFile.add(objJMenuItem);
057:
058:                objJMenuItem = new JMenuItem("Save"); //Save
059:                objJMenuItem.addActionListener(this );
060:                objJMenuFile.add(objJMenuItem);
061:
062:                objJMenuItem = new JMenuItem("Save As"); //Save As...
063:                objJMenuItem.addActionListener(this );
064:                objJMenuFile.add(objJMenuItem);
065:
066:                objJMenuFile.addSeparator(); //add a horizontal separator line
067:
068:                objJMenuItem = new JMenuItem("Quit"); //Quit
069:                objJMenuItem.addActionListener(this );
070:                objJMenuFile.add(objJMenuItem);
071:            }
072:
073:            //-----------------------------------------------------------------------
074:            private void buildJMenuEdit() {
075:                //-----------------------------------------------------------------------
076:
077:                JMenuItem objJMenuItem;
078:
079:                objJMenuEdit = new JMenu("Edit");
080:
081:                objJMenuItem = new JMenuItem("Undo");
082:                objJMenuItem.addActionListener(this );
083:                objJMenuEdit.add(objJMenuItem);
084:
085:                objJMenuItem = new JMenuItem("Redo");
086:                objJMenuItem.addActionListener(this );
087:                objJMenuEdit.add(objJMenuItem);
088:
089:                objJMenuEdit.addSeparator();
090:
091:                objJMenuItem = new JMenuItem("Cut");
092:                objJMenuItem.addActionListener(this );
093:                objJMenuEdit.add(objJMenuItem);
094:
095:                objJMenuItem = new JMenuItem("Copy");
096:                objJMenuItem.addActionListener(this );
097:                objJMenuEdit.add(objJMenuItem);
098:
099:                objJMenuItem = new JMenuItem("Paste");
100:                objJMenuItem.addActionListener(this );
101:                objJMenuEdit.add(objJMenuItem);
102:
103:                objJMenuItem = new JMenuItem("Delete");
104:                objJMenuItem.addActionListener(this );
105:                objJMenuEdit.add(objJMenuItem);
106:
107:                objJMenuEdit.addSeparator();
108:
109:                objJMenuItem = new JMenuItem("Find");
110:                objJMenuItem.addActionListener(this );
111:                objJMenuEdit.add(objJMenuItem);
112:
113:                objJMenuItem = new JMenuItem("Replace");
114:                objJMenuItem.addActionListener(this );
115:                objJMenuEdit.add(objJMenuItem);
116:
117:            }
118:
119:            //-----------------------------------------------------------------------
120:            private void buildJMenuAction() {
121:                //-----------------------------------------------------------------------
122:
123:                JMenuItem objJMenuItem;
124:                JMenu objJMenu_Sub;
125:                JRadioButtonMenuItem objJRBtnMenuItem;
126:                JCheckBoxMenuItem objJCBoxMenuItem;
127:
128:                objJMenuAction = new JMenu("Action");
129:
130:                //******************************
131:
132:                objJMenu_Sub = new JMenu("Sub 1");
133:
134:                objJMenuItem = new JMenuItem("Sub 1, Item 1");
135:                objJMenuItem.addActionListener(this );
136:                objJMenu_Sub.add(objJMenuItem);
137:
138:                objJMenuItem = new JMenuItem("Sub 1, Item 2");
139:                objJMenuItem.addActionListener(this );
140:                objJMenu_Sub.add(objJMenuItem);
141:
142:                objJMenuItem = new JMenuItem("Sub 1, Item 3");
143:                objJMenuItem.addActionListener(this );
144:                objJMenu_Sub.add(objJMenuItem);
145:
146:                objJMenuAction.add(objJMenu_Sub);
147:
148:                //******************************
149:
150:                objJMenu_Sub = new JMenu("Sub 2");
151:
152:                objJMenuItem = new JMenuItem("Sub 2, Item 1");
153:                objJMenuItem.addActionListener(this );
154:                objJMenu_Sub.add(objJMenuItem);
155:
156:                objJMenuItem = new JMenuItem("Sub 2, Item 2");
157:                objJMenuItem.addActionListener(this );
158:                objJMenu_Sub.add(objJMenuItem);
159:
160:                objJMenuAction.add(objJMenu_Sub);
161:
162:                //******************************
163:
164:                objJMenuAction.addSeparator();
165:
166:                //******************************
167:
168:                objJMenu_Sub = new JMenu("Sub 3");
169:
170:                ButtonGroup objButtonGroup = new ButtonGroup();
171:
172:                objJRBtnMenuItem = new JRadioButtonMenuItem("Radio 1");
173:                objJRBtnMenuItem.setSelected(true);
174:                objJRBtnMenuItem.addActionListener(this );
175:                objJMenu_Sub.add(objJRBtnMenuItem);
176:                objButtonGroup.add(objJRBtnMenuItem); //Groups the radio buttons together.
177:
178:                objJRBtnMenuItem = new JRadioButtonMenuItem("Radio 2");
179:                objJRBtnMenuItem.addActionListener(this );
180:                objJMenu_Sub.add(objJRBtnMenuItem);
181:                objButtonGroup.add(objJRBtnMenuItem); //Groups the radio buttons together.
182:
183:                objJRBtnMenuItem = new JRadioButtonMenuItem("Radio 2");
184:                objJRBtnMenuItem.addActionListener(this );
185:                objJMenu_Sub.add(objJRBtnMenuItem);
186:                objButtonGroup.add(objJRBtnMenuItem); //Groups the radio buttons together.
187:
188:                objJMenu_Sub.addSeparator();
189:
190:                objJCBoxMenuItem = new JCheckBoxMenuItem("Check Box 1");
191:                objJCBoxMenuItem.setSelected(true);
192:                objJCBoxMenuItem.addActionListener(this );
193:                objJMenu_Sub.add(objJCBoxMenuItem);
194:
195:                objJCBoxMenuItem = new JCheckBoxMenuItem("Check Box 2");
196:                objJCBoxMenuItem.setSelected(false);
197:                objJCBoxMenuItem.addActionListener(this );
198:                objJMenu_Sub.add(objJCBoxMenuItem);
199:
200:                objJCBoxMenuItem = new JCheckBoxMenuItem("Check Box 3");
201:                objJCBoxMenuItem.setSelected(true);
202:                objJCBoxMenuItem.addActionListener(this );
203:                objJMenu_Sub.add(objJCBoxMenuItem);
204:
205:                //zzz Note:  Need to add .addItemListener to JCheckBoxMenuItem
206:                //           Also add code to show selected vs deselected for Radio & Checkbox.
207:
208:                objJMenuAction.add(objJMenu_Sub);
209:
210:            }
211:
212:            //-----------------------------------------------------------------------
213:            public void actionPerformed(ActionEvent event) {
214:                //-----------------------------------------------------------------------
215:
216:                String strMenuName;
217:
218:                strMenuName = event.getActionCommand();
219:
220:                if (strMenuName.equals("Quit")) {
221:                    System.exit(0);
222:                } else {
223:                    lblMsg.setText(strMenuName + " choosen.");
224:                }
225:            }
226:
227:            //-----------------------------------------------------------------------
228:            public static void main(String args[]) {
229:                //-----------------------------------------------------------------------
230:
231:                JFrame app = new JFrame("Swing Menu's");
232:                app.setSize(400, 200); //set Frame: width, height
233:
234:                app.addWindowListener(//Register an anonymous class as a listener.
235:                        new WindowAdapter() {
236:                            public void windowClosing(WindowEvent e) {
237:                                System.exit(0);
238:                            }
239:                        });
240:
241:                MySwingJMenu applet = new MySwingJMenu(); //create the applet.
242:                applet.init(); //initialize applet.
243:                applet.start(); //start applet.
244:
245:                app.getContentPane().add(applet, BorderLayout.CENTER); //add applet to center of frame.
246:                app.setVisible(true); //Make frame visible.
247:
248:            } //main()
249:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.