473,498 Members | 37 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

GUI help

122 New Member
Hello Everyone:
I need some help with a GUI project.
What I want to do is when someone select the File Menu and chose New a Jpanel will open.

I have tried to write the code which is called class labelListener implements ActionListener. The Bold font is where I need help in...

Here is the code I have so far
public class GUIMenu extends JFrame {

Expand|Select|Wrap|Line Numbers
  1.     public GUIMenu() {
  2.  
  3.         super("Menus");
  4.         setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  5.  
  6.  
  7.         //Build first menu in the menu bar.
  8.         JMenuItem f1 = new JMenuItem("New");
  9.         f1.setMnemonic(KeyEvent.VK_N);
  10.         f1.getAccessibleContext().setAccessibleDescription(
  11.         "If this was working you could open a new file");
  12.  
  13.         JMenuItem f2 = new JMenuItem("Open");
  14.         f2.setMnemonic(KeyEvent.VK_O);
  15.         f2.addActionListener(new labelListener());//loads/sets the listener
  16.         JMenuItem f3 = new JMenuItem("Exit");
  17.         f3.setMnemonic(KeyEvent.VK_E);
  18.         f3.addActionListener(new exitListener());//loads/sets the listener
  19.  
  20.         //Build second menu in the menu bar.
  21.         JMenuItem e1 = new JMenuItem("Copy");
  22.         e1.setMnemonic(KeyEvent.VK_C);
  23.         JMenuItem e2 = new JMenuItem("Cut");
  24.         e2.setMnemonic(KeyEvent.VK_X);
  25.         JMenuItem e3 = new JMenuItem("Paste");
  26.         e3.setMnemonic(KeyEvent.VK_P);
  27.  
  28.         //Build third menu in the menu bar.
  29.         JMenuItem a1 = new JMenuItem("Close");
  30.         a1.setMnemonic(KeyEvent.VK_D);
  31.         a1.addActionListener(new exitListener());//loads/sets the listener
  32.  
  33.         //Create the menu bar.
  34.         JMenuBar menubar = new JMenuBar();
  35.  
  36.         //Build the first menu.
  37.         JMenu menu = new JMenu("File");
  38.         menu.add(f1);
  39.         menu.add(f2);
  40.         menu.addSeparator();
  41.         menu.add(f3);
  42.         menubar.add(menu);
  43.  
  44.         //Build the Second menu.
  45.         JMenu menu2 = new JMenu("Edit");
  46.         menu2.add(e1);
  47.         menu2.add(e2);
  48.         menu2.add(e3);
  49.         menubar.add(menu2);
  50.  
  51.         //Build the Third menu.
  52.         JMenu menu3 = new JMenu("Close the program");
  53.         menu3.add(a1);
  54.         menubar.add(menu3);
  55.  
  56.         // prepare user interface
  57.         JTextArea edit = new JTextArea(8, 40);
  58.         JScrollPane scroll = new JScrollPane(edit);
  59.         BorderLayout bord = new BorderLayout();
  60.         setLayout(bord);
  61.  
  62.         add("Center", scroll);
  63.         setJMenuBar(menubar);
  64.         pack();
  65.         setVisible(true);
  66.     }
  67.  
  68.     //inner class Section used for exit on menu 3 for fun
  69.     class exitListener implements ActionListener {
  70.  
  71.         public void actionPerformed(ActionEvent arg0) {
  72.  
  73.                 int x = JOptionPane.showOptionDialog(GUIMenu.this, "Exit Program?",
  74.                                 "Exit Request", JOptionPane.YES_NO_OPTION,
  75.                                 JOptionPane.QUESTION_MESSAGE, null, null,
  76.                                 JOptionPane.NO_OPTION);
  77.                 if (x == JOptionPane.YES_OPTION) {
  78.                     GUIMenu.this.dispose();
  79.                 }//close the if statement
  80.         }//close public void actionPerformed
  81. }//close the class exitListener
  82.  
  83. class labelListener implements ActionListener {
  84.     public void actionPerformed(ActionEvent arg0) {
  85.         String[] formats = { "Atom", "RSS 0.92", "RSS 1.0", "RSS 2.0" };
  86.         JPanel JPanelPane;
  87.         JPanel x = JPanelPane = new JPanel();
  88.             JLabel formatLabel = new JLabel("Output formats:");
  89.             rootPane.add(formatLabel);
  90.             JComboBox formatBox = null;
  91.             for (int i = 0; i < formats.length; i++)
  92.                 formatBox.addItem(formats[i]);
  93.             rootPane.add(formatBox);
  94.             add(rootPane);
  95.             setVisible(true);
  96.             {
  97.                 GUIMenu.this.dispose();
  98.     }
  99. }
  100. }
  101.     public static void main(String[] arguments) {
  102.         GUIMenu frame = new GUIMenu();
  103.     }
  104. }
Any help would be great
thanks
sandyw
May 13 '07 #1
0 1009

Sign in to post your reply or Sign up for a free account.

Similar topics

21
6482
by: Dave | last post by:
After following Microsofts admonition to reformat my system before doing a final compilation of my app I got many warnings/errors upon compiling an rtf file created in word. I used the Help...
9
4370
by: Tom | last post by:
A question for gui application programmers. . . I 've got some GUI programs, written in Python/wxPython, and I've got a help button and a help menu item. Also, I've got a compiled file made with...
6
4298
by: wukexin | last post by:
Help me, good men. I find mang books that introduce bit "mang header files",they talk too bit,in fact it is my too fool, I don't learn it, I have do a test program, but I have no correct doing...
3
3316
by: Colin J. Williams | last post by:
Python advertises some basic service: C:\Python24>python Python 2.4.1 (#65, Mar 30 2005, 09:13:57) on win32 Type "help", "copyright", "credits" or "license" for more information. >>> With...
7
5340
by: Corepaul | last post by:
Missing Help Files When I enter "recordset" as the keyword and search the Visual Basic Help index, I get many topics of interest in the resulting list. But there isn't any information available...
5
3247
by: Steve | last post by:
I have written a help file (chm) for a DLL and referenced it using Help.ShowHelp My expectation is that a developer using my DLL would be able to access this help file during his development time...
8
3203
by: Mark | last post by:
I have loaded Visual Studio .net on my home computer and my laptop, but my home computer has an abbreviated help screen not 2% of the help on my laptop. All the settings look the same on both...
10
3324
by: JonathanOrlev | last post by:
Hello everybody, I wrote this comment in another message of mine, but decided to post it again as a standalone message. I think that Microsoft's Office 2003 help system is horrible, probably...
1
6110
by: trunxnirvana007 | last post by:
'UPGRADE_WARNING: Array has a new behavior. Click for more: 'ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?keyword="9B7D5ADD-D8FE-4819-A36C-6DEDAF088CC7"' 'UPGRADE_WARNING: Couldn't resolve...
0
2843
by: hitencontractor | last post by:
I am working on .NET Version 2003 making an SDI application that calls MS Excel 2003. I added a menu item called "MyApp Help" in the end of the menu bar to show Help-> About. The application...
0
7124
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
6998
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7200
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6884
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
4586
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3090
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3078
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
651
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
287
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.