topical media & game development
graphic-processing-algorithm-Ch04-p107-MyControl.pde / pde
class MyControl extends Frame{
String status = "Move";
String part = "Group";
Button bexit;
Choice transform, whatPart;
Label coordsDisplay;
TextField input;
MyControl() {
super("Tools");
setSize(300,400);
setLocation(420,0);
setVisible(true);
//*** Button setup
bexit = new Button("Exit");
bexit.setLocation(width-50, height-30);
bexit.setSize(40, 20);
//*** Label setup
coordsDisplay = new Label();
coordsDisplay.setLocation(10, height-30);
coordsDisplay.setSize(100, 20);
//*** TextField setup
input = new TextField("Welcome");
input.setLocation(10, height-60);
input.setSize(width-20, 20);
//*** Choice setup
transform = new Choice();
transform.addItem("Move");
transform.addItem("Rotate");
transform.addItem("Scale");
transform.setLocation(width/2+20, 40);
transform.setSize(100, 40);
//*** Choice setup
whatPart = new Choice();
whatPart.addItem("Group");
whatPart.addItem("Shape");
whatPart.addItem("Segment");
whatPart.setLocation(width/2-80, 40);
whatPart.setSize(100, 30);
//*** Screen setup
setLayout(null); //use the user specified size and location
add(transform);
add(whatPart);
add(coordsDisplay);
add(input);
add(bexit);
transform.addItemListener(new ItemListener() {
public void itemStateChanged(ItemEvent e) {
status = transform.getItem(transform.getSelectedIndex());
control.input.setText(status);
}
}
);
whatPart.addItemListener(new ItemListener() {
public void itemStateChanged(ItemEvent e) {
part = whatPart.getItem(whatPart.getSelectedIndex());
}
}
);
bexit.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
System.exit(0);
}
}
);
input.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
println("textfield = " + input.getText());
}
}
);
}
}
(C) Æliens
04/09/2009
You may not copy or print any of this material without explicit permission of the author or the publisher.
In case of other copyright issues, contact the author.