package cn.com;import java.util.*;
import java.awt.*;
import java.awt.event.*;import sun.org.mozilla.javascript.internal.Interpreter;import com.sun.org.apache.xerces.internal.impl.xs.identity.Selector.Matcher;public class Hello extends Frame implements ActionListener, WindowListener {
private TextField text_input, text_output; private Button button_ok, button_cancel; private Dialog dialog; private Label label_dialog; public Hello() {
super("整数排序程序"); this.setSize(400, 200);
this.setResizable(false); // 窗口大小不能改变
this.setBackground(java.awt.Color.lightGray);
this.setLocation(300, 240);
this.setLayout(new java.awt.FlowLayout(FlowLayout.LEFT)); // 流布局且左对齐 this.add(new Label("输入")); text_input = new TextField(100);
this.add(text_input);
text_input.addActionListener(this); // 为文本行注册单击事件监听器 this.add(new Label("输出"));
text_output = new TextField(100);
text_output.setEditable(false); // 只能显示,不允许编辑
this.add(text_output); button_ok = new Button("排序");
this.add(button_ok);
button_ok.addActionListener(this); // 为按钮注册单击事件监听器 button_cancel = new Button("重置");
this.add(button_cancel);
button_cancel.addActionListener(this); // 为按钮注册单击事件监听器 this.addWindowListener(this); // 为框架注册事件监听器,委托当前类的对象处理事件
this.setVisible(true); dialog = new Dialog(this, "提示", true); // 模式窗口
dialog.setSize(300, 80);
label_dialog = new Label("", Label.CENTER); // 标签的字符串为空,居中对齐
dialog.add(label_dialog);
dialog.addWindowListener(this); // 为对话框注册窗口事件监听器 } public void Numbersort() throws Exception {
ArrayList list = new ArrayList();
Scanner input = new Scanner(System.in);// 创建一个键盘扫描类对象
String in = text_input.getText();
int index;
for (int j = 0; j < in.length(); j = index + 1) {
index = in.indexOf(in, j);
if (index == -1) {
list.add(Integer.valueOf(in.substring(j, in.length())));
break;
}
list.add(Integer.valueOf(in.substring(j, index))); } Collections.sort(list);
String a = list.toString();
text_output.setText(a); } public void actionPerformed(ActionEvent e) // 按钮单击、文本行中单击回车键
{
if (e.getSource() == button_cancel) // 获得产生事件的对象
text_input.setText("");
if (e.getSource() == button_ok) {
try {
Numbersort();
} /*catch (NumberFormatException  nfe) {
label_dialog.setText("\"" + text_input.getText() + "\""
+ "所输入的数不全是整数,请重新输入!");
dialog.setLocation(this.getX() + 100, this.getY() + 100);
dialog.setVisible(true);
}*/ catch(Exception ce){

}
finally {
}
}
} public void windowClosing(WindowEvent e) {
if (e.getSource() == dialog)
dialog.setVisible(false); // 隐藏对话框
else
System.exit(0);
} public static void main(String[] args) {
new Hello(); } public void actionPerformed(WindowEvent e) {
} public void windowActivated(WindowEvent e) {
} public void windowClosed(WindowEvent e) {
} public void windowDeactivated(WindowEvent e) {
} public void windowDeiconified(WindowEvent e) {
} public void windowIconified(WindowEvent e) {
} public void windowOpened(WindowEvent e) {
}}
为什么每次都抛出异常?谢谢