Java编程出现问题了 求解
import java.awt.BorderLayout;import java.awt.Dimension;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
import javax.swing.text.JTextComponent;
public class Calculator1 extends JFrame implements ActionListener{
public Calculator1(){
setTitle("简单计算器");
init();
setBounds(100,100,280,280);
setVisible(true);
}
void init(){
JTextField show=new JTextField();
show.setPreferredSize(new Dimension(12,50));
GridLayout grid=new GridLayout(4,4);
show.setText("0");
show.setHorizontalAlignment(JTextField.RIGHT);
grid.setHgap(5);
grid.setVgap(5);
JPanel panel=new JPanel();
panel.setLayout(grid);
this.getContentPane().add(panel,BorderLayout.CENTER);
this.getContentPane().add(show,BorderLayout.NORTH);
this.getContentPane().add(new JButton("清除"),BorderLayout.SOUTH);
String name[]={"1","2","3","+","4","5","6","—","7","8","9","x",".","0","=","÷"};
JButton []button=new JButton[16];
for(int i=0;i<name.length;i++){
button[i]= new JButton(name[i]);
panel.add(button[i]);
button[i].addActionListener(this);
}
show.addActionListener(this);
}
String num="0123456789";
String str="清除,x,÷,+,-";
double num1=0,num2=0,result=0;
char ch;
boolean isfirst=true;
public void actionPerformed(ActionEvent e) {
String get=e.getActionCommand();
if(isfirst&&num.indexOf(get)!=-1){
isfirst=false;
show.setText=("");
}
}
}
本人菜鸟一枚,编计算器的时候 编到我写的最后一步的时候 编译器说Multiple markers at this line
- setText cannot be resolved or is not
a field
- show cannot be resolved to a
variable
什么意思 show不是在前面定义了么。 --------------------编程问答-------------------- show.setText=("");
改为show.setText(""); --------------------编程问答-------------------- - -坑爹了,这个简单问题都没看出来 --------------------编程问答-------------------- 弱弱的问一句这个show文本框需要添加监视器么??
--------------------编程问答-------------------- show 是init方法的局部变量
在actionPerformed里不能使用
补充:Java , Java相关