«Back to Home

Core Java

Topics

How To Create Our Own Appletviewer In Java

Create our own Appletviewer
 
Appletviewer tool is used to create a frame and display the output of Applet in the frame. We can also create our frame and display the Applet output.
 
Let’s see an example of Applet, given below.
 
Code
  1. import java.applet.Applet;  
  2. import java.awt.Graphics;  
  3. public class AppletExample extends Applet {  
  4.     public void paint(Graphics grap) {  
  5.         grap.drawString("Hello Applet"100100);  
  6.     }  
  7. }  
77

Output

78

Let’s see another example, which works as Appletviewer tool.
 
Code
  1. import java.applet.Applet;  
  2. import java.awt.Frame;  
  3. import java.awt.Graphics;  
  4. public class AppletViewer extends Frame {  
  5.     public static void main(String[] args) throws Exception {  
  6.         Class cl = Class.forName(args[0]);  
  7.         AppletViewer av = new AppletViewer();  
  8.         av.setSize(300300);  
  9.         av.setLayout(null);  
  10.         av.setVisible(true);  
  11.         Applet a = (Applet) cl.newInstance();  
  12.         a.start();  
  13.         Graphics gh = av.getGraphics();  
  14.         a.paint(gh);  
  15.         a.stop();  
  16.     }  
  17. }  
79

Summary

Thus, we learnt that Java Appletviewer tool is used to create a frame and display the output of Applet in the frame and also learnt how to create it in Java.