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
- import java.applet.Applet;
- import java.awt.Graphics;
- public class AppletExample extends Applet {
- public void paint(Graphics grap) {
- grap.drawString("Hello Applet", 100, 100);
- }
- }
Output
Let’s see another example, which works as Appletviewer tool.
Code
- import java.applet.Applet;
- import java.awt.Frame;
- import java.awt.Graphics;
- public class AppletViewer extends Frame {
- public static void main(String[] args) throws Exception {
- Class cl = Class.forName(args[0]);
- AppletViewer av = new AppletViewer();
- av.setSize(300, 300);
- av.setLayout(null);
- av.setVisible(true);
- Applet a = (Applet) cl.newInstance();
- a.start();
- Graphics gh = av.getGraphics();
- a.paint(gh);
- a.stop();
- }
- }
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.