Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
Creating simple example applets                                  1
ObjectivesOn completion of this period, you would be able to  learn• Creating simple applets                              ...
RecapIn the previous classes , you have studied about• Order of applet initialization• Order of applet termination        ...
Creating simple appletWe will go through some exampleapplet                                  4
1.Write an applet to draw and fill rectangle     import java.awt.*;     import java.applet.*;     /*     <applet code = My...
2. Write an applet to draw a stringimport java.awt.*;import java.applet.*;/*<applet code = SimpleApplet width = 400 height...
3. Program to test all methods of appletimport java.awt.*;import java.applet.*;/*<applet code = Allmethods width = 400 hei...
3. Program to test all methods of applet                                                           contd..public void dest...
4. Applet program to change the foreground          and back ground colors     import java.awt.*;     import java.applet.*...
Applet program to change the foreground and             back ground colors     contd..    // Initialize the string to be d...
Summary• We have written several applet programs• Covering the different aspects of applets                               ...
Quiz1. Where is the JVM available to run an applet    when an applet is downloaded from an    internet into our local mach...
Frequently Asked Questions• Write applet program to draw the following  diagram                                           ...
Upcoming SlideShare
Loading in …5
×

Creating applets.60

343 views

Published on

  • Be the first to comment

  • Be the first to like this

Creating applets.60

  1. 1. Creating simple example applets 1
  2. 2. ObjectivesOn completion of this period, you would be able to learn• Creating simple applets 2
  3. 3. RecapIn the previous classes , you have studied about• Order of applet initialization• Order of applet termination 3
  4. 4. Creating simple appletWe will go through some exampleapplet 4
  5. 5. 1.Write an applet to draw and fill rectangle import java.awt.*; import java.applet.*; /* <applet code = MyApplet width= 200 height=150> </applet>*/ public class MyApplet extends Applet { public void paint(Graphics g) { g.drawRect(50,50,100,100); g.fillRect(200,200,300,300); //draw filled in rectangle of default color } } 5
  6. 6. 2. Write an applet to draw a stringimport java.awt.*;import java.applet.*;/*<applet code = SimpleApplet width = 400 height = 400 ></applet>*/public class SimpleApplet extends Applet { public void paint(Graphics g) { g.drawString ("Welcome to the world of applet programming", 20, 20); }} 6
  7. 7. 3. Program to test all methods of appletimport java.awt.*;import java.applet.*;/*<applet code = Allmethods width = 400 height= 400></applet>*/public class Allmethods extends Applet { String s1, s2, s3, s4; public void init() { s1= "message from init method"; } public void start() { s2= "message from start method"; } public void stop() { s3= " message from stop method"; } 7
  8. 8. 3. Program to test all methods of applet contd..public void destroy() { s4= " message from destroying"; } public void paint(Graphics g) {g.drawString("Demo for testing all methods of applet", 20,40); if(s1!=null) g.drawString(s1,20,80);if(s2!=null) g.drawString(s2,20,100); if(s3!=null)g.drawString(s3,20,120); if(s4!=null)g.drawString(s4,20,140); }} 8
  9. 9. 4. Applet program to change the foreground and back ground colors import java.awt.*; import java.applet.*; import java.awt.Graphics; import java.awt.Color; /* <applet code="Sample" width=300 height=50> </applet> */ public class Sample extends Applet{ String msg; // set the foreground and background colors. public void init() { setBackground(Color.cyan); setForeground(Color.red); msg = "Inside init( ) --"; } 9
  10. 10. Applet program to change the foreground and back ground colors contd.. // Initialize the string to be displayed. public void start() { msg += " Inside start( ) --"; } // Display msg in applet window. public void paint(Graphics g) { msg += " Inside paint( )."; g.drawString(msg, 10, 30); } } 10
  11. 11. Summary• We have written several applet programs• Covering the different aspects of applets 11
  12. 12. Quiz1. Where is the JVM available to run an applet when an applet is downloaded from an internet into our local machine where java was not installeda) Localb) Remote 12
  13. 13. Frequently Asked Questions• Write applet program to draw the following diagram 13

×