- 7 · JavaSummer/JavaMainRepo@891c1a2 · GitHub
Skip to content

Commit 891c1a2

Browse files
committed
- 7
1 parent 0cf9d25 commit 891c1a2

171 files changed

Lines changed: 6639 additions & 107 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 83 additions & 2 deletions
Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
package javasmmr.zoowsome.views;
2+
3+
import java.awt.GridBagConstraints;
4+
import java.awt.GridBagLayout;
5+
import java.awt.event.ActionEvent;
6+
import java.awt.event.ActionListener;
7+
import java.awt.event.KeyEvent;
8+
9+
import javax.swing.ButtonGroup;
10+
import javax.swing.ImageIcon;
11+
import javax.swing.JLabel;
12+
import javax.swing.JRadioButton;
13+
14+
import javasmmr.zoowsome.views.ZooFrame;
15+
16+
public class AnimalFrame extends ZooFrame {
17+
18+
/**
19+
*
20+
*/
21+
private static final long serialVersionUID = 1L;
22+
23+
private JLabel labelImage = new JLabel();
24+
25+
private JRadioButton btnAquatic = new JRadioButton("Aquatic");
26+
private JRadioButton btnBird = new JRadioButton("Bird");
27+
private JRadioButton btnInsect = new JRadioButton("Insect");
28+
private JRadioButton btnMammal = new JRadioButton("Mammal");
29+
private JRadioButton btnReptile = new JRadioButton("Reptile");
30+
31+
private ImageIcon iconAquatic = new ImageIcon(getClass().getResource("/javasmmr/zoowsome/views/fish.png"));
32+
private ImageIcon iconBird = new ImageIcon(getClass().getResource("/javasmmr/zoowsome/views/bird.gif"));
33+
private ImageIcon iconInsect = new ImageIcon(getClass().getResource("/javasmmr/zoowsome/views/fly.png"));
34+
private ImageIcon iconMammal = new ImageIcon(getClass().getResource("/javasmmr/zoowsome/views/dog.gif"));
35+
private ImageIcon iconReptile = new ImageIcon(getClass().getResource("/javasmmr/zoowsome/views/trex2.png"));
36+
37+
private JLabel item1;
38+
39+
AquaticFrame alexaa = new AquaticFrame();
40+
41+
public AnimalFrame() {
42+
43+
super("Choose your type of animal");
44+
item1 = new JLabel("Choose a type of animal:", JLabel.LEADING);
45+
add(item1);
46+
47+
ButtonGroup buttonGroup = new ButtonGroup();
48+
buttonGroup.add(btnAquatic);
49+
buttonGroup.add(btnBird);
50+
buttonGroup.add(btnInsect);
51+
buttonGroup.add(btnMammal);
52+
buttonGroup.add(btnReptile);
53+
54+
// first option will appear as marked/"chosen"
55+
btnAquatic.setMnemonic(KeyEvent.VK_N);
56+
btnAquatic.setActionCommand("aquatic");
57+
labelImage.setIcon(iconAquatic);
58+
btnAquatic.setSelected(true);
59+
60+
add(btnAquatic);
61+
add(btnBird);
62+
add(btnInsect);
63+
add(btnMammal);
64+
add(btnReptile);
65+
66+
setLayout(new GridBagLayout());
67+
GridBagConstraints constraints = new GridBagConstraints();
68+
69+
constraints.gridx = 0;
70+
constraints.gridy = 1;
71+
constraints.gridwidth = 3;
72+
73+
add(labelImage, constraints);
74+
75+
RadioButtonActionListener actionListener = new RadioButtonActionListener();
76+
btnAquatic.addActionListener(actionListener);
77+
btnBird.addActionListener(actionListener);
78+
btnInsect.addActionListener(actionListener);
79+
btnMammal.addActionListener(actionListener);
80+
btnReptile.addActionListener(actionListener);
81+
82+
pack();
83+
//setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
84+
setLocationRelativeTo(null);
85+
86+
}
87+
88+
class RadioButtonActionListener implements ActionListener {
89+
90+
@Override
91+
public void actionPerformed(ActionEvent e) {
92+
JRadioButton button = (JRadioButton) e.getSource();
93+
94+
if (button == btnAquatic) {
95+
96+
/*labelImage.setIcon(iconAquatic);
97+
alexaa.setSize(600, 300);
98+
alexaa.setLocation(40, 200);
99+
alexaa.setVisible(true);*/
100+
101+
} else if (button == btnBird) {
102+
103+
labelImage.setIcon(iconBird);
104+
105+
} else if (button == btnInsect) {
106+
107+
labelImage.setIcon(iconInsect);
108+
109+
} else if (button == btnMammal) {
110+
111+
labelImage.setIcon(iconMammal);
112+
113+
} else if (button == btnReptile) {
114+
115+
labelImage.setIcon(iconReptile);
116+
117+
}
118+
119+
}
120+
121+
}
122+
}
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
package javasmmr.zoowsome.views;
2+
3+
import java.awt.FlowLayout;
4+
import java.awt.event.ActionEvent;
5+
import java.awt.event.ActionListener;
6+
7+
import javax.swing.ButtonGroup;
8+
import javax.swing.JFrame;
9+
import javax.swing.JRadioButton;
10+
11+
public class AquaticFrame extends JFrame {
12+
13+
/**
14+
*
15+
*/
16+
private static final long serialVersionUID = 1L;
17+
18+
private JRadioButton SeaTurtleButton = new JRadioButton("Sea Turtle");
19+
private JRadioButton SeaHorseButton = new JRadioButton("Sea Horse");
20+
private JRadioButton MoonJellyButton = new JRadioButton("MoonJellyfish");
21+
22+
AquaticFrameAttributes alexaa = new AquaticFrameAttributes();
23+
24+
public AquaticFrame() {
25+
26+
super("Choose your animal:");
27+
setLayout(new FlowLayout());
28+
29+
ButtonGroup buttonGroup = new ButtonGroup();
30+
buttonGroup.add(SeaTurtleButton);
31+
buttonGroup.add(SeaHorseButton);
32+
buttonGroup.add(MoonJellyButton);
33+
34+
add(SeaTurtleButton);
35+
add(SeaHorseButton);
36+
add(MoonJellyButton);
37+
38+
RadioButtonActionListener actionListener = new RadioButtonActionListener();
39+
SeaTurtleButton.addActionListener(actionListener);
40+
SeaHorseButton.addActionListener(actionListener);
41+
MoonJellyButton.addActionListener(actionListener);
42+
43+
}
44+
45+
class RadioButtonActionListener implements ActionListener {
46+
47+
@Override
48+
public void actionPerformed(ActionEvent event) {
49+
JRadioButton button = (JRadioButton) event.getSource();
50+
51+
if (button == SeaTurtleButton) {
52+
53+
alexaa.setSize(600, 300);
54+
alexaa.setLocation(450, 200);
55+
alexaa.setVisible(true);
56+
57+
} else if (button == SeaHorseButton) {
58+
59+
alexaa.setSize(600, 300);
60+
alexaa.setLocation(450, 200);
61+
alexaa.setVisible(true);
62+
63+
} else if (button == MoonJellyButton) {
64+
65+
alexaa.setSize(600, 300);
66+
alexaa.setLocation(450, 200);
67+
alexaa.setVisible(true);
68+
69+
}
70+
71+
}
72+
}
73+
74+
}
Lines changed: 56 additions & 0 deletions

0 commit comments

Comments
 (0)