Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

button click showMessage in java

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......
}
like image 917
searchforit Avatar asked Feb 14 '23 20:02

searchforit


1 Answers

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

like image 149
Tony Dinh Avatar answered Feb 17 '23 11:02

Tony Dinh