button click showMessage in java

16,410

This may help you:

okButton.addActionListener(new MyAction());
public class MyAction implements ActionListener{
  public void actionPerformed(ActionEvent ae){
    JOptionPane.showMessageDialog(null, "This is the simple message 
    dialog box.", "Roseindia.net", 1);
  }
}

Taken from here: http://www.roseindia.net/java/example/java/swing/ShowMessageDialog.shtml

Share:
16,410
searchforit
Author by

searchforit

Updated on June 04, 2022

Comments

  • searchforit
    searchforit almost 2 years

    I have created a button in a JApplet. How can I use it to open a message box?

    okButton = new Button("Miow");
    okButton.setBounds(20,20,1150,30);
    add(okButton);
    
    //like
    if(okButton)
    {
        JOptionPane.showMessage......
    }
    
  • Mickey
    Mickey over 10 years
    That's exactly what I wanted to write, too. +1
  • searchforit
    searchforit over 10 years
    Ok. I have understood ;)