It would be helpful if you told us what the error was that you were getting.
On Thu, Apr 29, 2010 at 13:53, chai war <[email protected]> wrote: > Something is wrong in the following program but I don't know where is the > error. > > import java.awt.*; > import java.awt.event.*; > public class WindowMenu extends Frame implements ActionListener > { > private TextArea output; > > public WindowMenu() > { > super("A Simple Window Application with a Menu"); > addWindowListener(new WindowMenu.WindowEventHandler()); > > Toolkit toolkit = getToolkit(); > Dimension wndSize = toolkit.getScreenSize(); > > initializeMenu(); > > setLayout (new BorderLayout()); > > output = new TextArea(5,30); > output.setEditable(false); > > add("Center", output); > > setBounds (wndSize.width/4, wndSize.height/4, wndSize.width/2, > wndSize.height/2); > setVisible(true); > } > > private void initializeMenu() > { > MenuBar menuBar=new MenuBar(); > setMenuBar(menuBar); > > Menu fileMenu = new Menu("File"); > > MenuItem textDocItem = new MenuItem("Text Document"); > MenuItem javaDocItem = new MenuItem("Java Document"); > > textDocItem.setActionCommand("TEXT Document"); > javaDocItem.setActionCommand("JAVA Document"); > > textDocItem.addActionListener(this); > javaDocItem.addActionListener(this); > > Menu newMenu = new Menu ("New"); > > newMenu.add(textDocItem); > newMenu.add(javaDocItem); > > fileMenu.add(newMenu); > > MenuItem openItem = new MenuItem("Open"); > MenuItem closeItem = new MenuItem("Close"); > MenuItem saveItem = new MenuItem("Save"); > MenuItem saveAsItem = new MenuItem("Save As..."); > MenuItem printItem = new MenuItem("Print"); > > openItem.setActionCommand("OPEN"); > closeItem.setActionCommand("CLOSE"); > saveItem.setActionCommand("SAVE"); > saveAsItem.setActionCommand("SAVE AS"); > printItem.setActionCommand("PRINT"); > > openItem.addActionListener(this); > closeItem.addActionListener(this); > saveItem.addActionListener(this); > saveAsItem.addActionListener(this); > printItem.addActionListener(this); > > fileMenu.add(openItem); > fileMenu.add(closeItem); > fileMenu.addSeparator(); > fileMenu.add(saveItem); > fileMenu.add(saveAsItem); > fileMenu.addSeparator(); > fileMenu.add(printItem); > > menuBar.add(fileMenu); > } > > public void actionPerformed(ActionEvent e) > { > output.append(e.getActionCommand() + "Menu Item was clicked.\n"); > } > > public static void main (String[] args) > { > WindowMenu app =new WindowMenu(); > } > > class WindowEventHandler extends WindowAdapter > { > public void windowClosing(WindowEvent e) > { > System.exit(0); > } > } > } > > Thanks. > CW > > -- > To post to this group, send email to > [email protected] > To unsubscribe from this group, send email to > [email protected] > For more options, visit this group at > http://groups.google.com/group/javaprogrammingwithpassion?hl=en -- Mehul N. Sanghvi email: [email protected] -- To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/javaprogrammingwithpassion?hl=en
