btn.setBounds(50, 420, 70, 22);
btn.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
/*
* 参数1: 父组件 参数2: 提示信息 参数3: 标题信息
* 参数4: 指定按钮类型 参数5: 指定图标类型
* 返回值:用户所选选项的整数
*/
int option = JOptionPane.showConfirmDialog(null, "你确定提交吗?", "提交提示", JOptionPane.OK_CANCEL_OPTION,
JOptionPane.WARNING_MESSAGE);
if (option == JOptionPane.OK_OPTION) {
System.out.println("ok,submit!!!!");
} else {
System.out.println("no, cancel");
}
}
});
panel.add(btn);
JButton btn2 = new JButton(" 重置 ");
btn2.setBounds(150, 420, 70, 22);
panel.add(btn2);
btn2.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
//重置处理代码….
nameTxt.setText("");
pwd.setText("");
intrArea.setText("");
fRdo.setSelected(true) ;
hobbyChk2.setSelected(true);
hobbyChk3.setSelected(false);
hobbyChk.setSelected(false);
edicbo.setSelectedIndex(0);
}
});
}
public static void main(String[] args) {
new SwingReigster();
}
}