Results 1 to 6 of 6
Thread: Menu not getting displayed!
- 03-12-2012, 11:00 AM #1
Member
- Join Date
- Feb 2012
- Posts
- 23
- Rep Power
- 0
Menu not getting displayed!
Hi guys! The below code opens the applet and the frame, but nothing is really getting displayed.. What could be the problem?
Java Code:import java.awt.*; import java.applet.*; import java.awt.event.*; class MenuDemo extends Frame { String msg = " "; MenuDemo(String title){ super(title); //create menu bar and add it to frame MenuBar mbar = new MenuBar(); setMenuBar(mbar); // create the menu items Menu File = new Menu("file"); MenuItem item1 = new MenuItem("New"); MenuItem item2 = new MenuItem("Open"); File.add(item1); File.add(item2); mbar.add(File); MyMenuHandler handler = new MyMenuHandler(this); // register it to receive those events item1.addActionListener(handler); item2.addActionListener(handler); MyWindowAdapter adapter = new MyWindowAdapter(this); // register it to receive those events addWindowListener(adapter); } class MyWindowAdapter extends WindowAdapter{ MenuDemo menuFrame; public MyWindowAdapter(MenuDemo menuFrame){ this.menuFrame = menuFrame; } public void windowClosing(WindowEvent we){ menuFrame.setVisible(false); } } class MyMenuHandler implements ActionListener, ItemListener { MenuDemo menuFrame; public MyMenuHandler(MenuDemo menuFrame) { this.menuFrame = menuFrame; } // Handle action events public void actionPerformed(ActionEvent ae) { String msg = "You selected "; String arg = (String)ae.getActionCommand(); if(arg.equals("New...")) msg += "New."; else if(arg.equals("Open...")) msg += "Open."; } public void itemStateChanged(ItemEvent ie) { menuFrame.repaint(); } } public void paint(Graphics g) { g.drawString(msg, 10, 10); } } public class MenuFrame extends Applet { Frame f; public void init(){ f = new MenuDemo("Menu Demo"); int width = Integer.parseInt(getParameter("width")); int height = Integer.parseInt(getParameter("height")); setSize(new Dimension(width, height)); f.setSize(width,height); f.setVisible(true); } public void start() { f.setVisible(true); } public void stop() { f.setVisible(false); } }Last edited by javabeginner29; 03-12-2012 at 11:02 AM.
- 03-12-2012, 11:16 AM #2
Re: Menu not getting displayed!
Moved from New to Java
dbWhy do they call it rush hour when nothing moves? - Robin Williams
- 03-12-2012, 11:17 AM #3
Re: Menu not getting displayed!
Why are you using the antiquated AWT when Swing has been around for more than 10 years?
dbWhy do they call it rush hour when nothing moves? - Robin Williams
- 03-12-2012, 11:43 AM #4
Member
- Join Date
- Feb 2012
- Posts
- 23
- Rep Power
- 0
Re: Menu not getting displayed!
Im trying to learn core java...I am still not familiar with swing...
- 03-12-2012, 11:55 AM #5
Re: Menu not getting displayed!
Swing *is* part of core Java, and has been for more than 10 years.
Would you opt to learn driving in one of these?
dbWhy do they call it rush hour when nothing moves? - Robin Williams
- 03-12-2012, 11:58 AM #6
Member
- Join Date
- Feb 2012
- Posts
- 23
- Rep Power
- 0
Similar Threads
-
Same name displayed twice!
By javabeginner29 in forum New To JavaReplies: 2Last Post: 02-24-2012, 06:17 AM -
Fill a menu dynamically when menu is shown
By Java Tip in forum SWTReplies: 0Last Post: 07-07-2008, 04:47 PM -
How to use SWT menu and menu event
By Java Tip in forum SWTReplies: 0Last Post: 07-07-2008, 04:46 PM -
React to menu action and checkbox menu
By Java Tip in forum javax.swingReplies: 0Last Post: 06-27-2008, 07:50 PM -
how to create Popup Menu with Sub Menu while right-clicking the JTree Node??
By Kabiraa in forum AWT / SwingReplies: 7Last Post: 05-09-2008, 07:54 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks