5

The same program for an application or an applet

  1. // <applet code="Hello" width="200" height="30"></applet>
  2.  
  3. import java.applet.Applet;
  4. import java.awt.*;
  5. import java.awt.event.WindowAdapter;
  6. import java.awt.event.WindowEvent;
  7.  
  8. public class Hello extends Applet {
  9.     public void init() {
  10.         add(new Label("Hello from Java!"));
  11.     }
  12.  
  13.     public static void main(String args[]) {
  14.         Frame f = new Frame("Hello");
  15.  
  16.         f.addWindowListener(new WindowAdapter() {
  17.             public void windowClosing(WindowEvent e) {
  18.                 System.exit(0);
  19.             }
  20.         });
  21.  
  22.         Hello hello = new Hello();
  23.  
  24.         hello.init();
  25.  
  26.         f.add(hello);
  27.         f.pack();
  28.         f.setSize(f.getPreferredSize());
  29.         f.setVisible(true);
  30.     }
  31. }
$ javac Hello.java
$ java Hello

$ appletviewer Hello.java

Comments

Your comment:
[p] [b] [i] [u] [s] [quote] [pre] [br] [code] [url] [email] strip help 2000

Enter a maximum of 2000 characters.
Improve the presentation of your text with the following formatting tags:
[p]paragraph[/p], [b]bold[/b], [i]italics[/i], [u]underline[/u], [s]strike[/s], [quote]citation[/quote], [pre]as is[/pre], [br]line break,
[url]http://www.izend.org[/url], [url=http://www.izend.org]site[/url], [email]izend@izend.org[/email], [email=izend@izend.org]izend[/email],
[code]command[/code], [code=language]source code in c, java, php, html, javascript, xml, css, sql, bash, dos, make, etc.[/code].