Ok, let's see ... 1. add ActionListener to your menuitem. 2. when MenuItem fire the event, you can compare what MenuItem was clicked
if(a.getSource() == item1) { // MenuItem 1 has an action event. : } 3. You can call a method into that IF, and you can make a new window with all JList content. 4. You can pass as parameter the MenuItem that was clicked. showMyJList((JMenuItem)a.getSource()); or showMyJList(item1); 5. Into 'showMyJList', you can knows the MenuItem's text void showMyJList(JMenuItem item) { : String label = item.getLabel(); // MenuItem's name that was fired an event (clicked) : showNewWindows(); : } You will need to do a review of Swing :P ... On Thu, Sep 24, 2009 at 5:33 AM, javaquestion <cplusplusquest...@gmail.com>wrote: > > > > On Sep 24, 1:04 am, Victor Lutin <umg.victor.lu...@gmail.com> wrote: > > Mmmh ... You can add an ActionListener directly to MenuItem, You don't > need > > to use a JButton for that. > > > > Check Java Doc: > > > > http://java.sun.com/j2se/1.4.2/docs/api/java/awt/MenuItem.html > > > > This works in 1.4+ :) ... > > > > Your class most implements ActionListener Interface > > > > public class YourClasssWithMenuItems implements *ActionListener* { > > private JMenuItem item1; > > : > > *public void actionPerformed(ActionEvent a)* { > > if(a.getSource() == item1) { // MenuItem 1 has an action event. > > : > > } > > : > > } > > : > > item1 = new JMenuItem("Item 1"); > > item.addActionListener(this); > > : > > > > Thanks for this. However, the program in some cases will work as > follows: > > Click JMenuItem -> Display a JList -> Select an item from JList -> > Display a new window, in this new window I need to check which > JMenuItem I was clicked. I still don't know how to work. > > > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Java EE (J2EE) Programming with Passion!" group. To post to this group, send email to java-ee-j2ee-programming-with-passion@googlegroups.com To unsubscribe from this group, send email to java-ee-j2ee-programming-with-passion+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/java-ee-j2ee-programming-with-passion?hl=en?hl=en -~----------~----~----~----~------~----~------~--~---