import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.*;
/**
* Main program for testing Rawbutton's
*/
public class Main {
public static void main (String [] args) {
java.awt.EventQueue.invokeLater (new Runnable() {
public void run() {
new Main ();
}
});
}
private ArrayList<Rawbutton> buttons = new ArrayList<Rawbutton>(); //*1 Create and add just like a JButton
public Main () {
// Window setup
JFrame frame = new JFrame();
frame.setSize (500, 500);
frame.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
frame.add (new Canvas (this));
// Create some Rawbutton's for testing
buttons.add (new Rawbutton ("Push me", 100, 100)); //*1
buttons.add (new Rawbutton ("Me too", 300, 300)); //*1
// And a CircleButton
buttons.add (new CircleButton ("Circle", 100, 250)); //*1
frame.setVisible (true);
}
/**
* Catch our paint callback and pass to our "components"
*/
public void draw (Graphics g) { //*2 We dispatch the paint callbacks outside of Swing
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 domouse (MouseEvent event) { //*3 We dispatch mouse callbacks too
for (Rawbutton b: buttons) //*3
b.domouse (event.getPoint().x, event.getPoint().y); //*3
}
}