-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathFight.java
192 lines (157 loc) · 6.06 KB
/
Fight.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
import java.util.*;
import greenfoot.core.WorldHandler;
import greenfoot.core.Simulation;
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import greenfoot.*;
/**
* Write a description of class Dialog here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Fight
{
private java.util.List<JComponent> components = new ArrayList<JComponent>();
/**
* Constructor for objects of class Dialog
*/
public Fight()
{
initComponents();
npc.setImage("./images/wizard.jpg");
pc.setImage("./images/knight.jpg");
/*
final JPanel panel = WorldHandler.getInstance().getWorldCanvas();
//panel.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
final JLabel lab1 = new JLabel("Label", JLabel.LEFT);
//panel.setLayout(new FlowLayout());
panel.add(lab1);
lab1.setVisible(true);
panel.updateUI();
components.add(lab1);
lab1.addMouseListener(new MouseListener()
{
public void mouseClicked(MouseEvent arg0) {
panel.remove(lab1);
panel.updateUI();
}
public void mouseEntered(MouseEvent arg0) {
}
public void mouseExited(MouseEvent arg0) {
}
public void mousePressed(MouseEvent arg0) {
}
public void mouseReleased(MouseEvent arg0) {
}
});
*/
}
// Variables declaration - do not modify
private javax.swing.JPanel answer;
private javax.swing.JLabel answer1;
private javax.swing.JLabel answer2;
private javax.swing.JLabel answer3;
private javax.swing.JPanel images;
private ImagePanel npc;
private javax.swing.JPanel panel;
private ImagePanel pc;
private javax.swing.JPanel question;
private javax.swing.JLabel questionLabel;
// End of variables declaration
private LayoutManager layoutManager;
private void initComponents() {
final JPanel canvas = WorldHandler.getInstance().getWorldCanvas();
layoutManager = canvas.getLayout();
canvas.setLayout(new javax.swing.BoxLayout(canvas, javax.swing.BoxLayout.LINE_AXIS));
panel = new javax.swing.JPanel();
images = new javax.swing.JPanel();
npc = new ImagePanel();
pc = new ImagePanel();
question = new javax.swing.JPanel();
questionLabel = new javax.swing.JLabel();
answer = new javax.swing.JPanel();
answer1 = new javax.swing.JLabel();
answer2 = new javax.swing.JLabel();
answer3 = new javax.swing.JLabel();
panel.setBorder(javax.swing.BorderFactory.createEmptyBorder(10, 10, 10, 10));
panel.setLayout(new java.awt.GridLayout(3, 1));
images.setLayout(new java.awt.GridLayout(1, 2));
javax.swing.GroupLayout npcLayout = new javax.swing.GroupLayout(npc);
npc.setLayout(npcLayout);
npcLayout.setHorizontalGroup(
npcLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 190, Short.MAX_VALUE)
);
npcLayout.setVerticalGroup(
npcLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 93, Short.MAX_VALUE)
);
images.add(npc);
javax.swing.GroupLayout pcLayout = new javax.swing.GroupLayout(pc);
pc.setLayout(pcLayout);
pcLayout.setHorizontalGroup(
pcLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 190, Short.MAX_VALUE)
);
pcLayout.setVerticalGroup(
pcLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 93, Short.MAX_VALUE)
);
images.add(pc);
panel.add(images);
question.setAutoscrolls(true);
question.setLayout(new javax.swing.BoxLayout(question, javax.swing.BoxLayout.LINE_AXIS));
questionLabel.setText("What's the capital of Turkey?");
question.add(questionLabel);
panel.add(question);
answer.setAutoscrolls(true);
answer.setLayout(new javax.swing.BoxLayout(answer, javax.swing.BoxLayout.PAGE_AXIS));
answer1.setText("Ankara");
answer1.setName("answer1");
answer1.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
answerMouseClicked(evt);
}
});
answer.add(answer1);
answer2.setText("Instanbul");
answer2.setName("answer2");
answer2.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
answerMouseClicked(evt);
}
});
answer.add(answer2);
answer3.setText("Izmir");
answer3.setName("answer3");
answer3.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
answerMouseClicked(evt);
}
});
answer.add(answer3);
panel.add(answer);
canvas.add(panel);
canvas.updateUI();
}
private void answerMouseClicked(java.awt.event.MouseEvent evt) {
// TODO add your handling code here:
System.out.println(evt.getComponent().getName() + " clicked!");
}
/*
private void exitActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
dispose();
Greenfoot.setWorld(world);
Simulation.getInstance().setEnabled(false);
}
*/
public void dispose() {
final JPanel canvas = WorldHandler.getInstance().getWorldCanvas();
canvas.remove(panel);
canvas.setLayout(layoutManager);
canvas.updateUI();
}
}