-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLetter.java
More file actions
566 lines (485 loc) · 13.8 KB
/
Letter.java
File metadata and controls
566 lines (485 loc) · 13.8 KB
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
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
package start;
import javax.swing.border.*;
import java.awt.event.*;
import java.net.URL;
import java.awt.*;
import sun.audio.*;
import java.io.*;
import java.awt.event.*;
import java.util.*;
import javax.swing.*;
@SuppressWarnings("serial")
public class JLetter extends JFrame {
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable()
{
public void run()
{
new JLetter();
}
});
}
private JLetter()
{
super("L.E.T.T.E.R.");
launch();
}
//-----------------------------------------------TO PLACE IN MENU BAR
private JMenu createFileJMenu()
{
JMenu f = new JMenu("File");
f.setMnemonic(KeyEvent.VK_C);
f.add(createQuitAction());
return f;
}
private JMenu createExtraJMenu()
{
JMenu h = new JMenu("Extra");
h.add(createAboutAction());
h.add(createHelpAction());
return h;
}
//-----------------------------------------------TO PLACE IN MENU BAR
//-----------------------------------------------FOR EACH ELEMENT IN MENU BAR
private Action createQuitAction()
{
if(quitAction == null)
{
quitAction = new AbstractAction("Quit")
{
public void actionPerformed(ActionEvent e)
{
performQuitAction();
}
{
putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_Q, KeyEvent.CTRL_MASK));
putValue(MNEMONIC_KEY, KeyEvent.VK_Q);
}
};
}
return quitAction;
}
private Action createAboutAction()
{
if(aboutAction == null)
{
aboutAction = new AbstractAction("About")
{
public void actionPerformed(ActionEvent e)
{
performAboutAction();
}
{
putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_A, KeyEvent.CTRL_MASK));
putValue(MNEMONIC_KEY, KeyEvent.VK_A);
}
};
}
return aboutAction;
}
private Action createHelpAction()
{
if(helpAction == null)
{
helpAction = new AbstractAction("Help")
{
public void actionPerformed(ActionEvent e)
{
performHelpAction();
}
{
putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_H, KeyEvent.CTRL_MASK));
putValue(MNEMONIC_KEY, KeyEvent.VK_H);
}
};
}
return helpAction;
}
//-----------------------------------------------FOR EACH ELEMENT IN MENU BAR
private JMenuBar createJMenuBar() //MENU TOOLBAR {FILE SONGS HELP}
{
JMenuBar mb = new JMenuBar();
mb.add(createFileJMenu());
mb.add(createExtraJMenu());
return mb;
}
//-----------------------------------------------BUTTONS
private JButton createReadJButton() //READ A LETTER
{
JButton b = new JButton("Read a letter?");
b.setFont(new Font(b.getFont().getName(), Font.PLAIN, b.getFont().getSize()));
b.addActionListener(new ActionListener() //Links the button to what it's supposed to do
{
public void actionPerformed(ActionEvent e)
{
performReadAction();
}
});
return b;
}
private JButton createListenJButton() //LISTEN TO MUSIC
{
JButton b = new JButton("Listen to music?");
b.setFont(new Font(b.getFont().getName(), Font.PLAIN, b.getFont().getSize()));
b.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
performListenAction();
}
}
);
return b;
}
private JButton createSitJButton() //SIT IN SILENCE
{
JButton b = new JButton("Sit in silence?");
b.setFont(new Font(b.getFont().getName(), Font.PLAIN, b.getFont().getSize()));
b.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
performSitAction();
}
});
return b;
}
private JButton createPhotoJButton() //CALL MY CREATOR
{
JButton b = new JButton("Look at photos?");
b.setFont(new Font(b.getFont().getName(), Font.PLAIN, b.getFont().getSize()));
b.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
performPhotoAction();
}
});
return b;
}
private JButton createTalkJButton() //TALK TO ME
{
JButton b = new JButton("Talk to me?");
b.setFont(new Font(b.getFont().getName(), Font.PLAIN, b.getFont().getSize()));
b.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
performTalkAction();
}
});
return b;
}
private JButton createExitJButton() //EXIT
{
JButton b = new JButton("Exit?"); //Generates new button graphic
b.setFont(new Font(b.getFont().getName(), Font.PLAIN, b.getFont().getSize())); //Sets font variables for text displayed on button
b.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
performQuitAction();
}
});
return b;
}
//-----------------------------------------------BUTTONS
//-----------------------------------------------ACTIONS FOR BUTTONS
private void performReadAction()
{
JFrame frame = new JFrame("L.E.T.T.E.R");
frame.getContentPane().add(new ActualLetter());
frame.pack();
frame.setVisible(true);
}
private void performListenAction()
{
try
{
Runtime.getRuntime().exec("cmd /c start songs.html");
}
catch(IOException e){}
}
private void performSitAction()
{
JFrame frame = new JFrame("JOptionPane showMessageDialog example");
String message = "Ok. I'll be here if you need me";
JOptionPane.showMessageDialog(frame, message, "Take it easy", JOptionPane.PLAIN_MESSAGE);
}
private void performPhotoAction()
{
JFrame frame = new JFrame("Pictures");
frame.getContentPane().add(new Photoes());
frame.pack();
frame.setVisible(true);
}
private void performTalkAction()
{
JFrame frame = new JFrame("JOptionPane showMessageDialog example");
String message = "LOOK WHAT I CAN DO!!!";
JOptionPane.showMessageDialog(frame, message, "HEY!", JOptionPane.PLAIN_MESSAGE);
Robot robot;
try
{
Random generate = new Random();
robot=new Robot();
for (int i = 0; i < 600; i++)
{
int rand1 = 320 + generate.nextInt(640);
int rand2 = 180 + generate.nextInt(360);
robot.mouseMove(rand1,rand2);
Thread.sleep(25);
}
}
catch(InterruptedException ex)
{
Thread.currentThread().interrupt();
}
catch (AWTException ex)
{
System.err.println("Can't start Robot: " + ex);
System.exit(0);
}
//message = "What did you expect? I'm only " + age + " years old.";
message = "What did you expect? I'm only a few months old.";
JOptionPane.showMessageDialog(frame, message, "Sorry", JOptionPane.PLAIN_MESSAGE);
}
private void performQuitAction()
{
System.exit(0);
}
//DONE
private void performAboutAction()
{
JFrame frame = new JFrame("JOptionPane showMessageDialog example");
String message = "I AM L.E.T.T.E.R."
+ "\n"
+ "\n"
+ "-> Letter" + "\n"
+ "-> Emulating" + "\n"
+ "-> Through" + "\n"
+ "-> Terminal" + "\n"
+ "-> Extremely" + "\n"
+ "-> Radically"
+ "\n"
+ "\n"
+ "Build Start: March 28,2013" + "\n"
+ "Build End: August 8,2013" + "\n"
+ "Version 1.0" + "\n"
+ "AUTHOR: Dmytro Malaniouk" + "\n"
+ "SOURCE CODE AT:"+ "\n"
+ "web.njit.edu/~dm282" + "\n"
+ "This software is not licensed." + "\n";
JOptionPane.showMessageDialog(frame, message, "ABOUT", JOptionPane.PLAIN_MESSAGE);
}
//DONE
private void performHelpAction()
{
JFrame frame = new JFrame("JOptionPane showMessageDialog example");
String message = "The program is fairly self explanatory. "
+ "\n"
+"If you are in possession of this " + "\n"
+"program, then the following options are" + "\n"
+"catered to your specific category. " + "\n"
+"There are however extra features that " + "\n"
+"can be accessed. Play around. See what " + "\n"
+"happens." + "\n" + "-DM";
JOptionPane.showMessageDialog(frame, message, "HELP", JOptionPane.PLAIN_MESSAGE);
}
//-----------------------------------------------ACTIONS FOR BUTTONS
//-----------------------------------------------Creme de la creme ENGINE
private void launch()
{
int height = Toolkit.getDefaultToolkit().getScreenSize().height; //GET HEIGHT OF SCREEN
int width = Toolkit.getDefaultToolkit().getScreenSize().width; //GET WIDTH OF SCREEN
setBounds(width / 2 - 300, height / 2 - 300, 500, 400); //SETS WIDTH AND HEIGHT OF PROGRAM
//Last two value set x and y
setDefaultCloseOperation(EXIT_ON_CLOSE); //SETS DEFAULT CLOSE OPERATION
setJMenuBar(createJMenuBar()); //CREATES THE {FILE, SONGS, HELP} BAR
setResizable(true); //LETS USER RESIZE WINDOWS
//-----------------------------------------------PANELS
//MAIN PANEL -> MainPanel
JPanel MainPanel = new JPanel();
MainPanel.setBackground(Color.white);
MainPanel.setLayout(new GridLayout(2,0,10,10));
//IMAGE PANEL -> t
JPanel t = new JPanel();
t.setBackground(Color.white);
t.setLayout(new GridLayout(0, 1, 5, 5));
ImageIcon icon = new ImageIcon("pic/image.jpg", "Image");
JLabel label = new JLabel(icon);
t.add(label, BorderLayout.SOUTH);
//BUTTON PANEL -> Button
JPanel Button = new JPanel();
Button.setLayout(new GridLayout(0, 3, 10, 10));
//#A-How many rows? #B-How many columns? #C-Horizontal gap #D-Vertival gap
//BUTTONS
{
Button.add(createReadJButton());
Button.add(createListenJButton());
Button.add(createSitJButton());
Button.add(createPhotoJButton());
Button.add(createTalkJButton());
Button.add(createExitJButton());
}
MainPanel.add(t, BorderLayout.NORTH);
MainPanel.add(Button,BorderLayout.CENTER);
add(MainPanel, BorderLayout.CENTER);
//-----------------------------------------------PANELS
setVisible(true);
}
//-----------------------------------------------Creme de la creme ENGINE
//-----------------------------------------------ADDITIONAL GLOBAL VARIABLES
private Action quitAction;
private Action aboutAction;
private Action helpAction;
//-----------------------------------------------ADDITIONAL GLOBAL VARIABLES
}
//CLASS FOR INITIATING SEPERATE LETTER WINDOW
class ActualLetter extends JPanel {
private JTextArea textArea;
public ActualLetter() {
BufferedReader br = null;
//construct components
textArea = new JTextArea (5,20);
textArea.setEditable(false);
JScrollPane scrollPane = new JScrollPane(textArea,
JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
scrollPane.setPreferredSize(new Dimension(650,600));
try
{
FileReader reader = new FileReader("letter.txt");
br = new BufferedReader(reader);
String str;
while((str = br.readLine()) != null)
{
textArea.append(str + "\n");
}
textArea.setCaretPosition(0);
}
catch (IOException e)
{}
finally
{
try
{
br.close();
}
catch(Exception ex)
{}
}
setPreferredSize (new Dimension (650, 600));
add (scrollPane, BorderLayout.CENTER);
}
}
//CLASS FOR VIEWING PHOTOS
class Photoes extends JFrame {
static int x = 0;
JButton bNext = new JButton();
JButton bPrevious = new JButton();
TitledBorder titledBorder1 = new TitledBorder("");
JLabel lblPhoto = new JLabel();
TitledBorder titledBorder2 = new TitledBorder("");
public Photoes()
{
try
{
jbInit();
}
catch (Exception e)
{}
}
private void jbInit() throws Exception {
getContentPane().setLayout(null);
this.setResizable(true);
this.setTitle("Photo Viewer");
this.setBounds(50,10,810,840);
this.setVisible(true);
this.addWindowListener(new Photoes_this_windowAdapter(this));
lblPhoto.setFont(new java.awt.Font("Arial", Font.BOLD, 30));
lblPhoto.setHorizontalAlignment(JLabel.CENTER);
lblPhoto.setBorder(titledBorder2);
lblPhoto.setBounds(new Rectangle(2, 0, 800, 600));
bNext.setBounds(new Rectangle(610, 736, 118, 30));
bNext.setToolTipText("Show next image");
bNext.setText("Next");
bNext.addMouseListener(new Photoes_bNext_mouseAdapter(this));
bNext.addActionListener(new Photoes_bNext_actionAdapter(this));
bNext.setMnemonic('N');
bPrevious.setBounds(new Rectangle(371, 736, 118, 30));
bPrevious.setToolTipText("Show Previous Photo");
bPrevious.setText("Previous");
bPrevious.addActionListener(new Photoes_bPrevious_actionAdapter(this));
bPrevious.setMnemonic('P');
this.getContentPane().add(lblPhoto);
this.getContentPane().add(bNext,BorderLayout.CENTER);
this.getContentPane().add(bPrevious,BorderLayout.CENTER);
this.viewPhotoes();
}
public void viewPhotoes()
{
String file = "output/" + Integer.toString(x) + ".png";
File f = new File(file);
if (!f.exists())
{
x = -1;
}
ImageIcon i = new ImageIcon(file);
//ImageIcon newi = i.getImageIcon().getScaledInstance(600, 800, Image.SCALE_DEFAULT);
lblPhoto.setIcon(i);
}
public void bPrevious_actionPerformed(ActionEvent e)
{
if(x>0)
{
x--;
this.viewPhotoes();
}
}
public void bNext_actionPerformed(ActionEvent e)
{
x++;
this.viewPhotoes();
}
}
class Photoes_this_windowAdapter extends WindowAdapter
{
private Photoes adaptee;
Photoes_this_windowAdapter(Photoes adaptee)
{
this.adaptee = adaptee;
}
}
class Photoes_bNext_mouseAdapter extends MouseAdapter
{
private Photoes adaptee;
Photoes_bNext_mouseAdapter(Photoes adaptee)
{
this.adaptee = adaptee;
}
}
class Photoes_bNext_actionAdapter implements ActionListener
{
private Photoes adaptee;
Photoes_bNext_actionAdapter(Photoes adaptee)
{
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e)
{
adaptee.bNext_actionPerformed(e);
}
}
class Photoes_bPrevious_actionAdapter implements ActionListener
{
private Photoes adaptee;
Photoes_bPrevious_actionAdapter(Photoes adaptee)
{
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e)
{
adaptee.bPrevious_actionPerformed(e);
}
}