Biblioteca Java - Blame information for rev 27
Subversion Repositories:
Rev | Author | Line No. | Line |
---|---|---|---|
27 | mihai | 1 | package ex3_roadtraffic; |
2 | import java.awt.*; | ||
3 | import java.awt.event.*; | ||
4 | import javax.swing.*; | ||
5 | import java.util.*; | ||
6 | |||
7 | public class CarWindow extends JFrame { | ||
8 | |||
9 | CarWorld display; | ||
10 | JButton addLeft; | ||
11 | JButton addRight; | ||
12 | |||
13 | public CarWindow() { | ||
14 | |||
15 | Container c = getContentPane(); | ||
16 | |||
17 | c.setLayout(new BorderLayout()); | ||
18 | display = new CarWorld(); | ||
19 | |||
20 | |||
21 | c.add("Center",display); | ||
22 | addLeft = new JButton("Add Left"); | ||
23 | addRight = new JButton("Add Right"); | ||
24 | |||
25 | addLeft.addActionListener(new ActionListener() { | ||
26 | public void actionPerformed(ActionEvent e) { | ||
27 | display.addCar(Car.REDCAR); | ||
28 | } | ||
29 | } | ||
30 | ); | ||
31 | |||
32 | addRight.addActionListener(new ActionListener() { | ||
33 | public void actionPerformed(ActionEvent e) { | ||
34 | display.addCar(Car.BLUECAR); | ||
35 | } | ||
36 | } | ||
37 | ); | ||
38 | |||
39 | |||
40 | JPanel p1 = new JPanel(); | ||
41 | p1.setLayout(new FlowLayout()); | ||
42 | p1.add(addLeft); | ||
43 | p1.add(addRight); | ||
44 | c.add("South",p1); | ||
45 | setDefaultCloseOperation(EXIT_ON_CLOSE); | ||
46 | } | ||
47 | |||
48 | } |