/*
* Example8_4.java
*
* Created on 2011年3月17日, 下午2:33
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/
/**
*
* @author chin
*/
import java.awt.event.*;
import java.awt.*;
import javax.swing.JOptionPane;
class Dwindow extends Frame implements ActionListener {
TextField inputNumber;
TextArea show;
Dwindow(String s) {
super(s);
inputNumber=new TextField(22); inputNumber.addActionListener(this);
show=new TextArea();
add(inputNumber,BorderLayout.NORTH); add(show,BorderLayout.CENTER);
setBounds(60,60,300,300); setVisible(true);
validate();
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
}
);
}
public void actionPerformed(ActionEvent e) {
boolean boo=false;
if(e.getSource()==inputNumber) {
String s=inputNumber.getText();
if(java.lang.Character.isDigit(s.charAt(0))){
int a = Integer.parseInt(s);
if(a > 1000){
boo=true;
}
if(boo==true) //弹出“警告”消息对话框
{ int n=JOptionPane.showConfirmDialog(this,"您输入了大于1000的数字,是否添加?","确认对话框",
JOptionPane.YES_NO_OPTION);
if(n==JOptionPane.YES_OPTION)
{
show.append("\n" + a);
}
else if(n == JOptionPane.NO_OPTION)
{
inputNumber.setText(null);
}
inputNumber.setText(null);
} else if(boo==false) {
show.append("\n" + a);
}
}
else
{
JOptionPane.showMessageDialog(this,"你输入的不是数字!","确认对话框",
JOptionPane.WARNING_MESSAGE);
inputNumber.setText(null);
}
}
}
}
public class Example8_4 {
public static void main(String args[]) {
new Dwindow("带对话框的窗口");
}
}