import java.awt.*; import java.awt.event.*; import javax.swing.*; import java.util.*; /** * Main program for testing Rawbutton's */ public class Main extends JFrame implements MouseListener { public static void main (String [] args) { java.awt.EventQueue.invokeLater (new Runnable() { public void run() { new Main (); } }); } private ArrayList<Rawbutton> buttons = new ArrayList<Rawbutton>(); public Main () { // Window setup setSize (500, 500); setLayout (new FlowLayout()); setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE); addMouseListener (this); // Create some Rawbutton's for testing buttons.add (new Rawbutton ("Push me", 100, 100)); //*1 Create and add just like a JButton buttons.add (new Rawbutton ("Me too", 300, 300)); //*1 // And a CircleButton buttons.add (new CircleButton ("Circle", 100, 250)); //*1 setVisible (true); } /** * Catch our paint callback and pass to our "components" * NB Swing calls paint() but not paintComponent() for this case. */ public void paint (Graphics g) { //*2 We must dispatch the paint callbacks outside of Swing super.paint(g); for (Rawbutton b: buttons) //*2 b.draw (g); //*2 } /** * Catch our mouse callback and call each of our "components" to * offer them the input */ public void mousePressed (MouseEvent event) { //*3 We dispatch mouse callbacks too for (Rawbutton b: buttons) //*3 b.domouse (event.getPoint().x, event.getPoint().y); //*3 } /** * Remaining required MouseListener methods */ public void mouseClicked (MouseEvent event) {} public void mouseReleased (MouseEvent event) {} public void mouseEntered (MouseEvent event) {} public void mouseExited (MouseEvent event) {} }