package Lect40CustomWidget; import java.awt.*; import javax.swing.*; public class CustomWidgetExample { private final static int WIDTH = 500, HEIGHT = 400; public CustomWidgetExample() { JFrame frame = buildFrame(); buildGUI(frame); displayFrame(frame); } public JFrame buildFrame() { try { UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); } catch (Exception e) {} // Create a top-level window to put the picture in JFrame frame; frame = new JFrame("Simple Custom Widget"); frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); return frame; } public void buildGUI(JFrame frame) { JComponent widget; widget = new JButton("Hello"); // widget = new RedSquareWidget(); // widget = new MovableRedSquareWidget(); // widget = new AnimatedRedSquareWidget(); widget.setPreferredSize(new Dimension(WIDTH, HEIGHT)); frame.setContentPane(widget); } public void displayFrame(JFrame frame) { frame.setLocation(100, 100); frame.pack(); frame.show(); } static public void main(String[] args) { new CustomWidgetExample(); } }