5
The same program for an application or an applet
- // <applet code="Hello" width="200" height="30"></applet>
- import java.applet.Applet;
- import java.awt.*;
- import java.awt.event.WindowAdapter;
- import java.awt.event.WindowEvent;
- public class Hello extends Applet {
- public void init() {
- add(new Label("Hello from Java!"));
- }
- public static void main(String args[]) {
- Frame f = new Frame("Hello");
- f.addWindowListener(new WindowAdapter() {
- public void windowClosing(WindowEvent e) {
- System.exit(0);
- }
- });
- Hello hello = new Hello();
- hello.init();
- f.add(hello);
- f.pack();
- f.setSize(f.getPreferredSize());
- f.setVisible(true);
- }
- }
$ javac Hello.java
$ java Hello
$ appletviewer Hello.java
Comments