Biblioteca Java - Rev 27
Subversion Repositories:
package ex3_roadtraffic;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.*;
public class CarWindow extends JFrame {
CarWorld display;
JButton addLeft;
JButton addRight;
public CarWindow() {
Container c = getContentPane();
c.setLayout(new BorderLayout());
display = new CarWorld();
c.add("Center",display);
addLeft = new JButton("Add Left");
addRight = new JButton("Add Right");
addLeft.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
display.addCar(Car.REDCAR);
}
}
);
addRight.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
display.addCar(Car.BLUECAR);
}
}
);
JPanel p1 = new JPanel();
p1.setLayout(new FlowLayout());
p1.add(addLeft);
p1.add(addRight);
c.add("South",p1);
setDefaultCloseOperation(EXIT_ON_CLOSE);
}
}
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.*;
public class CarWindow extends JFrame {
CarWorld display;
JButton addLeft;
JButton addRight;
public CarWindow() {
Container c = getContentPane();
c.setLayout(new BorderLayout());
display = new CarWorld();
c.add("Center",display);
addLeft = new JButton("Add Left");
addRight = new JButton("Add Right");
addLeft.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
display.addCar(Car.REDCAR);
}
}
);
addRight.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
display.addCar(Car.BLUECAR);
}
}
);
JPanel p1 = new JPanel();
p1.setLayout(new FlowLayout());
p1.add(addLeft);
p1.add(addRight);
c.add("South",p1);
setDefaultCloseOperation(EXIT_ON_CLOSE);
}
}