简体   繁体   中英

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......
}

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM