小问题(急) 1 + ""2 try { a=Integer.parseInt(note.getText())+1; } catch 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 or:int to string : Integer.toString(123);2, the same as vcshcn(xx) Integer.toSring() or Double.toSring() public void AddMinus()这是构造函数没有返回值的去掉void写成public AddMinus()就可以了 把下面代码里的东西去掉note.setText("");抛异常的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); } 改了一下,可以工作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 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; try { a = Integer.parseInt(note.getText()) + 1; } catch (NumberFormatException e1) { a = 0; } String s = "" + a; note.setText(s); } else if (e.getActionCommand().equals("Minus")) { //note.setText(""); int a; try { a = Integer.parseInt(note.getText()) - 1; } catch (NumberFormatException e2) { a = 0; } String s = "" + a; note.setText(s); } else System.exit(0); } public static void main(String args[]) { AddMinus e = new AddMinus(); }} addWindowListener( new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } }); java的inputstreamreader的问题 细节 构造器 加载顺序 UnsupportedOperationException 请求高人解答!!!!!!!!!!!! 为什么序列化接口无须重载就能起作用? hibernate+MYSQL 找不到列问题 enumerated types 的使用 新手上路:编译通过的程序不能正常运行,请大虾们指点迷津! 超级简单,网站怎样计算某页的访问量? 各位兄弟,急救我是初学者,关于JBULID的问题? JavaUI界面不跳转?是怎么回事? 如何设置并查看java中JVM堆(heap)的大小? 求助:一道考试题目
int to string : Integer.toString(123);2, the same as vcshcn(xx)
这是构造函数没有返回值的
去掉void写成public AddMinus()
就可以了
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);
}
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 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;
try {
a = Integer.parseInt(note.getText()) + 1;
} catch (NumberFormatException e1) {
a = 0;
}
String s = "" + a;
note.setText(s);
} else if (e.getActionCommand().equals("Minus")) {
//note.setText("");
int a;
try {
a = Integer.parseInt(note.getText()) - 1;
} catch (NumberFormatException e2) {
a = 0;
}
String s = "" + a;
note.setText(s);
} else
System.exit(0);
} public static void main(String args[]) {
AddMinus e = new AddMinus();
}
}
new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});