need help on actionlistener....i have 2 use action listener to open a new Jframe from my Main JFrame...wat i have to do is when i click my MenuItem (ex. File, open), a new frame is opened...
here is my Mainframe
CODE:
import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.border.*; public class menu extends JFrame{ private JMenuBar jmMenuBar; private JMenu jmFile; private JMenuItem jmNew; public menu(){ JMenuBar jmbMenuBar = new JMenuBar(); JMenu jmFile = new JMenu ("File"); JMenuItem jmiOpen = new JMenuItem ("Open"); JMenuItem jmiSave = new JMenuItem ("Save"); JMenuItem jmiSaveAs = new JMenuItem ("SaveAs"); jmFile.add(jmiOpen); jmFile.add(jmiSave); jmFile.add(jmiSaveAs); jmbMenuBar.add(jmFile); JMenu jmEdit = new JMenu ("Edit"); JMenuItem jmiCut = new JMenuItem ("Cut"); JMenuItem jmiCopy = new JMenuItem ("Copy"); JMenuItem jmiPaste = new JMenuItem ("Paste"); jmEdit.add(jmiCut); jmEdit.add(jmiCopy); jmEdit.add(jmiPaste); jmbMenuBar.add(jmEdit); JMenu jmView = new JMenu ("View"); JMenuItem jmiToolBar = new JMenuItem ("ToolBar"); JMenuItem jmiStatusBar = new JMenuItem ("StatusBar"); JMenuItem jmiFormatBar = new JMenuItem ("FormatBar"); jmView.add(jmiToolBar); jmView.add(jmiStatusBar); jmView.add(jmiFormatBar); jmbMenuBar.add(jmView); setJMenuBar (jmbMenuBar); } public static void main (String[]args){ menu myApp = new menu(); myApp.setSize(500,400); myApp.setTitle("BSIT II-O"); myApp.setLocation(0,0); myApp.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); myApp.setVisible(true); } } and this is the second frame that should be opened when i click on my MenuItem from my Main Frame import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.border.*; public class Menu extends Jframe{ private JLabel jlbName; private JTextField jtfName; private JButton jbSave; private FlowLayout flLayout; public Menu (){ jlbName = new JLabel ("Name"); jtfName = new JTextField (30); jbSave = new JButton ("Save"); flLayout = new FlowLayout (); add(jlbName); add(jtfName); add(jbSave); jlbName.setForeground (Color.BLUE); jtfName.setBackground (Color.PINK); jtfName.setFont (new Font ("Vivaldi",3,12)); setLayout (flLayout); } public static void main (String args[]){ Menu form = new Menu (); form.setLocation (100,200); form.setSize(800,600); form.setTitle ("BSIT II-O"); form.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); form.setVisible(true); } }
I think i have to use actionListener but i dont know how to...can someone help me with my problem...?Plzzzz....tnx in advance...