/*
* Main.java
*
* Created on May 17, 2006, 11:32 PM
*/
package heavyswing;
import java.awt.Canvas;
import java.awt.Component;
import java.awt.Graphics;
import java.awt.Panel;
import java.awt.Window;
import javax.swing.JButton;
/**
*
* @author Scott Palmer
*/
public class Main
{
/** Creates a new instance of Main */
public Main()
{
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) throws InterruptedException
{
Window window = new Window(null);
window.setLayout(null);
window.setBounds(10,10,220,200);
JButton swingButton = new JButton("I'm Swing!");
window.add(swingButton);
swingButton.setLocation(10,10);
swingButton.setSize(swingButton.getPreferredSize());
JButton swingButton2 = new JButton("I'm Swing on a Heavyweight!");
Panel heavyPanel = new Panel(null);
heavyPanel.add(swingButton2);
swingButton2.setLocation(0,0);
swingButton2.setSize(swingButton2.getPreferredSize());
window.add(heavyPanel);
heavyPanel.setLocation(10,40);
heavyPanel.setSize(swingButton2.getPreferredSize());
// Add a heavyweight canvas
Canvas canvas = new FancyCanvas();
// comment out the next line to see the other Swing button
window.add(canvas);
canvas.setLocation(0,0);
canvas.setSize(220,200);
// It seems that the components are drawn in the reverse order in
// which they were added. But is it always so?
window.setVisible(true);
Thread.sleep(10000);
window.setVisible(false);
window.dispose();
}
}
// This could be a 3D canvas
class FancyCanvas extends Canvas
{
@Override
public void paint(Graphics g)
{
g.drawLine(0,0,getWidth(),getHeight());
g.drawLine(0,getHeight(),getWidth(),0);
}
}