Thread: SWING stuff...
View Single Post
Old Oct 23rd, 2006, 3:16 PM   #2
ReggaetonKing
Sexy Programmer
 
ReggaetonKing's Avatar
 
Join Date: Nov 2005
Location: New Jersey
Posts: 891
Rep Power: 4 ReggaetonKing is on a distinguished road
Send a message via AIM to ReggaetonKing
You must add an ActionListener to those menu items. For example
[php]
import javax.swing.*;
import java.awt.event.*;

public class Example
{
public static void main(String args[])
{
JFrame frame = new JFrame("Example Frame");
JMenu filemenu = new JMenu("File");
JMenuItem exititem = new JMenuItem("Exit");
exititem.addActionListener(new ExitAction());
filemenu.add(exititem);
JMenuBar bar = new JMenuBar().add(filemenu);
frame.addJMenuBar(bar);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(300,300);
frame.setVisible(true);

}
private class ExitAction implements ActionListener
{
public void actionPerformed(ActionEvent ev)
{
System.exit(0);
}
}
}
[/php]
Here I have set the ActionListener "ExitAction " to the menu item object "exititem" which was add to a JMenu object, "filemenu". This was a simple example but what I do myself is make a lot of inner classes for different tasks and set those tasks according to the menu items/buttons I want those to execute that tasks.
__________________
I would love to change the world, but they won't give me the source code!
ReggaetonKing is offline   Reply With Quote