Home Answers Viewqa Java-Beginners menuItem and actionPerformed

 
 


syed firoze
menuItem and actionPerformed
2 Answer(s)      2 years and 8 months ago
Posted in : Java Beginners

i tried to do notepad application. but in that,when i clicks CUT menuItem of EDIT menu,i wanna get the MENU label("edit") inside the actionPerformed.how could i get it

View Answers

October 23, 2010 at 11:06 AM


Hi Friend,

Try the following code:

import java.awt.*; import javax.swing.*; import java.awt.event.*;

public class MenuExample extends JFrame { JMenuBar menuBar = new JMenuBar(); JMenu menu = new JMenu("File"); JMenu menu1 = new JMenu("Edit"); JMenuItem item1 = new JMenuItem("New"); JMenuItem item2 = new JMenuItem("Open");

public MenuExample(){ setJMenuBar(menuBar); setVisible(true); setSize(400,200); menuBar.add(menu); menuBar.add(menu1); menu.add(item1); menu.add(item2); item1.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { JFileChooser chooser=new JFileChooser(); chooser.showOpenDialog(null);

        }

    });
     item2.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            JFileChooser chooser=new JFileChooser();
            chooser.showOpenDialog(null);

        }

    });

} public static void main(String[]args){ MenuExample ex=new MenuExample(); }

}

Read more at:

http://www.roseindia.net/java/example/java/swing/

Thanks


October 23, 2010 at 11:08 AM


Hi Friend,

Try the following code:

import java.awt.*;
import javax.swing.*;
import java.awt.event.*;

public class MenuExample extends JFrame
{
JMenuBar menuBar = new JMenuBar();
JMenu menu = new JMenu("File");
JMenu menu1 = new JMenu("Edit");
JMenuItem item1 = new JMenuItem("New");
JMenuItem item2 = new JMenuItem("Open");

public MenuExample(){
setJMenuBar(menuBar);
setVisible(true);
setSize(400,200);
menuBar.add(menu);
menuBar.add(menu1);
menu.add(item1);
menu.add(item2);
item1.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                JFileChooser chooser=new JFileChooser();
                chooser.showOpenDialog(null);

            }

        });
         item2.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                JFileChooser chooser=new JFileChooser();
                chooser.showOpenDialog(null);

            }

        });
}
public static void main(String[]args){
    MenuExample ex=new MenuExample();
}

}

Read more at:

http://www.roseindia.net/java/example/java/swing/

Thanks









Related Pages:
menuItem and actionPerformed
menuItem and actionPerformed  i tried to do notepad application. but in that,when i clicks CUT menuItem of EDIT menu,i wanna get the MENU label("edit...); item1.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent
Pop-up Menus
; A PopupMenu is similar to a Menu as it contains MenuItem objects. The Pop...;public void actionPerformed(ActionEvent e){    m.show(b...; add(mi = new MenuItem("Copy"));    
Dojo: How MenuItem helps page redirction - Ajax
Dojo: How MenuItem helps page redirction  Hi, I am wondering that if "MenuItem" accepts an event of window.location (page redirection) like this : Response : NO, stay at same page. Is there any simple way
Menu Shortcuts
; The MenuItem class also provides a feature of menu shortcuts and speed keys... of the MenuItem can be created with the help of MenuItem class. The use of Ctrl... and Shift-Ctrl-P for Print Preview: file.add (m = new MenuItem ("Print", new
Create Menu Bar in SWT
, the classes Menu and MenuItem of package org.eclipse.swt.widgets is allowed... the shell on clicking the exit item: if (((MenuItem) event.widget...;fileItem = new MenuItem(menu, SWT.CASCADE);   
Java controls
Java controls  What is the difference between a MenuItem and a CheckboxMenuItem
Menus
of Menu objects. These Menu objects comprise of MenuItem objects which can be selected by the user with a click of a mouse. A MenuItem may be a String, checkbox...; Now the MenuItem options can be added to the Menu from top to bottom, using
FlexNativeMenu Control in Flex4
;{menuItem}" labelField="@label" keyEquivalentField="...;menuitem label="File"> <menuitem label="New" keyEquivalent="n" controlKey="true"/> <menuitem label="
Crate a Popup Menu in Java
; JMenuItem menuItem;   public static void main...;new JMenuItem("Cut");   Pmenu.add(menuItem);   ...(menuItem);   menuItem = new JMenuItem("Paste"
JFRAME - Java Beginners
menuItems(new,open).. actionevent given to open(menuitem)... now when click on open...(new java.awt.event.ActionListener() { public void actionPerformed...() { public void actionPerformed(ActionEvent e) { JFileChooser
Menu Control in Flex4
;   var menu1:Menu= Menu.createMenu(null, menuItem, false..., menuItem, false); menu1.labelField="@label"; menu1.iconField="...;root> <menuitem label="MenuItem A"> <menuitem label
retaining save dialog box even after clicking save button - Java Beginners
textArea=new JTextArea("",5,40); static JMenuItem menuItem; public static void..."); menu.setMnemonic(KeyEvent.VK_F); menuBar.add(menu); menuItem... Listener()); menu.add(menuItem); JScrollPane scrollPane = new
JTable
JTable  i want to delete record from JTable using a MenuItem DELETE. and values of JTable are fetched from database....please reply soon
Applet - Applet
"); m.add(new MenuItem("Shortcut Keys")); m.add(new MenuItem("Version")); mb.add(m...); } public void paint(Graphics g) { if(evt.target instanceof MenuItem... actionPerformed(ActionEvent e) { String text="Home=Move to start of the current
MenuBar Control in Flex4
;menuBarCollection"> <menuitem label="File" icon="topIcon"> <menuitem label="New" /> <menuitem label="Open" /> <menuitem label="Save" icon="top1Icon
Hash Table for maintaining popup menus in Java
;MenuItem("First Menu");   item.addActionListener(this);   m.add(item);   item = new MenuItem("...;void actionPerformed(ActionEvent e){   
java script - Development process
) { menuItem="document.layers"; styleSwitch... if(document.all){ menuItem="document.all... if(document.getElementById){ menuItem="document.getElementByID
Computers - Java Beginners
CalcFrame fr; MenuBar menu; Menu view, font; MenuItem bold, regular... = new MenuItem("Arial Bold"); bold.addActionListener(this); regular = new MenuItem("Arial Regular"); regular.addActionListener
java code
; MenuItem student,rollnowise,namewise,allresult; public static menu m; rollnowise... actionPerformed(ActionEvent ae) { String arg=ae.getActionCommand..."); dlg.add(msg); dlg.add(ok); } public void actionPerformed(ActionEvent
Question?
is to shown on menuitem selection. import java.awt.*; import java.util....() { public void actionPerformed(ActionEvent e
PopUpMenuButton Control in Flex4
;e4x" id="menuData"> <root> <menuitem label="New"/> <menuitem label="Open"/> <menuitem label="Save"/> <menuitem label="Save as..."
Core Java Interview Question, Interview Question
: What is the difference between a MenuItem and a CheckboxMenuItem? Answer: The CheckboxMenuItem class extends the MenuItem class to support a menu item... is the immediate superclass of Menu? Answer: MenuItem Question: What is the purpose
Events
;TextField   TextListener  Button  List  MenuItem...;windowDeactivated(WindowEvent e)  ActionListener  actionPerformed
ArrayList - Java Beginners
() { public void actionPerformed(ActionEvent ae) { btnAdd.doClick... void actionPerformed(ActionEvent ae) { vector.add(txtAdd.getText...(); } }); btnSize.addActionListener(new ActionListener() { public void actionPerformed
GUI problem - Java Beginners
; Handle the actionPerformed event for JButton and try doing something like...; Handle the actionPerformed event for JButton and try doing something like
Dojo Menu and Menu Item
then popup menu is appeared on the screen. MenuItem widgets are an actual items in the menu. The PopupMenuItem is a MenuItem, but it displays a submenu or other
Dojo Menu and Menu Item
then popup menu is appeared on the screen. MenuItem widgets are an actual items in the menu. The PopupMenuItem is a MenuItem, but it displays a submenu or other
java button - Java Beginners
ActionListener() { public void actionPerformed(ActionEvent e...() { public void actionPerformed(ActionEvent e) { trace("2", cb2...() { public void actionPerformed(ActionEvent e) { trace("3", cb3
Creating Menu using GWT
;new Label("Move the cursor over the Menuitem"
Java Evet Erropr - Java Beginners
: actiondemo is not abstract and does not override abstrac thod actionPerformed...); b.addActionListner(this); } public void ActionPerformed(ActionEvent ae...(){ public void actionPerformed(ActionEvent ae){ b.setLabel("Button Clicked
calender applet
)); ddText.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e...())); } }); add(p, BorderLayout.SOUTH); } public void actionPerformed(ActionEvent e) { System.out.println("Cal::ActionPerformed"); yy = Integer.parseInt
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
) { ................... ON.addActionListener(new ActionListener() { public void actionPerformed...() { public void actionPerformed(ActionEvent ev) { t.stop... actionPerformed(ActionEvent ae) { String value1 = text1.getText
NotePad - Swing AWT
() { public void actionPerformed(ActionEvent e... actionPerformed(ActionEvent e) { String str=newODialog... ActionListener() //save dialog { public void actionPerformed
Dojo Menu and Menu Item
of the mouse then popup menu is appeared on the screen. MenuItem widgets are an actual items in the menu. The PopupMenuItem is a MenuItem, but it displays a submenu
Java Code - Java Beginners
); item1.addActionListener(new ActionListener(){ public void actionPerformed... ActionListener(){ public void actionPerformed(ActionEvent e){ JLabel label2=new... actionPerformed(ActionEvent e){ JLabel label3=new JLabel("This is Panel3
Action Listener Review
. The ActionListener interface requires that the class define an actionPerformed... actionPerformed(ActionEvent e) { // do something for button b1... ActionListener { public void actionPerformed(ActionEvent e) { // do something
java
not override the abstract method actionPerformed. For implementing an interface
java
); } public void ActionPerformed(ActionEvent e) { t.setText(e.getActionCommand
help me
(){ public void actionPerformed(ActionEvent e){ String st=text.getText...(new ActionListener(){ public void actionPerformed(ActionEvent e... actionPerformed(ActionEvent e){ String st=text.getText(); String reverse
Swings - Java Beginners
ActionListener() { public void actionPerformed(ActionEvent e...); } }); jTextField2.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent... actionPerformed(ActionEvent e) { jTextField3_actionPerformed(e
Swings - Java Beginners
ActionListener() { public void actionPerformed(ActionEvent e...); } }); jTextField2.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent... actionPerformed(ActionEvent e) { jTextField3_actionPerformed(e
Listeners
to the actionPerformed() method defined in the class of the listener object. An ActionEvent object is passed as a parameter to it actionPerformed(). The listener method must be called actionPerformed There is (unfortunately) no way to use
Average
actionPerformed(java.awt.event.ActionEvent evt) { txtStudentIDActionPerformed...() { public void actionPerformed(java.awt.event.ActionEvent evt...); } }); cboxGrades.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed
connection database error
public void actionPerformed(ActionEvent e) { clear_actionPerformed(e); } } private class ExitActionListener implements ActionListener { // action for button exit public void actionPerformed
swings - Java Beginners
() { public void actionPerformed(ActionEvent e...); } }); jTextField2.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e... actionPerformed(ActionEvent e) { jTextField3_actionPerformed(e
swings - Java Beginners
() { public void actionPerformed(ActionEvent e...); } }); jTextField2.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e... actionPerformed(ActionEvent e) { jTextField3_actionPerformed(e
java - Java Server Faces Questions
"); ADD.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae...; } } }); SUB.addActionListener(new ActionListener() { public void actionPerformed...; } } }); MUL.addActionListener(new ActionListener() { public void actionPerformed
validating text fields - Swing AWT
java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt...() { public void actionPerformed(java.awt.event.ActionEvent evt... java.awt.event.ActionListener() { public void actionPerformed
please give me a java program for the following question
ActionListener(){ public void actionPerformed(ActionEvent e){ JFrame f1=new JFrame...); } }); button2.addActionListener(new ActionListener(){ public void actionPerformed... ActionListener(){ public void actionPerformed(ActionEvent e){ JFrame f1=new
Java AWT Package Example
a Menu consists of Menu objects. Menu Shortcuts The MenuItem class also... A PopupMenu is similar to a Menu as it contains MenuItem objects. The Pop-up Menu can