Simple program using applet.
Program 1
Java File
1 2 3 4 5 6 7 8 9 10 11 12 | import java.applet.Applet; import java.awt.Graphics; public class FirstApplet extends Applet { int width, height; public void paint(Graphics g) { width = getSize().width; height = getSize().height; g.drawString("welcome",width/2,height/2); } } |
HTML File :
1 2 3 4 5 6 | <html> <body> <applet code="FirstApplet.class" width="300" height="300"> </applet> </body> </html> |
Program 2
Java File :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | import java.awt.*; import java.awt.event.*; import java.applet.*; public class MyButtonApplet extends Applet implements ActionListener { Button b1,b2; String msg="null"; public void init() { setLayout(new FlowLayout()); b1 = new Button("Yes"); b2 = new Button("No"); add(b1); add(b2); b1.addActionListener(this); b2.addActionListener(this); } public void actionPerformed(ActionEvent ae) { if(ae.getSource()==b1) msg = ("Pressed Yes"); if(ae.getSource()==b2) msg ="You pressed No"; repaint(); } public void paint(Graphics g) { g.drawString(msg,80,100); } } |
HTML File :
1 2 3 4 5 6 | <html> <body> <applet CODE ="MyButtonApplet.class" width = 400 height = 500> </applet> </body> </html> |
No comments:
Post a Comment
Thank you for spending your valuable time!