Skip to content

Commit 1fdac6f

Browse files
author
Sean Thames
committed
Finished exercise 7. Added setResizable(false) to existing work to fix an issue with FlowLayout
1 parent fbe9a51 commit 1fdac6f

File tree

4 files changed

+60
-5
lines changed

4 files changed

+60
-5
lines changed

m7/ex4/JMyNewHome.java

+1
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ public JMyNewHome()
6363
super("My New Home");
6464
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
6565
setSize(WIDTH, HEIGHT);
66+
setResizable(false);
6667
setLayout(new FlowLayout());
6768

6869
for(int i = 0; i < separator.length; i++)

m7/ex5/JVideo.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,9 @@ private movie(double f)
4545
public JVideo()
4646
{
4747
super("Video Rental System");
48-
setSize(WIDTH, HEIGHT);
49-
setLayout(new FlowLayout());
5048
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
49+
setSize(WIDTH, HEIGHT);
50+
setResizable(false);
5151
setLocationRelativeTo(null);
5252

5353
add(top);

m7/ex5/JVideo2.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,10 @@ private movie(double f)
4646
public JVideo2()
4747
{
4848
super("Video Rental System");
49+
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
4950
setSize(WIDTH, HEIGHT);
51+
setResizable(false);
5052
setLayout(new FlowLayout());
51-
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
5253
setLocationRelativeTo(null);
5354

5455
add(top);

m7/ex7/JBasketball.java

+55-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,64 @@
11
/**
22
* Programmer: Sean Thames
33
* Date: 2013-06-30
4-
* Filename: temp.java
4+
* Filename: JBasketball.java
55
* Assignment: Ch 14 Ex 7
66
*
77
* Description: Write an application that allows a user to select a
88
* favorite basketball team from a list box. Include at least five teams in the
99
* list, and display the chosen team in a text field after the user makes a
1010
* 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

Comments
 (0)