-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathICEPort copy.java
409 lines (345 loc) · 11.8 KB
/
ICEPort copy.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
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
import iceworld.given.ICEWorldImmigration;
import iceworld.given.MyIcetizen;
import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.JMenuBar;
import javax.swing.JMenu;
import javax.swing.JMenuItem;
import javax.swing.JSeparator;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.JTextField;
import java.awt.BorderLayout;
import javax.swing.JTextPane;
import javax.swing.JTextArea;
import java.awt.Panel;
import javax.swing.JEditorPane;
import javax.swing.JLabel;
import java.awt.Font;
import javax.swing.SwingConstants;
import java.awt.Dimension;
import javax.swing.JPanel;
import java.awt.GridBagLayout;
import java.awt.GridBagConstraints;
import java.awt.Insets;
import javax.swing.JButton;
import java.awt.Color;
import javax.swing.ImageIcon;
import javax.swing.BoxLayout;
//import com.jgoodies.forms.layout.FormLayout;
//import com.jgoodies.forms.layout.ColumnSpec;
//import com.jgoodies.forms.layout.RowSpec;
//import com.jgoodies.forms.factories.FormFactory;
import javax.swing.JLayeredPane;
import java.awt.Component;
import java.awt.SystemColor;
import java.net.MalformedURLException;
import java.net.URL;
import java.awt.event.ActionListener;
import java.awt.image.BufferedImage;
import javax.imageio.ImageIO;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.image.BufferedImage;
import java.io.*;
import java.net.*;
import javax.swing.JPasswordField;
public class ICEPort {
private JFrame frmIceWorld;
private JTextField textField;
private JPasswordField passwordField;
private JTabbedPane tabbedPane;
private JPanel panel1;
private JPanel panel2;
private JPanel panel3;
public JTextField username;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
ICEPort window = new ICEPort();
window.frmIceWorld.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the application.
*
* @throws MalformedURLException
*/
public ICEPort() throws MalformedURLException {
initialize();
}
/**
* Initialize the contents of the frame.
*
* @throws MalformedURLException
*/
private void initialize() throws MalformedURLException {
frmIceWorld = new JFrame();
frmIceWorld.setTitle("ICE World");
frmIceWorld.setBounds(100, 100, 850, 500);
frmIceWorld.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
JMenuBar menuBar = new JMenuBar();
frmIceWorld.setJMenuBar(menuBar);
JMenu mnFile = new JMenu("File");
menuBar.add(mnFile);
JMenuItem mntmNewWindow = new JMenuItem("New window");
mntmNewWindow.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
ICEPort window = null;
try {
window = new ICEPort();
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
window.frmIceWorld.setVisible(true);
}
});
mnFile.add(mntmNewWindow);
JSeparator separator = new JSeparator();
mnFile.add(separator);
JMenuItem mntmExit = new JMenuItem("Exit");
mntmExit.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
System.exit(0);
}
});
mnFile.add(mntmExit);
JMenu mnAbout = new JMenu("About");
menuBar.add(mnAbout);
JMenuItem author = new JMenuItem("Author");
mnAbout.add(author);
author.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
JFrame pic = new JFrame();
BufferedImage myImage = null;
try {
myImage = ImageIO.read(new URL(
"http://dl.dropbox.com/u/107759697/about.jpg"));
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
// System.out.println("Cannot find image");
}
myImage = resize(myImage, 1000, 700);
ImageIcon imageIcon = new ImageIcon(myImage);
JPanel imagePanel = new JPanel(new GridLayout(1, 1, 10, 10));
JLabel author_image = new JLabel(imageIcon);
pic.setLayout(new BorderLayout());
imagePanel.add(author_image);
pic.add(imagePanel);
pic.setPreferredSize(new Dimension(1000, 700));
pic.pack();
pic.setVisible(true);
}
});
JMenuItem mntmHelp = new JMenuItem("Help");
mnAbout.add(mntmHelp);
mntmHelp.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
JFrame frame = new JFrame();
JDialog dialog = new JDialog(frame,"Dialog");
// NOTE: to reduce the amount of code in this example, it uses
// panels with a NULL layout. This is NOT suitable for
// production code since it may not display correctly for
// a look-and-feel.
//setTitle("Tabbed Pane Application");
//setSize(300, 200);
//setBackground(Color.gray);
JPanel panel = new JPanel();
dialog.setLayout(new BorderLayout());
//frame.add(frame);
// Create the tab pages
createPage1();
createPage2();
createPage3();
// Create a tabbed pane
tabbedPane = new JTabbedPane();
tabbedPane.addTab("Page 1", panel1);
tabbedPane.addTab("Page 2", panel2);
tabbedPane.addTab("Page 3", panel3);
panel.add(tabbedPane, BorderLayout.CENTER);
dialog.setModal(true);
dialog.add(panel,BorderLayout.CENTER);
dialog.setPreferredSize(new Dimension(1000,600));
dialog.pack();
dialog.pack();
}
});
frmIceWorld.getContentPane().setLayout(null);
JLabel lblIceWorld = new JLabel("ICE World");
lblIceWorld.setBounds(0, 0, 834, 56);
lblIceWorld.setForeground(new Color(0, 191, 255));
lblIceWorld.setBackground(Color.RED);
lblIceWorld.setHorizontalAlignment(SwingConstants.CENTER);
lblIceWorld.setFont(new Font("Cooper Black", Font.BOLD, 48));
frmIceWorld.getContentPane().add(lblIceWorld);
JLabel lblItsATrap = new JLabel("Live in your world, play in ours");
lblItsATrap.setForeground(new Color(147, 112, 219));
lblItsATrap.setFont(new Font("Copperplate Gothic Bold", Font.BOLD, 13));
lblItsATrap.setHorizontalAlignment(SwingConstants.CENTER);
lblItsATrap.setBounds(0, 53, 834, 24);
frmIceWorld.getContentPane().add(lblItsATrap);
JPanel panel = new JPanel();
panel.setBounds(263, 127, 306, 173);
frmIceWorld.getContentPane().add(panel);
panel.setLayout(null);
JLabel lblUsername = new JLabel("Username");
lblUsername.setBounds(22, 34, 66, 14);
panel.add(lblUsername);
textField = new JTextField();
textField.setBounds(98, 31, 164, 20);
panel.add(textField);
textField.setColumns(10);
String username = textField.getText();
JLabel lblPassword = new JLabel("Password");
lblPassword.setBounds(22, 60, 66, 14);
panel.add(lblPassword);
String password;
JButton btnLogin = new JButton("Login");
btnLogin.addActionListener(new Action() );
btnLogin.setBounds(108, 98, 94, 23);
panel.add(btnLogin);
//btnLogin.addActionListener(new Action() );
/*public void actionPerformed(ActionEvent e) {
/*
* MyIcetizen icetizen = new MyIcetizen() ICEWorldImmigration
* immigration = new ICEWorldImmigration(new
* MyIcetizen(username)); if (immigration.login(<<(String) the
* password of the Icetizen>>)) System.out.println("Login OK");
}
}); */
JButton btnLoginAsAlien = new JButton("Login as Alien");
btnLoginAsAlien.addActionListener(new Action() );
btnLoginAsAlien.setBounds(98, 127, 114, 23);
panel.add(btnLoginAsAlien);
passwordField = new JPasswordField();
passwordField.setBounds(98, 57, 164, 20);
panel.add(passwordField);
JLayeredPane layeredPane = new JLayeredPane();
layeredPane.setBounds(0, 433, 834, -428);
frmIceWorld.getContentPane().add(layeredPane);
JPanel panel_1 = new JPanel();
panel_1.setBackground(Color.BLACK);
panel_1.setBounds(0, 0, 834, 441);
frmIceWorld.getContentPane().add(panel_1);
panel_1.setLayout(null);
JLabel lblNewLabel = new JLabel("");
lblNewLabel
.setIcon(new ImageIcon(
new URL(
"https://github.com/nichada/Project/blob/master/ice1.png?raw=true")));
lblNewLabel.setBounds(40, 102, 180, 238);
panel_1.add(lblNewLabel);
JLabel lblNewLabel_1 = new JLabel("");
lblNewLabel_1
.setIcon(new ImageIcon(
new URL(
"https://github.com/nichada/Project/blob/master/ice2.png?raw=true")));
lblNewLabel_1.setBounds(614, 102, 174, 238);
panel_1.add(lblNewLabel_1);
}
class Action implements ActionListener{
@Override
public void actionPerformed(ActionEvent arg0) {
// TODO Auto-generated method stub
String username = textField.getText();
String pass= new String(passwordField.getPassword());
//String = passwordField.getPassword();
//for(int i = 0;i<a.length;i++){
// pass = pass+a[i];
//}
System.out.print(pass);
Icetizen tester = new Icetizen();
tester.setListeningPort(256);
ICEWorldImmigration immigration = new ICEWorldImmigration(tester);
JButton b = (JButton) arg0.getSource();
String name = b.getText();
if(name.equals("Login")){
tester.setUsername(username);
if(immigration.login(pass)){
//log in laew tum arai
System.out.println("login to iceworld");
System.out.println(immigration.walk(10,10));
}
else{
//password or username pid
System.out.println("wrong password");
}
}else{
if(immigration.loginAlien()){
//log in as alien
System.out.println("login to iceworld as alien");
}else{
// log in mai dai
System.out.println("cant login");
}
}
}
}
public static BufferedImage resize(BufferedImage image, int width,
int height) {
int type = image.getType() == 0 ? BufferedImage.TYPE_INT_ARGB : image
.getType();
BufferedImage resizedImage = new BufferedImage(width, height, type);
Graphics2D g = resizedImage.createGraphics();
g.setComposite(AlphaComposite.Src);
g.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
RenderingHints.VALUE_INTERPOLATION_BILINEAR);
g.setRenderingHint(RenderingHints.KEY_RENDERING,
RenderingHints.VALUE_RENDER_QUALITY);
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
g.drawImage(image, 0, 0, width, height, null);
g.dispose();
return resizedImage;
}
public void createPage1() {
panel1 = new JPanel();
panel1.setLayout(null);
JLabel label1 = new JLabel("Username:");
label1.setBounds(10, 15, 150, 20);
panel1.add(label1);
JTextField field = new JTextField();
field.setBounds(10, 35, 150, 20);
panel1.add(field);
JLabel label2 = new JLabel("Password:");
label2.setBounds(10, 60, 150, 20);
panel1.add(label2);
JPasswordField fieldPass = new JPasswordField();
fieldPass.setBounds(10, 80, 150, 20);
panel1.add(fieldPass);
}
public void createPage2() {
panel2 = new JPanel();
panel2.setLayout(new BorderLayout());
panel2.add(new JButton("North"), BorderLayout.NORTH);
panel2.add(new JButton("South"), BorderLayout.SOUTH);
panel2.add(new JButton("East"), BorderLayout.EAST);
panel2.add(new JButton("West"), BorderLayout.WEST);
panel2.add(new JButton("Center"), BorderLayout.CENTER);
}
public void createPage3() {
panel3 = new JPanel();
panel3.setLayout(new GridLayout(3, 2));
panel3.add(new JLabel("Field 1:"));
panel3.add(new TextArea());
panel3.add(new JLabel("Field 2:"));
panel3.add(new TextArea());
panel3.add(new JLabel("Field 3:"));
panel3.add(new TextArea());
}
// Main method to get things started
}