Program : 24 Aim: Write a program to print hello in an applet. import [Link].*; import [Link].*; import [Link].
*; /* <applet code="hello" width = 100 height = 100> </applet> */ public class hello extends Applet { String msg; public void paint(Graphics g) { [Link](msg,50,50); } } HTML File <html> <head> <title> hello world example </title> </head> <body> <applet code = "[Link]" width = 100 height = 100> </applet> </body> </html> OUTPUT
Date: 15.11.2012
Program: 25 Aim: Write a program to illustrate life cycle of applets import [Link].*; import [Link].*; import [Link].*; /* <applet code="hello" width = 100 height = 100> </applet> */ public class hello extends Applet { String msg ; public void init() { msg = " Init " ; } public void start() { msg = "Start"; repaint(); } public void stop() { msg = "Stop"; repaint(); } public void destroy() { msg = "destroy"; repaint(); } public void paint(Graphics g) { [Link](msg,50,50); } }
Date: 15.11.2012
HTML File <html> <head> <title> hello world example </title> </head> <body> <applet code = "[Link]" width = 100 height = 100> </applet> </body> </html>
OUTPUT
Program: 26 Date: 15.11.2012 Aim: Write a program to display a color bar having all colors on the screen using applets. import [Link].*; import [Link].*; import [Link].*; /* <applet code="hello" width = 100 height = 100> </applet> */ public class hello extends Applet { Color colors[]={ [Link], [Link], [Link], [Link], [Link], [Link], [Link], [Link], [Link], [Link], [Link], [Link]}; public void paint(Graphics g) { Dimension d = getSize(); int x = [Link]/[Link]; setBackground([Link]); for (int i=0; i<[Link] ; i++ ) { [Link](colors[i]); [Link](i*x, 0, (i+1) * x, [Link]); } } } HTML Code <html> <head> <title> ques 25 </title> </head> <body> <applet code = "[Link]" width = 600 height = 300> </applet> </body> </html>
Output
Program: 27 Aim: Write a program to create a applet using a moving banner. import [Link].*; import [Link].*; import [Link].*; /* <applet code="hello" width = 100 height = 100> </applet> */ public class hello extends Applet implements Runnable { String msg=" A Simple Moving Banner. "; Thread t = null; int state; boolean stopflag; public void init() { setForeground([Link]); } public void start() { t = new Thread(this); stopflag = false; [Link](); } public void run() { char ch; for(;;){ try{ repaint(); [Link](250); ch=[Link](0); msg=[Link](1,[Link]()); msg=msg+ch; if(stopflag) break; }catch(InterruptedException e) {} } }
Date: 15.11.2012
public void stop() { stopflag = true; t = null; } public void paint(Graphics g) { [Link](msg,50,30); showStatus("Simple Banner"); } } Output :
Program: 28 Aim: Write a program to create a calculator. import [Link].*; import [Link].*; import [Link].*; import [Link].*; public class calc implements ActionListener { int c,n; String s1,s2,s3,s4,s5; JButton sum,sub,mul,div,eq; JButton one,two,three,four,five,six,seven,eight,nine,zero; JTextField jtf; Frame f; Panel p; GridLayout g1; calc() { f = new Frame("Calculator"); p = new Panel(); sum = new JButton("+"); [Link](this); sub = new JButton("-"); [Link](this); mul = new JButton("x"); [Link](this); div = new JButton("/"); [Link](this); eq = new JButton("="); [Link](this); zero = new JButton("0"); [Link](this); one = new JButton("1"); [Link](this); two = new JButton("2"); [Link](this); three = new JButton("3"); [Link](this); four = new JButton("4"); [Link](this); five = new JButton("5");
Date: 15.11.2012
[Link](this); six = new JButton("6"); [Link](this); seven = new JButton("7"); [Link](this); eight = new JButton("8"); [Link](this); nine = new JButton("9"); [Link](this); jtf = new JTextField(20); [Link](jtf); [Link]([Link]); g1 = new GridLayout(4,4,10,20); [Link](g1); [Link](one); [Link](two); .add(three); [Link](four); [Link](five); [Link](six); [Link](seven); [Link](eight); [Link](nine); [Link](zero); [Link](sum); [Link](sub); [Link](mul); [Link](div); [Link](eq); [Link](p); [Link](100,200); [Link](true); } public void actionPerformed(ActionEvent e) { if([Link]()==zero) { s3 = [Link](); s4 = "0"; s5 = s3 + s4; [Link](s5); } if([Link]()==one) { s3 = [Link](); s4 = "1"; s5 = s3 + s4; [Link](s5); } if([Link]()==two) { s3 = [Link](); s4 = "2"; s5 = s3 + s4; [Link](s5); }
if([Link]()==three) { s3 = [Link](); s4="3"; s5=s3+s4; [Link](s5); } if([Link]()==four) { s3 = [Link](); s4 = "4"; s5 = s3 + s4; [Link](s5); } if([Link]()== five) { s3 = [Link](); s4 = "5"; s5 = s3 + s4; [Link](s5); } if([Link]()== six) { s3 = [Link](); s4 = "6"; s5 = s3 + s4; [Link](s5); } if([Link]()==seven) { s3 = [Link](); s4 = "7"; s5 = s3 + s4; [Link](s5); } if([Link]()==eight) { s3 = [Link](); s4 = "8"; s5 = s3 + s4; [Link](s5); } if([Link]()==nine) { s3 = [Link](); s4 = "9"; s5 = s3 + s4;
[Link](s5); } if([Link]()== sum) { s1 = [Link](); [Link](""); c=1; } if([Link]()== sub) { s1 = [Link](); [Link](""); c=2; } if([Link]()== mul) { s1 = [Link](); [Link](""); c=3; } if([Link]()== div) { s1 = [Link](); [Link](""); c=4; } if([Link]()==eq) { s2 = [Link](); if(c==1) { n=[Link](s1)+[Link](s2); [Link]([Link](n)); } else if(c==2) { n=[Link](s1)-[Link](s2); [Link]([Link](n)); }
else if(c==3) { n=[Link](s1)*[Link](s2); [Link]([Link](n)); } else if(c==4) { n=[Link](s1)/[Link](s2); [Link]([Link](n)); } } } public static void main(String args[]) { calc c=new calc(); } } Output :