Title: ???? Applet?????
1???? Applet?????
2 ??
- Date?
- SimpleDateFormat?
- Math??????
- AWT?
- Frame
- Panel
- Button
3GUI????
?AWT????,?????????????????GUI??(Component)????
???????????? 1?????,?????????????,???????????????
???????????????????? 2???????????????,??????(conta
iner)????????????????,??????????????,?????????????
? 3?AWT????????Frame??Dia1og??Panel????AWT??????
,Applet???????,??Panel???????
4AWT ??????
5?????????
- ????????,AWT????????
- ??????Object???,?????Component
- ????????Component??,??????Container
- ????Container??,???????????
- ?????????,??????????????????(???????)
- ????????????????Container?????(JavaAPI)
- add()??
- remove()??
- setLayout()??
6 ??
- Applet????????
- ??????????
- Applet??????????
- Html??
- ????
7Applet????????
- Java????
- ????????main??,??JVM????
- ?????
- ????????????????,??????main???
- ??????????????
- import java.applet.
- public class MyApplet extends Applet
-
- ???????????????,??public,???Applet????
- ????????
- ?????????????????
- ??html??,??ltappletgt ????????????
- ??????html?????appletviewer???????
8????
import java.applet.Applet import
java.awt. public class Test extends
Applet public void paint(Graphics
g) g.drawOval(10,10,100,100)
lt!-- test.html??--gt ltapplet codeTest.class
height120 width400gtlt/appletgt
???????Graphics,????Java????????Graphics????,????
??paint()????g???????????
9Applet??????????
10import java.applet. import java.awt. public
class MyApple extends Applet Button b1,b2 int
sum public void init() b1new
Button("??") b2new Button("??") add(b1)add
(b2) public void start() sum0 for
(int i 1 ilt100 i) sumi public
void paint(Graphics g) g.setColor(Color.blue)
g.drawString("??????",20,60) g.setColor(
Color.red) g.drawString("sum"sum,20,100)
11???9.1
1???????sum 2?????fillOval()?drawOval() 3????
?????new Color(r,g,b) 4???????Math.radom()
12Html??
- ????
- ltapplet codeTest height120 width400gtlt/appletgt
- ltApplet ??gt
- Code????????,?????,?????html?????????
- Height?width??applet???????
13????
lt!-- test.html??????--gt ltapplet codeTest2.class
height400 width500 gt ltparam name"gao"
value"400"gt ltparam name"kuan"
value"500"gt lt/appletgt
//???? int width0,height0 String
para paragetParameter("gao") if(para!null)
height Integer.parseInt(para) paragetParam
eter("kuan") if(para!null) widthInteger.parseI
nt(para)
14????
import java.applet. import java.awt. public
class MyApple extends Applet public void
paint(Graphics g) int r,gr,b,h300,w400 i
nt x,y,x1,y1 for (int i 0 ilt100
i) r(int)(Math.random()255) gr(int
)(Math.random()255) b(int)(Math.random()255
) g.setColor(new Color(r,gr,b)) x(int)(Ma
th.random()w) y(int)(Math.random()h) x1
(int)(Math.random()105) y1x1 g.fillOva
l(x,y,x1,y1)
15??????
- ??
- ??AWT???????
- ???????
- ??Applet??????????
- ??Applet????????
- ?????
- 1?????GUI????,???(Frame??,?????)???????(Panel??,??
???),?????????(button1?button2),??????400,?300? - 2?????Applet???,?????????????
- 3???????????,???????????