按钮单击java中的showMessage

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19657443/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-12 19:12:11  来源:igfitidea点击:

button click showMessage in java

javajbuttonmessagebox

提问by searchforit

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

我在 JApplet 中创建了一个按钮。如何使用它打开消息框?

okButton = new Button("Miow");
okButton.setBounds(20,20,1150,30);
add(okButton);

//like
if(okButton)
{
    JOptionPane.showMessage......
}

采纳答案by TrungDQ

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

取自这里:http: //www.roseindia.net/java/example/java/swing/ShowMessageDialog.shtml