http://www.cn-java.com/index_download_center.php
import java.awt.*;import java.awt.event.*;
import javax.swing.JOptionPane;
public class Example16_3
{
public static void main(String args[])
{
new DWindow("带消息框的窗口");
}
};
class DWindow extends Frame implements ActionListener
{
TextField inputNumber;
TextArea text;
DWindow(String s)
{
super(s);
//setLayout(new FlowLayout());
setResizable(false);
inputNumber=new TextField(20);
text=new TextArea(10,20);
inputNumber.addActionListener(this);
add(inputNumber,BorderLayout.NORTH);
add(text,BorderLayout.CENTER);
setBounds(0,0,200,300);//validate();
setVisible(true);
addWindowListener(new WindowAdapter()
{
public void WindowClosing(WindowEvent e)
{
System.exit(0);
}
});
validate();
}
public void actionPerformed(ActionEvent e)
{
boolean boo=false;
if (e.getSource()==inputNumber)
{
String s=new String(inputNumber.getText());
char a[]=s.toCharArray();
for (int i=0;i<a.length;i++)
{
if (!(Character.isDigit(a[i])))
{
boo=true;
}
}
if (boo==true)
{
JOptionPane.showMessageDialog(this,"您输入了非法字符。","警告对话框",JOptionPane.WARNING_MESSAGE);
inputNumber.setText(null);
}
else if(boo=false)
{
int number=Integer.parseInt(s);
text.append("\n"+number+"平方:"+(number*number));
}
}
}
};