当前位置: 技术问答>java相关
怎样识别JOptionPane.showConfirmDialog的键值?高分!
来源: 互联网 发布时间:2017-03-25
本文导语: 在这个提示信息中,我怎么去识别用户是选择了"确定"和"取消"???? JOptionPane.showConfirmDialog(this,"要继续吗","提示信息",JOptionPane.OK_CANCEL_OPTION,JOptionPane.INFORMATION_MESSAGE ); | import javax.swing.*; import jav...
在这个提示信息中,我怎么去识别用户是选择了"确定"和"取消"????
JOptionPane.showConfirmDialog(this,"要继续吗","提示信息",JOptionPane.OK_CANCEL_OPTION,JOptionPane.INFORMATION_MESSAGE );
JOptionPane.showConfirmDialog(this,"要继续吗","提示信息",JOptionPane.OK_CANCEL_OPTION,JOptionPane.INFORMATION_MESSAGE );
|
import javax.swing.*;
import java.awt.event.*;
public class AA extends JFrame {
Container c;
int value;
public AA() {
super("aa");
setSize(300, 200);
c = getContentPane();
c.setLayout(new BorderLayout());
JButton b = new JButton("a");
ActionListener action = new ActionListener() {
public void actionPerformed(ActionEvent e) {
value =JOptionPane.showConfirmDialog(c,"要继续吗","提示信息",JOptionPane.OK_CANCEL_OPTION,JOptionPane.INFORMATION_MESSAGE );
if (value ==JOptionPane.OK_OPTION){
JOptionPane.showMessageDialog(c,"message1","message1",JOptionPane.YES_OPTION);
}
if(value ==JOptionPane.CANCEL_OPTION){
JOptionPane.showMessageDialog(c,"message2","message2",JOptionPane.YES_OPTION);
}
}
};
b.addActionListener(action);
c.add(b, BorderLayout.CENTER);
setVisible(true);
}
public static void main(String args[]) {
AA a = new AA();
}
}
import java.awt.event.*;
public class AA extends JFrame {
Container c;
int value;
public AA() {
super("aa");
setSize(300, 200);
c = getContentPane();
c.setLayout(new BorderLayout());
JButton b = new JButton("a");
ActionListener action = new ActionListener() {
public void actionPerformed(ActionEvent e) {
value =JOptionPane.showConfirmDialog(c,"要继续吗","提示信息",JOptionPane.OK_CANCEL_OPTION,JOptionPane.INFORMATION_MESSAGE );
if (value ==JOptionPane.OK_OPTION){
JOptionPane.showMessageDialog(c,"message1","message1",JOptionPane.YES_OPTION);
}
if(value ==JOptionPane.CANCEL_OPTION){
JOptionPane.showMessageDialog(c,"message2","message2",JOptionPane.YES_OPTION);
}
}
};
b.addActionListener(action);
c.add(b, BorderLayout.CENTER);
setVisible(true);
}
public static void main(String args[]) {
AA a = new AA();
}
}