1
1
/**
2
2
* Programmer: Sean Thames
3
3
* Date: 2013-06-30
4
- * Filename: temp .java
4
+ * Filename: JBasketball .java
5
5
* Assignment: Ch 14 Ex 7
6
6
*
7
7
* Description: Write an application that allows a user to select a
8
8
* favorite basketball team from a list box. Include at least five teams in the
9
9
* list, and display the chosen team in a text field after the user makes a
10
10
* selection. Save the file as JBasketball.java
11
- */
11
+ */
12
+
13
+ import javax .swing .*;
14
+ import java .awt .*;
15
+ import java .awt .event .*;
16
+
17
+ public class JBasketball extends JFrame implements ActionListener
18
+ {
19
+ final int WIDTH = 250 ;
20
+ final int HEIGHT = 100 ;
21
+
22
+ String [] teams = {"Bulls" , "Celtics" , "Heat" , "Lakers" , "Spurs" };
23
+
24
+ JLabel title = new JLabel ("Please choose a team:" );
25
+ JComboBox <String > teamBox = new JComboBox <String >(teams );
26
+ JLabel choiceTitle = new JLabel ("You chose: " );
27
+ JTextField choice = new JTextField (8 );
28
+
29
+ public JBasketball ()
30
+ {
31
+ super ("Team Chooser" );
32
+ setDefaultCloseOperation (JFrame .EXIT_ON_CLOSE );
33
+ setSize (WIDTH , 75 );
34
+ setResizable (false );
35
+ setLocationRelativeTo (null );
36
+ setLayout (new FlowLayout ());
37
+
38
+ add (title );
39
+ add (teamBox );
40
+ add (choiceTitle );
41
+ add (choice );
42
+
43
+ teamBox .addActionListener (this );
44
+
45
+ choiceTitle .setVisible (false );
46
+ choice .setVisible (false );
47
+ choice .setEditable (false );
48
+
49
+ setVisible (true );
50
+ }
51
+
52
+ public void actionPerformed (ActionEvent event )
53
+ {
54
+ setSize (WIDTH , HEIGHT );
55
+ choiceTitle .setVisible (true );
56
+ choice .setVisible (true );
57
+ choice .setText (teamBox .getSelectedItem ().toString ());
58
+ }
59
+
60
+ public static void main (String [] args )
61
+ {
62
+ new JBasketball ();
63
+ }
64
+ }
0 commit comments