Experiment 10

 

Import  Java  AWT  Import  the javax  Swing  public  class JFramedemo the extends the JFrame { Private Box Box  Private Container Container  Private the JTextField  text  Private the JPanel Panel1  Panel2  Private String Sl  "the Backspace"  " the CE "  " C "  // there will be an array of content displayed on the calculator inside  Private S2 String 








"1" "2" "3" "+" "sqrt" "4""5" "6" "-" "%" "7" "8" "9" "*" "1/x" "0" ,"+/-" "." "/" "=" 
public JFramedemo {
this 
setTitle "Calculator display interface" 
the this 
The setBounds  300  300  500  500 
Container 
the getContentPane 
Container 
SetLayout  new new the FlowLayout  // set streaming content pane layout  text  the JTextField new new  15  Box  Box  createVerticalBox  Panel1 


new JPanel new GridLayout 20 )
//panel1.setLayout(new GridLayout(1,3,10,0)); 
panel2 
new JPanel 
panel2 
setLayout new GridLayout 10 10 )
for int on the contents of the array S1 // added to the Button button panel1 
{
panel1 
the Add  new new the JButton  S1 
}
for  int  20 is  / / S2 the content added to the array of button button panel2 
{
panel2 
the Add  new new the JButton  S2 
}
box 
add text 
box 
add Box createVerticalStrut 15 
box 
add panel1 
box 
add Box createVerticalStrut 25 
box 
add panel2 
container 
add box 
Pack 
// resize the window, to adapt the size and layout of the component 
setVisible 
to true 
the this 
SetDefaultCloseOperation  EXIT_ON_CLOSE 
}
public  static void main  String  args  {
new new JFramedemo 

}
}

Experience:

1 in the preparation of the calculator to pay attention to the use of the package

Note that a method using two add

Guess you like

Origin www.cnblogs.com/ltx515/p/10963991.html