Appletler'de Parametre Kullanımı
Appletler'de Parametre Almak
Bir applet'in duruma göre değişik çalşıması için ona parametre aktarmak gerekebilir. Bunun için
String value=getParameter("name");
şeklinde bir ifade yazılır.
Aldığı renk parameteresine göre ekrana dikdörtgen çizen bir applet yapalım.
1 import java.applet.*;
2 import java.awt.*;
3 import java.awt.event.*;
4 public class ParametricRectangleDrawerApplet extends Applet {
5 private Color color=Color.black;
6 public void init(){
7 String value=getParameter("color");
8 if(value!=null){
9 if(value.equalsIgnoreCase("yellow")){
10 color=Color.blue;
11 }else if(value.equalsIgnoreCase("blue")){
12 color=Color.yellow;
13 }else{
14 color=Color.pink;
15 }
16 }
17 }
18 public void paint(Graphics g){
19 g.setColor(color);
20 g.fillRect(50,50,100,100);
21 }
22 }
HTML'den Applete Parametre Aktarmak
HTML'de <applet> tag'inin içerisinde <param> tag'i kullanılarak applete parameter aktarılır
<APPLET CODE="MyApplet.class">
<PARAM NAME="name" VALUE="value">
</APPLET>
Yukarıdaki applet şöyle çağrılır :
<!-- ColorRect.html -->
<html>
<body>
<applet code="ParametricRectangleDrawerApplet.class" width="100" height="200" >
<param name="color" value="yellow">
</applet>
</body>
</html>
Dosya Listesi