import java.awt.*; import java.awt.event.*; public class Foo extends Canvas { Foo() { setBackground(Color.white); setSize(100,100); Frame f = new Frame(); f.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent evt) {System.exit(0);} }); f.add(this); f.pack(); f.show(); } public void paint(Graphics g) { g.drawLine(10, 10, 90, 90); } public static void main(String args[]) { new Foo(); } } |
import java.awt.*; import java.awt.event.*; public class Foo extends Frame { Foo() { addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent evt) {System.exit(0);} }); Canvas canv=new Canvas() { public void paint(Graphics g) { g.drawLine(10,10,90,90); } }; canv.setBackground(Color.white); canv.setSize(100,100); add("Center", canv); pack(); } public static void main(String args[]) { new Foo().show(); } } |
// <applet code="Foo.class" width=100 height=100></applet> import java.applet.Applet; import java.awt.*; import java.awt.event.*; public class Foo extends Applet { public void init() { setBackground(Color.white); } public void paint(Graphics g) { g.drawLine(10,10,90,90); } public static void main(String args[]) { Applet applet=new Foo(); applet.init(); Frame f=new Frame(); f.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent evt) {System.exit(0);} }); f.add(applet); f.setSize(100+20,100+30); f.show(); } } |