Click here to Skip to main content
15,907,001 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Can anyone guide me how add actionListener to a button named "OK" that when I click the button it goes to another window called MainMenu?
Posted

Hey you, may try following coding my best way of java project implementation.
import javax.swing.*;
import java.awt.event.*;
public class ChangeButtonLabel{
  JButton button;
  JDialog dispay;
  MainMenu myDispay;
  public static void main(String[] args){
    ChangeButtonLabel cl = new ChangeButtonLabel();
  }
  public ChangeButtonLabel(){
    JFrame frame = new JFrame("Change JButton Lebel");
    dispay=new JDialog();
    button = new JButton("Click Me");
    myDispay=new MainMenu();  ///MainMenu class file should present in current folder as well as this class must extend from JPanel
    button.addActionListener(new MyAction());
    frame.add(button);
    dispay.add(myDispay);
    frame.setSize(400, 400);
    frame.setVisible(true);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  }
  public class MyAction implements ActionListener{
    public void actionPerformed(ActionEvent e)
   {
               dispay.setSize(300, 300);
               dispay.setVisible(true);
   }
  }
} 

if you have any suggestion most WELCOME
 
Share this answer
 
Comments
sanieJ 29-Mar-11 4:42am    
how to implements the actionPerformed by calling other class.
Hi,
Please find below two articles of JAVA GUI. Here you can find the code for ActionListner and ActionPerformed:

http://shivasoft.in/blog/java/jdbc-example-with-microsoft-access-in-swing/[^]

http://shivasoft.in/blog/java/bouncing-ball-applet-create-balls-on-mouse-click-of-random-color-and-random-size/[^]

Regards,
Jitendra Zaa
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900