JAVA计算机不显示
论文问答
1
package ai1;
import javax.swing.;
import java.awt.;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class Ts {
public static void main(String[] args) {
JS win=new JS();
}
}
class JS extends JFrame implements ActionListener{
private StringBuilder sBuilder = new StringBuilder();
JTextArea text=new JTextArea();
double a,b;
Double sum;
int i;
public JS()
{
setBounds(100,100,400,400);
setTitle("计算器");
JMenuBar menubar=new JMenuBar();
this.setLayout(new BorderLayout());
JPanel p1=new JPanel();
JPanel p2=new JPanel();
text.setPreferredSize(new Dimension (370,60));//设置组件大小
p2.setLayout(new FlowLayout());
p1.add(text);
this.add(p1,BorderLayout.NORTH);
p2.setLayout(new GridLayout(5,4)); //添加按钮
JButton button[]=new JButton[20];
button[0]=new JButton("C");
button[1]=new JButton("CE");
button[2]=new JButton("%");
button[3]=new JButton("÷");
button[4]=new JButton("7");
button[5]=new JButton("8");
button[6]=new JButton("9");
button[7]=new JButton("x");
button[8]=new JButton("4");
button[9]=new JButton("5");
button[10]=new JButton("6");
button[11]=new JButton("—");
button[12]=new JButton("1");
button[13]=new JButton("2");
button[14]=new JButton("3");
button[15]=new JButton("+");
button[16]=new JButton("±");
button[17]=new JButton("0");
button[18]=new JButton(".");
button[19]=new JButton("=");
for(int i=0;i<button.length;i++ )
p2.add(button[i]);
for(int i=0;i<button.length;i++)
button[i].addActionListener(this);
this.setVisible(true);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
String lab=e.getActionCommand();
if(lab.equals("0"))
{
sBuilder.append("0");
text.setText(sBuilder.toString());
}
}
}运行结果怎么没有显示计算机按钮
发表回复