Java小程序莫名溢出
import java.awt.*;
import java.awt.event.*;
import java.math.*;
import java.io.*;
import java.util.*;
import javax.swing.*;
import javax.swing.border.*;
import javax.swing.JOptionPane;
public class Exec
{
public static void main(String args[])
{
new Winp("Basic Application Example");
}
}
class Winp extends Frame implements ActionListener
{
File file;
FileReader reader;
BufferedReader in;
FileDialog file_open;
StringTokenizer fenxi;
BigInteger a1,a2,a3;
MenuBar bar;
Menu menu1,menu2;
MenuItem item1,item2;
TextField text1,text2,text3;
Panel panel;
Label label;
Box box1,box2,box3;
Button button1,button2;
Winp(String s)
{
super(s);
bar=new MenuBar();
menu1=new Menu("File");
menu2=new Menu("Help");
menu2.addActionListener(this);
item1=new MenuItem("Open");
item1.addActionListener(this);
item2=new MenuItem("help...");
menu2.add(item2);
item2.addActionListener(this);
bar.add(menu1);bar.add(menu2);
menu1.add(item1);
setMenuBar(bar);
button1=new Button("获取题目");
button1.addActionListener(this);
button2=new Button("确认答案");
button2.addActionListener(this);
box1=Box.createHorizontalBox();
box3=Box.createVerticalBox();
text1=new TextField(10);
text1.setEditable(false);
text2=new TextField(10);
text2.setEditable(false);
text3=new TextField(16);
box1.add(button1);
box1.add(text1);box1.add(new Label("+"));
box1.add(text2);box1.add(new Label("="));
box1.add(text3);
panel=new Panel();
panel.add(button2);
label=new Label(null);
panel.add(label);
add(box1,BorderLayout.NORTH);
add(panel,BorderLayout.CENTER);
setBounds(240,240,500,300);
file_open=new FileDialog(this,"打开文件对话框",FileDialog.LOAD);
file_open.setVisible(false);
file_open.addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
file_open.setVisible(false);
}
}
);
setVisible(true);
validate();
addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
}
);
}
public void actionPerformed(ActionEvent ev)
{
if(ev.getSource()==item1)
{
file_open.setVisible(true);
if(file_open.getFile()!=null)
{
try
{
file=new File(file_open.getDirectory(),file_open.getFile());
reader=new FileReader(file);
in=new BufferedReader(reader);
}
catch(
IOException io){}
}
}
else if(ev.getSource()==button1)
{
if(file==null)
{
label.setText("Please choose file first!");
text3.setText(null);
this.validate();
}
else
{
try
{
String s=in.readLine();
if(s.startsWith("-1"))
{
label.setText("测试完毕");
text1.setText(null);text2.setText(null);text3.setText(null);
in.close();
reader.close();
}
else
{
fenxi=new StringTokenizer(s," ,");
a1=new BigInteger(fenxi.nextToken());
text1.setText(a1.toString());