Creating your own
appletviewer
As you know well that appletviewer tool creates
a frame and displays the output of applet in the frame.You can also create your
frame and display the applet output.
Example that works like appletviewer tool
Let's see the simple example that works like
appletviewer tool. This example displays applet on the frame.
1. import java.applet.Applet;
2. import java.awt.Frame;
3. import java.awt.Graphics;
4.
5. public class MyViewer extends Frame{
6. public static void main(String[] args) throws Exception{
7. Class c=Class.forName(args[0]);
8.
9. MyViewer v=new MyViewer();
10. v.setSize(400,400);
11. v.setLayout(null);
12. v.setVisible(true);
13.
14. Applet a=(Applet)c.newInstance();
15. a.start();
16. Graphics g=v.getGraphics();
17. a.paint(g);
18. a.stop();
19.
20. }
21.
22. }
1. //simple program of applet
2.
3. import java.applet.Applet;
4. import java.awt.Graphics;
5.
6. public class First extends Applet{
7.
8. public void paint(Graphics g){g.drawString("Welcome",50, 50);}
9. }
Output:
No comments:
Post a Comment