J
justineee
Hi again everyone,
I am quite new to java and this is what I have with my project..
My problem is.. the compiler cannot find menu item "exitItem" in the
actionPerformed method..
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
public class MainFrame extends JPanel implements ActionListener {
private JButton displayButton;
private JButton findButton;
private JButton addButton;
private JTextArea displayWords;
private JMenuBar menuBar;
private JTextField wordInput;
private JTextField inputWord;
private JLabel mpLabel;
private JButton deleteButton;
public MainFrame()
{
JMenu fileMenu = new JMenu ("File");
JMenuItem exitItem = new JMenuItem ("Exit");
JMenuItem loadItem = new JMenuItem ("Load");
JMenu configureMenu = new JMenu ("Configure");
JMenuItem setwordsItem = new JMenuItem ("Set number of
words");
JMenu helpMenu = new JMenu ("Help");
JMenuItem contentsItem = new JMenuItem ("Contents");
JMenuItem aboutItem = new JMenuItem ("About");
fileMenu.add (loadItem);
fileMenu.add (exitItem);
configureMenu.add (setwordsItem);
helpMenu.add (aboutItem);
helpMenu.add (contentsItem);
displayButton = new JButton ("Display Words");
findButton = new JButton ("Find");
addButton = new JButton ("Add");
displayWords = new JTextArea (5, 5);
menuBar = new JMenuBar();
menuBar.add (fileMenu);
menuBar.add (configureMenu);
menuBar.add (helpMenu);
wordInput = new JTextField (6);
inputWord = new JTextField (5);
mpLabel = new JLabel ("E-Dictionary v1.0");
deleteButton = new JButton ("Delete");
displayButton.setToolTipText ("Display all words");
findButton.setToolTipText ("Find a word");
addButton.setToolTipText ("Add a word");
deleteButton.setToolTipText ("Delete a word");
setPreferredSize (new Dimension (281, 460));
setLayout (null);
add (displayButton);
add (findButton);
add (addButton);
add (displayWords);
add (menuBar);
add (wordInput);
add (inputWord);
add (mpLabel);
add (deleteButton);
displayButton.addActionListener(this);
findButton.addActionListener(this);
addButton.addActionListener(this);
deleteButton.addActionListener(this);
exitItem.addActionListener(this);
setwordsItem.addActionListener(this);
fileMenu.setMnemonic('F');
exitItem.setMnemonic('X');
configureMenu.setMnemonic('C');
helpMenu.setMnemonic('H');
loadItem.setMnemonic('L');
displayButton.setBounds (10, 400, 145, 30);
findButton.setBounds (175, 40, 95, 25);
addButton.setBounds (10, 365, 70, 25);
displayWords.setBounds (10, 75, 260, 280);
menuBar.setBounds (0, 0, 705, 25);
wordInput.setBounds (90, 365, 180, 25);
inputWord.setBounds (10, 40, 155, 25);
mpLabel.setBounds (5, 440, 135, 25);
deleteButton.setBounds (165, 400, 110, 30);
displayWords.setEditable(false);
}
public void actionPerformed (ActionEvent jnd)
{
if(jnd.getSource() == exitItem)
{
System.exit(0);
}
}
}
Can anyone pls give me some tips?
Thanks
Justine
I am quite new to java and this is what I have with my project..
My problem is.. the compiler cannot find menu item "exitItem" in the
actionPerformed method..
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
public class MainFrame extends JPanel implements ActionListener {
private JButton displayButton;
private JButton findButton;
private JButton addButton;
private JTextArea displayWords;
private JMenuBar menuBar;
private JTextField wordInput;
private JTextField inputWord;
private JLabel mpLabel;
private JButton deleteButton;
public MainFrame()
{
JMenu fileMenu = new JMenu ("File");
JMenuItem exitItem = new JMenuItem ("Exit");
JMenuItem loadItem = new JMenuItem ("Load");
JMenu configureMenu = new JMenu ("Configure");
JMenuItem setwordsItem = new JMenuItem ("Set number of
words");
JMenu helpMenu = new JMenu ("Help");
JMenuItem contentsItem = new JMenuItem ("Contents");
JMenuItem aboutItem = new JMenuItem ("About");
fileMenu.add (loadItem);
fileMenu.add (exitItem);
configureMenu.add (setwordsItem);
helpMenu.add (aboutItem);
helpMenu.add (contentsItem);
displayButton = new JButton ("Display Words");
findButton = new JButton ("Find");
addButton = new JButton ("Add");
displayWords = new JTextArea (5, 5);
menuBar = new JMenuBar();
menuBar.add (fileMenu);
menuBar.add (configureMenu);
menuBar.add (helpMenu);
wordInput = new JTextField (6);
inputWord = new JTextField (5);
mpLabel = new JLabel ("E-Dictionary v1.0");
deleteButton = new JButton ("Delete");
displayButton.setToolTipText ("Display all words");
findButton.setToolTipText ("Find a word");
addButton.setToolTipText ("Add a word");
deleteButton.setToolTipText ("Delete a word");
setPreferredSize (new Dimension (281, 460));
setLayout (null);
add (displayButton);
add (findButton);
add (addButton);
add (displayWords);
add (menuBar);
add (wordInput);
add (inputWord);
add (mpLabel);
add (deleteButton);
displayButton.addActionListener(this);
findButton.addActionListener(this);
addButton.addActionListener(this);
deleteButton.addActionListener(this);
exitItem.addActionListener(this);
setwordsItem.addActionListener(this);
fileMenu.setMnemonic('F');
exitItem.setMnemonic('X');
configureMenu.setMnemonic('C');
helpMenu.setMnemonic('H');
loadItem.setMnemonic('L');
displayButton.setBounds (10, 400, 145, 30);
findButton.setBounds (175, 40, 95, 25);
addButton.setBounds (10, 365, 70, 25);
displayWords.setBounds (10, 75, 260, 280);
menuBar.setBounds (0, 0, 705, 25);
wordInput.setBounds (90, 365, 180, 25);
inputWord.setBounds (10, 40, 155, 25);
mpLabel.setBounds (5, 440, 135, 25);
deleteButton.setBounds (165, 400, 110, 30);
displayWords.setEditable(false);
}
public void actionPerformed (ActionEvent jnd)
{
if(jnd.getSource() == exitItem)
{
System.exit(0);
}
}
}
Can anyone pls give me some tips?
Thanks
Justine