package jiangcai;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.JButton;
import java.awt.FlowLayout;
import java.awt.Dimension;
import javax.swing.JFrame;
import javax.swing.JTextField;
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Cal c =new Cal();
c.initUI ();
}
public void initUI(){
// instantiate class object container assembly JFrame form
JFrame frame =new JFrame();
// Set the attribute value form: title, size, display position, the closing operation, layout, visible,
frame.setTitle("Calculator");
// set the title property value
frame.setSize(new Dimension(300,350));
frame.setLocationRelativeTo(null);
frame.setDefaultCloseOperation(3);
// Instantiate Object FlowLayout flow layout class, setting alignment, horizontal spacing, vertical spacing
FlowLayout f1=new FlowLayout(FlowLayout.CENTER,5,5);
frame.setLayout(f1);
// instantiate an object class element assembly, then the component is added to the object on the form (adding components to form visible prior to completion).
JTextField screen =new JTextField();
screen.setPreferredSize(new Dimension(300,30));
frame.add(screen);
JButton jia =new JButton(" + ");
frame.add(jia);
JButton jian =new JButton(" - ");
frame.add(jian);
JButton cheng =new JButton(" x ");
frame.add(cheng);
JButton chu =new JButton(" / ");
frame.add (chu);
JButton yi =new JButton(" 1 ");
frame.add(yi);
JButton er =new JButton(" 2 ");
frame.add (s);
JButton san =new JButton(" 3 ");
frame.add(san);
JButton si =new JButton(" 4 ");
frame.add(si);
JButton wu =new JButton(" 5 ");
frame.add(wu);
JButton liu =new JButton(" 6 ");
frame.add(liu);
JButton qi =new JButton(" 7 ");
frame.add(qi);
JButton ba =new JButton(" 8 ");
frame.add(ba);
JButton jiu =new JButton(" 9 ");
frame.add(jiu);
JButton ling =new JButton(" 0 ");
frame.add(ling);
JButton deng =new JButton(" = ");
frame.add(deng);
JButton CE =new JButton(" CE ");
frame.add(CE);
frame.setVisible(true);
}
}
result: