Anda di halaman 1dari 10

Applet Programming

<html> <! This web page contains the information about welcome title> <head> <title> Welcome to the java </title> </head> <Body> <Center> <h2> welcome </h2> </center> <applet> </applet> </body> </html>

Applet Programming
Applet Tag: This tag supplies the name of
the applet to be loaded and tells the browser how much space the applet requires. <applet Code=hello.class Width=400 Height=200> </applet>

Applet Programming
<html> <! This web page contains the information about welcome title> <head> <title> Welcome to the java </title> </head> <Body> <Center> <h2> welcome </h2> </center> <applet Code=hello.class Width=400 Height=200> </applet> </body> </html>

Passing parameters to applets


We can supply user-defined parameters to an applet using <param> tags. Each <param..> tag has a name attribute such as colour and a value attribute such as red. E.g. we can change the colour of the text displayed to red by an applet by using a <param> tag as follows:
<applet> <param=color value=red> </applet>

Passing parameters to applets


import java.awt.* import java.applet.* public class hello extends Applet { String str; public void init() { str=getparameter(String); if(str==null) str=java; str=hello+str; }

Passing parameters to applets


public void paint(Graphics g) { g.drawString(str,10,100); } }

HTML File
<html> <! Html file > <head> <title> welcome </title> </head> <body> <applet code=hello.class Width=400 Height=200> <param name=string Value=applet> </applet> </body> </html>

Getting Input from the User


import java.awt.*; import java.applet.*; public class data extends Applet { textField t1,t2; public void init() { t1=new TextField(8); t2=new TextField(8); add(t1); add(t2); t1.setText(0); t2.settExt(0); }

Getting Input from the User


public void paint(Graphics g) { int x=0,y=0,z=0; String s1,s2,s; g.drawString(Input the number,10,50); try { s1=t1.getText(); x=Integer.parseInt(s1); s2=t2.getText(); y=Integer.parseInt(s2); }

Getting Input from the User


catch (Exception e) {} z=x+y; s=String.valueOf(z); g.drawString(the sum is ,10,77); g,.drawString(s,100,75); }
public boolean action(Event event, Object o) { repaint(); return true; } }

Anda mungkin juga menyukai