小问题(急)
编译能通过,但运行有异常
最大的问题是怎么把数字转换成字符串
题目是点Add加一,点Minus减一
import java.awt.*;
import java.awt.event.*;
public class AddMinus extends WindowAdapter implements ActionListener
{
private Frame frm;
private Panel pan1,pan2;
private TextField note;
private Button b1,b2,b3;
public void AddMinus()
{
frm=new Frame("Add and Minus");
frm.setLayout(new BorderLayout());
pan1=new Panel();
pan2=new Panel();
pan1.setLayout(new FlowLayout());
pan2.setLayout(new FlowLayout());
b1=new Button("Add");
b1.addActionListener(this);
b2=new Button("Minus");
b2.addActionListener(this);
b3=new Button("Exit");
b3.addActionListener(this);
note=new TextField();
pan1.add(note);
pan2.add(b1);
pan2.add(b2);
pan2.add(b3);
frm.add(pan1,BorderLayout.CENTER);
frm.add(pan2,BorderLayout.SOUTH);
frm.setSize(400,300);
frm.addWindowListener(this);
frm.pack();
frm.show();
}
public void WindowClosing(WindowEvent e)
{
System.exit(0);
}
public void actionPerformed(ActionEvent e)
{
if(e.getActionCommand().equals("Add"))
{
note.setText("");
int a;
a=Integer.parseInt(note.getText())+1;
String s=""+a;
note.setText(s);
}
else if(e.getActionCommand().equals("Minus"))
{
note.setText("");
int a;
a=Integer.parseInt(note.getText())-1;
String s=""+a;
note.setText(s);
}
else System.exit(0);
}
public static void main(String args[])
{
AddMinus e=new AddMinus();
}
}