• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Paul Clapham
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Roland Mueller
  • Piet Souris
Bartenders:

menu problem

 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi all !
I'm not able to build the EXIT button in a MENU in java.
Will someone plz. help me ,HOW to do that?
Thx in advance!
gags!
------------------
 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Are you using Swing or AWT, and is this an application or an Applet?
 
gagan sharma
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Bodie Minster:
Are you using Swing or AWT, and is this an application or an Applet?


I'm using AWT & this is an application.
------------------
 
Sheriff
Posts: 7001
6
Eclipse IDE Python C++ Debian Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So which bit of adding an exit button is not working? Creating the button? Adding the button to the menu? Showing the menu? Responding to a click on the button? doing whatever you want it to do when clicked?
 
gagan sharma
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Frank Carver:
So which bit of adding an exit button is not working? Creating the button? Adding the button to the menu? Showing the menu? Responding to a click on the button? doing whatever you want it to do when clicked?


what i want is that when i click EXIT on MENU,it should kick me out of the application! hope someone will help me on that!!!
------------------
 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Gagan,
Below is some test code for you, I have written an actionListener for capturing your exit click and then kick off the application. I know there is a better way to pull out of application but can not implement. Hope this will help.
//code start
import java.awt.AWTEvent.*;
import java.awt.*;
import java.awt.event.*;

public class exit implements ActionListener
{
public Frame f;
public void actionPerformed(ActionEvent ae)
{
System.out.println("Action performed.");
}
public exit()
{
f = new Frame();
MenuBar mb = new MenuBar();
Menu m = new Menu("Test");
m.add("Exit");
mb.add(m);
f.setMenuBar(mb);
f.setSize(200, 300);
f.setVisible(true);

m.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent ae)
{
System.exit(0);
}
}
);
}
public static void main (String args[])
{
exit e = new exit();

}
}
// code End
 
gagan sharma
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by rehan hamid:
Gagan,
Below is some test code for you, I have written an actionListener for capturing your exit click and then kick off the application. I know there is a better way to pull out of application but can not implement. Hope this will help.
//code start
import java.awt.AWTEvent.*;
import java.awt.*;
import java.awt.event.*;

public class exit implements ActionListener
{
public Frame f;
public void actionPerformed(ActionEvent ae)
{
System.out.println("Action performed.");
}
public exit()
{
f = new Frame();
MenuBar mb = new MenuBar();
Menu m = new Menu("Test");
m.add("Exit");
mb.add(m);
f.setMenuBar(mb);
f.setSize(200, 300);
f.setVisible(true);

m.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent ae)
{
System.exit(0);
}
}
);
}
public static void main (String args[])
{
exit e = new exit();

}
}
// code End


thx a lot Rehan,let me try with ur code then I'll tell u about the results!!!
gagan!
------------------
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic