390 likes | 621 Vues
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. importjavax.swing.*;importjava.awt.*;
publicclassexec{publicstaticvoidmain(String[]args){JFramef=newJFrame("Hello!");f.setLocation(10,100);f.setSize(600,400);f.getContentPane().setLayout(newFlowLayout());JButtonjb1=newJButton("Click1");JButtonjb2=newJButton("Click2");JButtonjb3=newJButton("Click3");f.getContentPane().add(jb1);f.getContentPane().add(jb2);f.getContentPane().add(jb3);f.setVisible(true);}}
5. ??,??????????????????,?????????????,?:importjavax.swing.*;importjava.awt.*;
publicclassexec{publicstaticvoidmain(String[]args){JFramef=newJFrame("Hello!");f.setLocation(10,100);f.setSize(600,400);f.getContentPane().setLayout(newFlowLayout(1,10,100));JButtonjb1=newJButton("Click1");JButtonjb2=newJButton("Click2");JButtonjb3=newJButton("Click3");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. importjavax.swing.*;importjava.awt.*;
publicclassexec{publicstaticvoidmain(String[]args){JFramef=newJFrame("Hello!");f.setLocation(10,100);f.setSize(600,400);f.getContentPane().setLayout(newFlowLayout(1,10,100));JButtonjb1=newJButton("Click1");JButtonjb2=newJButton("Click2");JButtonjb3=newJButton("Click3");f.getContentPane().add(jb1);f.getContentPane().add(jb2);f.getContentPane().add(jb3);f.setResizable(false);//??f.setVisible(true);}}
8. 3)??????????????????,???????????,???????????????,???????????????????????????,?????????????????:importjavax.swing.*;importjava.awt.*;
publicclassexec{publicstaticvoidmain(String[]args){JFramef=newJFrame("Hello!");f.setLocation(10,100);f.setSize(150,400);f.getContentPane().setLayout(newFlowLayout(1,10,10));JLabell=newJLabel("****???****");JLabell1=newJLabel("?1:");JLabell2=newJLabel("?2:");JLabell3=newJLabel("?:");JTextFieldt1=newJTextField(5);JTextFieldt2=newJTextField(5);JTextFieldt3=newJTextField(10);JButtonb=newJButton("Sum");JPanelp1=newJPanel();JPanelp2=newJPanel();JPanelp3=newJPanel();JPanelp4=newJPanel();JPanelp5=newJPanel();p1.setLayout(newFlowLayout(FlowLayout.CENTER,0,10));p1.add(l);p2.setLayout(newFlowLayout(FlowLayout.CENTER,10,0));p2.add(l1);p2.add(t1);p3.setLayout(newFlowLayout(FlowLayout.CENTER,10,0));p3.add(l2);p3.add(t2);p4.setLayout(newFlowLayout(FlowLayout.CENTER,10,0));p4.add(l3);p4.add(t3);p5.setLayout(newFlowLayout(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. importjavax.swing.*;importjava.awt.*;
publicclassexec{publicstaticvoidmain(String[]args){JFramef=newJFrame("Hello!");f.setLocation(10,100);f.setSize(600,400);f.setMinimumSize(newDimension(200,100));f.getContentPane().setLayout(newGridLayout(3,3,10,10));JButton[]jb=newJButton[9];for(inti=0;i<jb.length;i++){jb[i]=newJButton(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. importjavax.swing.*;importjava.awt.*;
publicclassexec{publicstaticvoidmain(String[]args){JFramef=newJFrame("Hello!");f.setLocation(10,100);f.setSize(600,400);f.setMinimumSize(newDimension(200,100));f.getContentPane().setLayout(newBorderLayout(5,10));JButtonjb1=newJButton("1");JButtonjb2=newJButton("2");JButtonjb3=newJButton("3");JButtonjb4=newJButton("4");JButtonjb5=newJButton("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???)