390 likes | 621 Views
Java?????. ??????(?????????) ???? ???? ???? ???? ????? ???. ????. ??????????????,???????????????????????,?????????????,??????????????????????????applet?????????????????????. import?javax.swing.*; import?java.awt.*;public?class?exec? { ?public?static?void?main(String?[]?args) ?{ ??JFrame?f=n
E N D
1. Java???? ??????????
IT??????
2. Java????? ??????(?????????)
????
????
????
????
?????
???
3. ???? ??????????????,??????????
?????????????,?????????????,?????????????????
?????????applet?????????????????????
4. import javax.swing.*;import java.awt.*;
public class exec { public static void main(String [] args) { JFrame f=new JFrame("Hello!"); f.setLocation(10,100); f.setSize(600,400); f.getContentPane().setLayout(new FlowLayout()); JButton jb1=new JButton("Click 1"); JButton jb2=new JButton("Click 2"); JButton jb3=new JButton("Click 3"); f.getContentPane().add(jb1); f.getContentPane().add(jb2); f.getContentPane().add(jb3); f.setVisible(true); } }
5. ??,??????????????????,?????????????,?:import javax.swing.*;import java.awt.*;
public class exec { public static void main(String [] args) { JFrame f=new JFrame("Hello!"); f.setLocation(10,100); f.setSize(600,400); f.getContentPane().setLayout(new FlowLayout(1,10,100)); JButton jb1=new JButton("Click 1"); JButton jb2=new JButton("Click 2"); JButton jb3=new JButton("Click 3"); f.getContentPane().add(jb1); f.getContentPane().add(jb2); f.getContentPane().add(jb3); f.setVisible(true); } }
6. ??:1)?????????????????????:??????????,?0?????,1????,2???,3????,4????;??????????;???????????2)????????????,???????,????,???????????????,????????????????????????100???????,?????????,????????????????????????????????????,???setResizable()????,?:
7. import javax.swing.*;import java.awt.*;
public class exec { public static void main(String [] args) { JFrame f=new JFrame("Hello!"); f.setLocation(10,100); f.setSize(600,400); f.getContentPane().setLayout(new FlowLayout(1,10,100)); JButton jb1=new JButton("Click 1"); JButton jb2=new JButton("Click 2"); JButton jb3=new JButton("Click 3"); f.getContentPane().add(jb1); f.getContentPane().add(jb2); f.getContentPane().add(jb3); f.setResizable(false);//?? f.setVisible(true); } }
8. 3)??????????????????,???????????,???????????????,???????????????????????????,?????????????????:import javax.swing.*;import java.awt.*;
public class exec { public static void main(String [] args) { JFrame f=new JFrame("Hello!"); f.setLocation(10,100); f.setSize(150,400); f.getContentPane().setLayout(new FlowLayout(1,10,10)); JLabel l=new JLabel("****???****"); JLabel l1=new JLabel("?1:"); JLabel l2=new JLabel("?2:"); JLabel l3=new JLabel("?:"); JTextField t1=new JTextField(5); JTextField t2=new JTextField(5); JTextField t3=new JTextField(10); JButton b=new JButton("Sum"); JPanel p1=new JPanel(); JPanel p2=new JPanel(); JPanel p3=new JPanel(); JPanel p4=new JPanel(); JPanel p5=new JPanel(); p1.setLayout(new FlowLayout(FlowLayout.CENTER,0,10)); p1.add(l); p2.setLayout(new FlowLayout(FlowLayout.CENTER,10,0)); p2.add(l1); p2.add(t1); p3.setLayout(new FlowLayout(FlowLayout.CENTER,10,0)); p3.add(l2); p3.add(t2); p4.setLayout(new FlowLayout(FlowLayout.CENTER,10,0)); p4.add(l3); p4.add(t3); p5.setLayout(new FlowLayout(FlowLayout.CENTER,10,10)); p5.add(b); f.getContentPane().add(p1); f.getContentPane().add(p2); f.getContentPane().add(p3); f.getContentPane().add(p4); f.getContentPane().add(p5); f.setVisible(true);
} }
9. ???? ???????????,?????
???????????,????????????????,??????????????
??????????,??????????,??????,???????
???????????????,????????????????,??,?????????????????????
????:panel.setLayout(new GridLayout(5,4));
????:panel.add(new JButton(“1”));
panel.add(new JButton(“2”));
10. import javax.swing.*;import java.awt.*;
public class exec { public static void main(String [] args) { JFrame f=new JFrame("Hello!"); f.setLocation(10,100); f.setSize(600,400); f.setMinimumSize(new Dimension(200,100)); f.getContentPane().setLayout(new GridLayout(3,3,10,10)); JButton[] jb=new JButton[9]; for(int i=0;i<jb.length;i++) { jb[i]=new JButton(String.valueOf(i)); f.getContentPane().add(jb[i]); }
f.setVisible(true); } }??:???????????????????,??????????,??????????????????
11. ???? ??????????????? : ?(north)??(south)??(east)??(west)??(center),??????????
???????????????,???????????????????
?????????????,????????
???????????????????add(Object,String)//Object??????;String???????,?:BorderLayout.NORTH
????????:?????????????
12. ?????????????????????????
??????????:????????????,??????????????
?:panel = new Panel();
panel.add(new Button(“??”));
panel.add(new Label(“??”));
add(panel,BorderLayout.SOUTH);
13. import javax.swing.*;import java.awt.*;
public class exec { public static void main(String [] args) { JFrame f=new JFrame("Hello!"); f.setLocation(10,100); f.setSize(600,400); f.setMinimumSize(new Dimension(200,100)); f.getContentPane().setLayout(new BorderLayout(5,10)); JButton jb1=new JButton("1"); JButton jb2=new JButton("2"); JButton jb3=new JButton("3"); JButton jb4=new JButton("4"); JButton jb5=new JButton("5"); f.getContentPane().add(jb1,BorderLayout.NORTH); f.getContentPane().add(jb2,BorderLayout.SOUTH); f.getContentPane().add(jb3,BorderLayout.EAST); f.getContentPane().add(jb4,BorderLayout.WEST); f.getContentPane().add(jb5,BorderLayout.CENTER); f.setVisible(true); } }??:???????????????????????????????????,????????????????????????????????????????,????????????????,??,???????????????????
14. ????(CardLayout) ??????????????,???????????
?????????:
1?????????:mycard=new CardLayout();
2?????:container.setLayout(mycard)
3?????:container.add(????,??);
4???:mycard.show()
15. ?????????(con???)