JAVA JFrame 第一个窗口中点击开始 然后出现第二个窗口 输入内容点击OK 开始程序
- 提问者网友:心牵心
- 2021-05-05 04:00
- 五星知识达人网友:持酒劝斜阳
- 2021-05-05 04:34
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
public class Test extends JFrame implements ActionListener{
private JButton button;
public Test(){
this.setBounds(100, 200, 300, 400);
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
button = new JButton("开始");
this.getContentPane().add(button);
button.addActionListener(this);
}
public void actionPerformed(ActionEvent e) {
Object[] options = { "OK", "CANCEL" };
JOptionPane.showOptionDialog(null, "Click OK to continue", "Warning",
JOptionPane.DEFAULT_OPTION, JOptionPane.WARNING_MESSAGE,
null, options, options[0]);
System.out.println("程序继续了。");
}
public static void main(String args[]){
new Test().setVisible(true);
}
}