public void actionPerformed(ActionEvent e) {
if (e.getSource() == text1) {
// String word=text1.getText();
String word = e.getActionCommand();
int a = Integer.parseInt(word);
int m = a * a;
text2.setText(m);出现这样错误信息
Exception in thread "AWT-EventQueue-0" java.lang.Error: 无法解析的编译问题:
类型 TextField 中的方法 setText(String)对于参数(int)不适用怎么会对int类型不适用,请教高手
if (e.getSource() == text1) {
// String word=text1.getText();
String word = e.getActionCommand();
int a = Integer.parseInt(word);
int m = a * a;
text2.setText(m);出现这样错误信息
Exception in thread "AWT-EventQueue-0" java.lang.Error: 无法解析的编译问题:
类型 TextField 中的方法 setText(String)对于参数(int)不适用怎么会对int类型不适用,请教高手
因为TextField中是字符串
所以如下:
int a = Integer.parseInt(word);
int m = a * a;
String s=""+m;//把整形转换为String
text2.setText(s); 就OK了
Integer m = a * a;
text2.setText(m.toString());