-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathChooseJob.java
77 lines (62 loc) · 2.58 KB
/
ChooseJob.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class ChooseJob extends JFrame {
public static void main( String[] args ) {
new ChooseJob();
}
public ChooseJob() {
super("ChooseJob");
Novice novice = new Novice("Enter Name");
Container c = getContentPane();
JPanel panel0 = new JPanel();
JPanel panel1 = new JPanel();
JPanel panel2 = new JPanel();
c.setLayout(new BoxLayout(c, BoxLayout.X_AXIS));
panel0.setLayout(new BoxLayout(panel0, BoxLayout.Y_AXIS));
panel1.setLayout(new BoxLayout(panel1, BoxLayout.Y_AXIS));
panel2.setLayout(new BoxLayout(panel2, BoxLayout.Y_AXIS));
JRadioButton swordman,merchant;
JLabel swordmanPicture = new JLabel(new ImageIcon("Swordman.png"));
JLabel merchantPicture = new JLabel(new ImageIcon("Merchant.png"));
JLabel novicetPicture = new JLabel(new ImageIcon("novice.png"));
JLabel welcome = new JLabel(" Welcome");
JLabel choose = new JLabel(" [Novice]");
swordman = new JRadioButton( "[Swordman]");
panel1.add(swordman);
merchant = new JRadioButton( "[Merchant]");
panel0.add(merchant);
swordman.setSelected(true);
ButtonGroup radioGroup = new ButtonGroup();
radioGroup.add( swordman );
radioGroup.add( merchant );
swordman.setActionCommand("swordman");
merchant.setActionCommand("merchant");
JButton okButton = new JButton("Choose Job");
panel0.add(merchantPicture);
panel1.add(swordmanPicture);
panel2.add(welcome);
panel2.add(choose);
panel2.add(novicetPicture);
panel2.add(okButton);
c.add(panel0);
c.add(panel1);
c.add(panel2);
okButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e){
if (radioGroup.getSelection().getActionCommand().equals("swordman")){
MyGame game = new MyGame(new Swordman(novice));
dispose();
}
else if (radioGroup.getSelection().getActionCommand().equals("merchant")){
MyGame game = new MyGame(new Merchant(novice));
dispose();
}
}
});
setSize(370, 260);
setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
setLocationRelativeTo(null);
setVisible(true);
}
}