[开源]问千里一个有关格式的问题
import javax.swing.*;import javax.swing.event.*;
import java.awt.*;
import java.awt.event.*;
public class Jsq extends JFrame
{
double a=0,b=0,c=0;
int i=0;
JPanel pl1=new JPanel();
JPanel pl2=new JPanel();
JTextField tf=new JTextField(10);
JButton bt=new JButton("清空");
JButton bt1=new JButton("1");
JButton bt2=new JButton("2");
JButton bt3=new JButton("3");
JButton bt4=new JButton("4");
JButton bt5=new JButton("5");
JButton bt6=new JButton("6");
JButton bt7=new JButton("7");
JButton bt8=new JButton("8");
JButton bt9=new JButton("9");
JButton bt10=new JButton("0");
JButton bt11=new JButton("+");
JButton bt12=new JButton("-");
JButton bt13=new JButton("*");
JButton bt14=new JButton("/");
JButton bt15=new JButton(".");
JButton bt16=new JButton("=");
public Jsq()
{
super("计算器");
Container c=getContentPane();
c.add(pl1,BorderLayout.NORTH);
c.add(pl2,BorderLayout.CENTER);
pl1.setLayout(new FlowLayout());
pl1.add(tf);
pl1.add(bt);
pl2.setLayout(new GridLayout(4,4));
pl2.add(bt1);
pl2.add(bt2);
pl2.add(bt3);
pl2.add(bt11);
pl2.add(bt4);
pl2.add(bt5);
pl2.add(bt6);
pl2.add(bt12);
pl2.add(bt7);
pl2.add(bt8);
pl2.add(bt9);
pl2.add(bt13);
pl2.add(bt10);
pl2.add(bt14);
pl2.add(bt15);
pl2.add(bt16);
bt.addActionListener(new shijian());
bt1.addActionListener(new shijian());
bt2.addActionListener(new shijian());
bt3.addActionListener(new shijian());
bt4.addActionListener(new shijian());
bt5.addActionListener(new shijian());
bt6.addActionListener(new shijian());
bt7.addActionListener(new shijian());
bt8.addActionListener(new shijian());
bt9.addActionListener(new shijian());
bt10.addActionListener(new shijian());
bt11.addActionListener(new shijian());
bt12.addActionListener(new shijian());
bt13.addActionListener(new shijian());
bt14.addActionListener(new shijian());
bt15.addActionListener(new shijian());
bt16.addActionListener(new shijian());
setSize(200,200);
setVisible(true);
setResizable(false);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public static void main(String args[])
{
new Jsq();
}
class shijian implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==bt)
{
tf.setText("");
}
if(e.getSource()==bt1)
{
tf.setText(tf.getText()+String.valueOf(1));
}
if(e.getSource()==bt2)
{
tf.setText(tf.getText()+String.valueOf(2));
}
if(e.getSource()==bt3)
{
tf.setText(tf.getText()+String.valueOf(3));
}
if(e.getSource()==bt4)
{
tf.setText(tf.getText()+String.valueOf(4));
}
if(e.getSource()==bt5)
{
tf.setText(tf.getText()+String.valueOf(5));
}
if(e.getSource()==bt6)
{
tf.setText(tf.getText()+String.valueOf(6));
}
if(e.getSource()==bt7)
{
tf.setText(tf.getText()+String.valueOf(7));
}
if(e.getSource()==bt8)
{
tf.setText(tf.getText()+String.valueOf(8));
}
if(e.getSource()==bt9)
{
tf.setText(tf.getText()+String.valueOf(9));
}
if(e.getSource()==bt10)
{
tf.setText(tf.getText()+String.valueOf(0));
}
if(e.getSource()==bt15)
{
tf.setText(tf.getText()+".");
}
if(e.getSource()==bt11)
{
a=Double.parseDouble(tf.getText().trim());
tf.setText("");
i=1;
}
if(e.getSource()==bt12)
{
a=Double.parseDouble(tf.getText().trim());
tf.setText("");
i=2;
}
if(e.getSource()==bt13)
{
a=Double.parseDouble(tf.getText().trim());
tf.setText("");
i=3;
}
if(e.getSource()==bt14)
{
a=Double.parseDouble(tf.getText().trim());
tf.setText("");
i=4;
}
if(e.getSource()==bt16)
{
if(i==1)
{
b=Double.parseDouble(tf.getText().trim());
c=a+b;
tf.setText(String.valueOf(c));
}
if(i==2)
{
b=Double.parseDouble(tf.getText().trim());
c=a-b;
tf.setText(String.valueOf(c));
}
if(i==3)
{
b=Double.parseDouble(tf.getText().trim());
c=a*b;
tf.setText(String.valueOf(c));
}
if(i==4)
{
b=Double.parseDouble(tf.getText().trim());
if(b==0)
{
tf.setText("0不能作为分母");
}
c=a/b;
tf.setText(String.valueOf(c));
}
}
}
}
}
这是个简单计算器的程序,请问这个程序的格式怎样呢?有哪些要修改的地方?