计算器界面
public class Calculator {
JFrame f ;
JTextField jtf;
JButton[ ] jbs ;
JButton clear;
public Calculator ( ) {
f = new JFrame ( "计算器V1.1" ) ;
jtf = new JTextField ( 15 ) ;
clear = new JButton ( "清空" ) ;
jbs = new JButton [ 16 ] ;
String str = "123+456-789*0.=/" ;
for ( int i = 0 ; i < jbs. length; i++ )
{
jbs[ i] = new JButton ( str. charAt ( i) + "" ) ;
}
init ( ) ;
f. setSize ( 300 , 400 ) ;
f. setVisible ( true ) ;
}
public void init ( ) {
f. setLayout ( new BorderLayout ( ) ) ;
JPanel panel = new JPanel ( ) ;
JPanel panel2 = new JPanel ( ) ;
panel. setLayout ( new FlowLayout ( ) ) ;
panel. add ( jtf) ;
panel. add ( clear) ;
panel2. setLayout ( new GridLayout ( 4 , 4 ) ) ;
for ( int i = 0 ; i < jbs. length; i++ ) {
panel2. add ( jbs[ i] ) ;
}
f. add ( panel, BorderLayout. NORTH ) ;
f. add ( panel2, BorderLayout. CENTER ) ;
}
public static void main ( String[ ] args) {
Calculator c = new Calculator ( ) ;
}
}