我希望如此,当您单击“确定”或“取消”时,它会关闭。我应该添加什么代码?
rightbutton = new JButton("Right.");
add(rightbutton);
rightbutton.addActionListener(
new ActionListener(){
public void actionPerformed(ActionEvent event){
//what do we want to happen when we
//click the button
final ImageIcon icon = new ImageIcon("C:\\Users\\Scr3am\\Desktop\\paypal.jpg");
JOptionPane.showOptionDialog(null,
"Congratulations, you clicked the button.",
"Congrats", JOptionPane.DEFAULT_OPTION,
JOptionPane.INFORMATION_MESSAGE, null,
new Object[] { panel }, icon);
答案 0 :(得分:-1)
当你点击确定时,JOptionPane应该自动关闭,但是尝试添加System.exit(0);到actionPerformed方法。
例如
rightbutton = new JButton("Right.");
add(rightbutton);
rightbutton.addActionListener(
new ActionListener(){
public void actionPerformed(ActionEvent event){
//what do we want to happen when we
//click the button
final ImageIcon icon = new ImageIcon("C:\\Users\\Scr3am\\Desktop\\paypal.jpg");
JOptionPane.showOptionDialog(null,
"Congratulations, you clicked the button.",
"Congrats", JOptionPane.DEFAULT_OPTION,
JOptionPane.INFORMATION_MESSAGE, null,
new Object[] { panel }, icon);
System.exit(0);