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
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
|
/*
Kopiec Kreta - gra w odgadywanie slow
ver. 0.4.0-beta
autor: Przemyslaw R. Pietraszczyk
data: 2020-09-30
licencja: GPL v3
slownik pochodzi z: sjp.pl
*/
package src;
import java.awt.*; // Toolkit
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JButton;
//import javax.swing.JComponent;
import javax.swing.JMenuBar;
import javax.swing.JMenu;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.Box;
import javax.swing.JTextArea;
import javax.swing.JDialog;
import javax.swing.JTextField;
import javax.swing.JCheckBox;
import javax.swing.BorderFactory;
import javax.swing.WindowConstants;
import java.awt.event.*;
import java.awt.event.ActionListener;
//import java.awt.event.KeyListener;
import java.awt.event.ActionEvent;
import java.awt.event.WindowEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.ComponentAdapter;
import java.awt.event.ComponentEvent;
import java.awt.event.ItemEvent;
//import java.awt.event.KeyEvent;
import java.util.*; //Timer
//import java.awt.Robot;
import java.awt.Toolkit;
import java.beans.*; //property change stuff
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.InputStreamReader;
import java.io.IOException;
public class KopiecKreta extends JTextArea implements ActionListener {
static JMenuBar menuBar;
static JMenu menu, info, menu2;
static JMenuItem menuItem, menuExit, menuInfo, menuPref;
static JFrame frame;
static boolean go=false;
static Timer timer = new Timer();
static String content;
final static int NRINGS=11;
final static int NCHAR=23; //32;
static MyResource res = new MyResource();
static wavResource wav;
static Ring []truering = new Ring[NRINGS];
static Ring []falsering = new Ring[NRINGS];
static String [] mound = new String[20]; // tekst do wyswietlenia przez paint
static JTextArea textArea;
static JPanel startScreen;
static int activeRing; // indeks ringu na ktorym jest prowadzona aktualnie gra
static KopiecKreta kk;
static Actions actions;
final static String CONSTCH="1234";
final static Character[] charsInStock= {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'r', 's', 't', 'u', 'w', 'y', 'z'};
static ArrayList<String> cheatSheet;
static int pointsForTheRing;
static int pointsFOrTheMund;
static int totalScore, level;
static boolean cheatActivate=false;
static SoundDialog sounddialog;
//static ResetDialog resetdialog;
//static GetNameDialog getNameDialog;
//Boolean runSoundDialog=Boolean.valueOf(false);
static ConfigFile configfile;
//static char pressKey=' ';
public KopiecKreta() {
//GridBagLayout gridbag = (GridBagLayout)getLayout();
//GridBagConstraints c = new GridBagConstraints();
menuBar = new JMenuBar();
menu = new JMenu("Plik");
menuBar.add(menu);
menu2 = new JMenu("Opcje");
menuBar.add(menu2);
// przenosi INFO na prawa strone
menuBar.add(Box.createHorizontalGlue());
info = new JMenu("Info");
// kierunek wyswietlania menu
info.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
menuBar.add(info);
menuItem = new JMenuItem("Nowa Gra", null);
menuItem.setActionCommand("MenuItem1");
menuItem.addActionListener(this);
menuItem.setToolTipText("Rozpoczyna nowa gre.");
menu.add(menuItem);
//menuItem = new JMenuItem("Sala slawy", null);
//menuItem.setActionCommand("MenuItem11");
//menuItem.addActionListener(this);
//menuItem.setToolTipText("Wyswietla najlepsze wyniki");
//menu.add(menuItem);
menu.addSeparator();
menuExit = new JMenuItem("Zakoncz", null);
menuExit.setActionCommand("MenuItem2");
menuExit.addActionListener(this);
menuExit.setToolTipText("Wyjscie z programu");
menu.add(menuExit);
menuPref = new JMenuItem("Preferencje dzwieku",null);
menuPref.setActionCommand("MenuItem4");
menuPref.addActionListener(this);
menuPref.setToolTipText("Preferencje dotyczace dzwieku");
menu2.add(menuPref);
/*
menuPref = new JMenuItem("Resetowanie",null);
menuPref.setActionCommand("MenuItem5");
menuPref.addActionListener(this);
menuPref.setToolTipText("Resetowanie najlepszych wynikow");
menu2.add(menuPref);
*/
menuInfo = new JMenuItem("Pomoc", null);
menuInfo.setActionCommand("MenuItem33");
menuInfo.addActionListener(this);
menuInfo.setToolTipText("Samouczek");
info.add(menuInfo);
menuInfo = new JMenuItem("O Programie", null);
menuInfo.setActionCommand("MenuItem3");
menuInfo.addActionListener(this);
menuInfo.setToolTipText("Informacje o programie");
info.add(menuInfo);
//addKeyListener(this);
//actions = new Actions();
//addKeyListener(actions);
//setFocusable(true);
}
public void actionPerformed(final ActionEvent e) {
// Nowa gra
if(e.getActionCommand().equals("MenuItem1")) {
//getNameDialog.initUI(configfile, frame, getNameDialog.runGetNameDialog);
//getNameDialog.runGetNameDialog=true;
//if (getNameDialog.go){
activeRing=10;
totalScore=0;
pointsForTheRing=0;
pointsFOrTheMund=0;
level=1;
//frame.remove(startScreen);
//frame.add(textArea);
startScreen.setVisible(false);
textArea.setVisible(true);
create_secret_mound();
create_real_mound(); // generuje prawdziwy kopiec
cheatSheet = new ArrayList<String>();
setCharCheatSheet ();
go=true;
setDisplayMound();
// }
}
// Zakonczenie
else if(e.getActionCommand().equals("MenuItem2")) {
System.exit(0);
}
// O Programie
else if(e.getActionCommand().equals("MenuItem3")) {
String s1=" Port mojej gry pierwotnie napisanej dla Androida 2.3\n\n",
s2=" Program napisany na podstawie fragmentow kodow,\n",
s3=" wyszukanych w wyszukiwarce Google,\n",
s4=" plus wlasna inwencja\n\n",
s5=" Autor zarzeka sie ze nigdy nie posiadal, ani nie posiada\n",
s6=" zadnej ksiazki na temat Javy.\n",
s7="Oraz nie przeczytal ani jednej ksiazki na temat tego jezyka!\n\n",
s8=" Przemyslaw R. Pietraszczyk - jesien 2020\n",
s9=" Licencja: GPL v3\n\n",
s10=" Stworzono w oparciu o OpenJDK 11 oraz ANT\n\n",
s11=" o/s: "+configfile.osName+" ver. "+configfile.osVersion+"\n",
s12=" java ver: "+configfile.jvmVersion;
JOptionPane.showMessageDialog(frame,
s1+s2+s3+s4+s5+s6+s7+s8+s9+s10+s11+s12,
"Kopiec Kreta 0.230924-0",
JOptionPane.PLAIN_MESSAGE);
}
else if(e.getActionCommand().equals("MenuItem33")) {
String s1="Celem gry jest odgadniecie wszyskich zakrytych pol.\n",
s2="Rozgrywke rozpoczyna sie od dolnego pierscienia.\n",
s3="Po odgadnieciu wszyskich liter w danym pierscieniu,\n",
s4="rozgrywka przenosi sie na kolejny, wyzszy ring.\n",
s5="Po odgadnieciu wszystkich liter, gracz pytany jest\n",
s6="o chec gry na opcjonalnym nastepnym poziomie.\n\n",
s7="UWAGA ! Caps Lock - bez znaczenia !\n",
s8="\n";
JOptionPane.showMessageDialog(frame,
s1+s2+s3+s4+s5+s6+s7+s8,
"Pomoc",
JOptionPane.PLAIN_MESSAGE);
}
else if(e.getActionCommand().equals("MenuItem4")) {
sounddialog.initUI(configfile, frame, sounddialog.runSoundDialog);
sounddialog.runSoundDialog=true;
}
/*
else if(e.getActionCommand().equals("MenuItem5")) {
resetdialog.initUI(configfile);
}
*/
// sala slawy
/*
else if(e.getActionCommand().equals("MenuItem11")) {
}
*/
//System.out.println("ACTION PERFORMED " + e);
}
private static void createAndShowGUI() {
frame=new JFrame("Kopiec Kreta");
//Robot robot;
// menuBar z konstruktora
final int frameWidth = 250;
final int frameHeight = 460;
final int GNOMEPANEL=80; // nieco nizej niz panel
final Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
//frame.setBounds((int) screenSize.getWidth() - frameWidth,
// (int) screenSize.getHeight() - frameHeight, frameWidth, frameHeight);
frame.setBounds((int) screenSize.getWidth() - frameWidth,
GNOMEPANEL, frameWidth, frameHeight);
frame.setResizable(false);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
sounddialog = new SoundDialog();
//resetdialog = new ResetDialog();
//getNameDialog = new GetNameDialog();
textArea = new KopiecKreta();
startScreen = new StartScreen();
//textArea.setFont(new Font("Serif", Font.ITALIC, 18));
textArea.setFont(new Font("Serif", Font.BOLD, 18));
textArea.setLineWrap(true); //nowe
textArea.setWrapStyleWord(true); // nowe
textArea.setEditable(false);
textArea.setBounds(5,5,240,430);
frame.add(textArea);
textArea.setVisible(false);
frame.add(menuBar);
frame.add(startScreen);
startScreen.setFont(new Font("Serif", Font.BOLD, 18));
startScreen.setBounds(5,5,240,430);
frame.setJMenuBar(menuBar);
frame.setLayout(null);
frame.setSize(250,500); // 400 x 400
frame.setVisible(true);
actions = new Actions();
frame.addKeyListener(actions);
frame.setFocusable(true);
textArea.setForeground(Color.BLACK);
textArea.setBackground(Color.GREEN);
// zapobiega utracie KeyEvent po wyjsciu z SoundDialog i ResetDialog
frame.addFocusListener(new FocusListener(){
public void focusGained(FocusEvent e){
//System.out.println("Focus GAINED:"+e);
}
public void focusLost(FocusEvent e){
//System.out.println("Focus LOST:"+e);
// FIX FOR GNOME/XWIN FOCUS BUG
e.getComponent().requestFocus();
}
});
try {
configfile = new ConfigFile();
}catch (IOException e){}
configfile.load();
/*
try {
// obiekt robot posiada metode do pobierania koloru pixela
robot = new Robot();
robot.mouseMove(screenSize.width-100, 200);
robot.mousePress(InputEvent.BUTTON1_DOWN_MASK);
robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);
}catch (AWTException e) {}
frame.setAlwaysOnTop(true);
*/
timer.schedule(new KeyTicks(), 0, 1000); // lepiej 1000
}
// dodaje punkty za pierscien i kazuje pozostale litery sciagi
static public void addScores(){
int n;
pointsForTheRing=0;
if (!cheatActivate){
for (int i=0;i< cheatSheet.size();i++){
pointsForTheRing++;
}
pointsFOrTheMund+=pointsForTheRing;
}
//System.out.println("Naliczylem "+pointsForTheRing+" punktow za ring");
}
// zapelnia tablice ze znakami do podpowiedzi
static private void setCharCheatSheet (){
for (int i=0; i<NCHAR; i++){
// przepisujemy kolejno znaki do listy stringow
char c= Character.toUpperCase(charsInStock[i]);
cheatSheet.add(String.valueOf(c));
}
}
static private void refreshCheatSheet(int n){
String t="";
cheatSheet.remove(n);
for (int i=0;i< cheatSheet.size();i++){
t+=cheatSheet.get(i);
}
}
// szuka znaku w tablicy z podpowiedzia
static private int searchCharChaetSheet(char c){
String s="";
String sc="";
//String test="";
for (int i=0;i< cheatSheet.size();i++){
s=cheatSheet.get(i);
sc = String.valueOf(c);
// test+=sc;
if (s.equals(sc)) {
return i;
}
}
//System.out.println("Nie odnalazlem znaku:"+sc);
return -1;
}
static private void create_real_mound(){
int n_char=3;
String r="";
for (int i=0; i<NRINGS; i++){
truering[i] = new Ring(res.getDirectory(n_char));
n_char++;
for (int j=0;j<truering[i].getLength();j++){
String _r=Character.toString(truering[i].getChar(j));
r+=_r;
}
r+="\n";
}
System.out.println(r);
}
public static void create_secret_mound(){
// kodujemy od 3 liter
String s="???";
for (int i=0; i<NRINGS; i++){
falsering[i] = new Ring(s);
s+="?";
}
}
public static void main(final String[] args) {
try {
res.read();
//wav = new wavResource();
//wav.loadWav();
//wav.initWav();
}catch (Exception e) {
e.printStackTrace();
}
javax.swing.SwingUtilities.invokeLater(new RunnableImplementation());
}
static private void setDisplayMound(){
String sr = new String();
String r="";
textArea.setText(null);
sr+="\n";
// i=1 poniewaz pomijamy 3 literowy ring
for (int i=1;i<NRINGS;i++){
//String r="";
for (int j=0;j<truering[i].getLength();j++){
String _r=Character.toString(truering[i].getChar(j));
r+=_r;
}
//System.out.println(r);
r="";
sr+=" ";
if (i==activeRing){
sr+=">";
}
else sr+=" ";
for (int j=0;j<falsering[i].getLength();j++){
String _s=Character.toString(falsering[i].getChar(j));
sr +=_s;
}
if (i==activeRing){
sr+="<";
}
mound[i]=sr;
//System.out.println("mound["+i+"] "+mound[i]);
textArea.append(mound[i]+"\n");
sr="";
}
textArea.append("\n\n");
for (int i=0; i<cheatSheet.size();i++){
textArea.append(cheatSheet.get(i));
textArea.append(" ");
}
}
private static final class RunnableImplementation implements Runnable {
public void run(){
wav = new wavResource();
createAndShowGUI();
}
}
public static void unhideWords(){
for (int j=0;j<truering[activeRing].getLength();j++){
falsering[activeRing].setChar(truering[activeRing].getChar(j),j);
}
}
static class KeyTicks extends TimerTask {
int cw=0;
static char pressKey='Q';
static char lastKey='Q';
static boolean firstRun=true;
int n=0;
/* FIXME - miga gdy odnaleziono litere ?
*/
public void run() {
ArrayList<Integer> indexExist = new ArrayList<Integer>();
int returnIndex;
pressKey=actions.getKey();
if (go) {
wav.stop();
indexExist=checkInstance(pressKey);
for (int exist: indexExist){
falsering[activeRing].setChar(pressKey,exist);
wav.PlayFlag=true;
if (lastKey != pressKey) {
if (sounddialog.soundAccept()){
//System.out.println("Dzwiek akceptuje");
wav.play("/smooth-ok.wav");
}
else System.out.println("Dzwiek NIE akceptuje");
}
}
if (lastKey != pressKey && indexExist.isEmpty() && !firstRun) {
//if (lastKey != pressKey && indexExist.isEmpty()) {
wav.PlayFlag=true;
if (sounddialog.soundAccept()){
//System.out.println("Dzwiek akceptuje");
wav.play("/bass-bad.wav");
}
else System.out.println("Dzwiek NIE akceptuje");
}
lastKey=pressKey;
returnIndex = searchCharChaetSheet(pressKey);
if (returnIndex != -1){
refreshCheatSheet(returnIndex);
}
setDisplayMound();
pressKey=' ';
indexExist.clear();
if (actions.getCheat().equals(CONSTCH)){
//pointsForTheRing=0;
actions.resetCheat();
cheatActivate=true;
unhideWords();
}
if (checkFullRing()) {
totalScore+=pointsForTheRing;
setCharCheatSheet ();
setDisplayMound();
}
firstRun=false;
}
}
static private boolean checkFullRing() {
if (truering[activeRing].getString().equals(falsering[activeRing].getString())){
//System.out.println("Czy zaliczony pierscien ? activeRing:"+activeRing);
if (activeRing >1){
addScores();
cheatActivate=false;
// nowa sciaga
cheatSheet = new ArrayList<String>();
activeRing--;
return true;
}
else {
go=false;
setDisplayMound();
if(activeRing==1){
String s1="Ukonczyles poziom "+level+" !\n",
s2="Na tym poziomie uzyskales "+pointsFOrTheMund+" punktow.\n",
s3="Poki co ugrales "+totalScore+" punktow !\n\n",
s4="Kontynujesz gre ?";
// moze boolean ?
int dialogButton = JOptionPane.YES_NO_OPTION;
int answer = JOptionPane.showConfirmDialog (frame, s1+s2+s3+s4,"Komunikat", dialogButton);
if(answer == JOptionPane.YES_OPTION) {
activeRing=10;
go=true;
level++;
create_secret_mound();
create_real_mound(); // generuje prawdziwy kopiec
setDisplayMound();
pointsFOrTheMund=0;
}
if(answer == JOptionPane.NO_OPTION) {
System.exit(0);
}
}
}
}
return false;
}
// sprawdza czy rzadana litera znajduje sie w pierscieniu
static private ArrayList<Integer> checkInstance(char key){
ArrayList<Integer> indexExist = new ArrayList<Integer>();
for (int i=0; i<truering[activeRing].getLength();i++){
if (truering[activeRing].getChar(i) == key) {
indexExist.add(i);
}
}
/*
if (indexExist.size()!=0) {
changeView=true;
}
*/
return indexExist;
}
}
static class Ring {
char c[];
int l=0; // dlugosc
public Ring(String s){
//System.out.println("Z Ring constructor: "+s+" dlugosc: "+s.length());
c = new char[s.length()+2];
c =s.toCharArray();
l=s.length();
}
public char getChar(int poz){
return (char) c[poz];
}
public void setChar(char _c,int p){
c[p]=_c;
}
public int getLength(){
return l;
}
public String getString(){
String sr = new String();
for (int j=0;j<l;j++){
String _s=Character.toString(c[j]);
sr +=_s;
}
return sr;
}
}
}
class SoundDialog implements ItemListener, ActionListener{
JCheckBox chkBox1;
JFrame frame;
boolean sound = true;
ConfigFile config;
public Boolean runSoundDialog=false;
protected void initUI(ConfigFile cf, JFrame f, Boolean run) {
if (!run) {
frame = new JFrame("Zapytanko");
frame.getContentPane().setSize(new Dimension(300,200)); // nie dziala
frame.getContentPane().setLayout(new GridBagLayout());
frame.setAlwaysOnTop(true);
GridBagConstraints c = new GridBagConstraints();
// nadpisanie metody zamykania okna
frame.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
frame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent ev) {
runSoundDialog=false;
frame.dispose();
}
// zapobiega minimalizacji okna dialogowego
public void windowIconified(WindowEvent we) {
frame.setState(JFrame.NORMAL);
//JOptionPane.showMessageDialog(frame, "Cant Minimize");
}
});
JLabel label = new JLabel(" ");
JButton button = new JButton("Zatwierdz");
chkBox1= new JCheckBox("Odtwarzaj dzwiek");
config=cf;
sound = cf.load();
System.out.println("Dzwiek: "+sound);
chkBox1.setSelected(sound);
c.fill = GridBagConstraints.HORIZONTAL;
c.ipady = 0;
c.weighty = 1.0;
c.gridwidth = 3;
c.gridx = 0;
c.gridy = 0;
frame.getContentPane().add(chkBox1,c);
c.fill = GridBagConstraints.HORIZONTAL;
c.ipady = 0;
c.weighty = 1.0;
c.gridwidth = 3;
c.gridx = 0;
c.gridy = 1;
frame.getContentPane().add(label,c);
c.fill = GridBagConstraints.HORIZONTAL;
c.ipady = 0;
c.weighty = 1.0;
c.anchor = GridBagConstraints.PAGE_END; //bottom of space
c.gridwidth = 3;
c.gridx = 0;
c.gridy = 2;
frame.getContentPane().add(button,c);
chkBox1.addItemListener(this);
button.addActionListener(this);
if (cf.osName.equals("Linux")) frame.setUndecorated(true);
chkBox1.setBorder(BorderFactory.createMatteBorder(20, 20, 20, 20, Color.RED)); // w tym wypadku kolor nie ma znaczenia
frame.getRootPane().setBorder(BorderFactory.createMatteBorder(10, 10, 10, 10, Color.RED));
frame.pack();
// pojawi sie nad oknem rodzica
frame.setLocationRelativeTo(f);
frame.setResizable(false);
frame.setVisible(true);
}
}
public void itemStateChanged(ItemEvent e) {
Object source = e.getItemSelectable();
if (source == chkBox1) {
//System.out.println("Zaznaczono dzwiek");
sound = true;
}
if (e.getStateChange() == ItemEvent.DESELECTED) {
//System.out.println("Odznaczono dzwiek");
sound = false;
}
}
public void actionPerformed(ActionEvent e) {
frame.setVisible(false);
config.save(sound);
runSoundDialog=false;
//System.out.println("Zapisuje dzwiek: "+sound);
}
public boolean soundAccept(){
return sound;
}
}
/*
class ResetDialog implements ItemListener, ActionListener{
JCheckBox chkBox1;
JFrame frame;
boolean reset = false;
protected void initUI(ConfigFile cf) {
frame = new JFrame("Zapytanko");
JPanel mainPanel;
JButton button;
frame.getContentPane().setLayout(new GridBagLayout());
GridBagConstraints c = new GridBagConstraints();
button = new JButton("Zatwierdz");
//chkBox1= new JCheckBox("Odtwarzaj dzwiek");
chkBox1= new JCheckBox("Zresetuj najlepsze wyniki");
chkBox1.setSelected(reset);
c.fill = GridBagConstraints.HORIZONTAL;
c.ipady = 0;
c.weighty = 1.0;
//c.anchor = GridBagConstraints.PAGE_END; //bottom of space
c.gridwidth = 3;
c.gridx = 0;
c.gridy = 0;
frame.getContentPane().add(chkBox1,c);
c.fill = GridBagConstraints.HORIZONTAL;
c.ipady = 0;
c.weighty = 1.0;
c.anchor = GridBagConstraints.PAGE_END; //bottom of space
c.gridwidth = 3;
c.gridx = 0;
c.gridy = 2;
frame.getContentPane().add(button,c);
chkBox1.addItemListener(this);
button.addActionListener(this);
frame.pack();
frame.setLocationRelativeTo(null);
frame.setResizable(false);
frame.setVisible(true);
}
public void itemStateChanged(ItemEvent e) {
//t index = 0;
//ar c = '-';
Object source = e.getItemSelectable();
if (source == chkBox1) {
//dex = 0;
System.out.println("Zaznaczono dzwiek");
reset = true;
}
if (e.getStateChange() == ItemEvent.DESELECTED) {
System.out.println("Odznaczono dzwiek");
reset = false;
}
}
public void actionPerformed(ActionEvent e) {
frame.setVisible(false);
System.out.println("jestem action");
}
public boolean resetAccept(){
return reset;
}
}
*/
/*
class GetNameDialog implements ActionListener, KeyListener {
JTextField text;
JFrame frame;
public String namePlayer="";
public boolean go;
ConfigFile config;
public Boolean runGetNameDialog=false;
protected void initUI(ConfigFile cf, JFrame f, Boolean run) {
if (!run) {
frame = new JFrame("Zapytanko");
frame.getContentPane().setSize(new Dimension(300,200)); // nie dziala
frame.getContentPane().setLayout(new GridBagLayout());
frame.setAlwaysOnTop(true);
GridBagConstraints c = new GridBagConstraints();
// nadpisanie metody zamykania okna
frame.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
frame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent ev) {
runGetNameDialog=false;
frame.dispose();
}
});
JLabel label1 = new JLabel(" ");
JLabel label2 = new JLabel("Najperw sie przedstaw:");
JButton button = new JButton("Zatwierdz");
button.setActionCommand("Button");
text = new JTextField();
//text.addActionListener(this);
//text.setActionCommand("Text");
text.addKeyListener(this);
text.setFocusable(true);
text.requestFocus();
c.fill = GridBagConstraints.HORIZONTAL;
c.ipady = 0;
c.weighty = 1.0;
c.gridwidth = 3;
c.gridx = 0;
c.gridy = 0;
frame.getContentPane().add(label2,c);
c.fill = GridBagConstraints.HORIZONTAL;
c.ipady = 0;
c.weighty = 1.0;
c.gridwidth = 3;
c.gridx = 0;
c.gridy = 1;
frame.getContentPane().add(text,c);
c.fill = GridBagConstraints.HORIZONTAL;
c.ipady = 0;
c.weighty = 1.0;
c.gridwidth = 3;
c.gridx = 0;
c.gridy = 2;
frame.getContentPane().add(label1,c);
c.fill = GridBagConstraints.HORIZONTAL;
c.ipady = 0;
c.weighty = 1.0;
c.anchor = GridBagConstraints.PAGE_END; //bottom of space
c.gridwidth = 3;
c.gridx = 0;
c.gridy = 3;
frame.getContentPane().add(button,c);
text.setEditable(true);
if (namePlayer.length()!=0){
text.setText(namePlayer);
text.selectAll();
}
button.addActionListener(this);
if (cf.osName.equals("Linux")) frame.setUndecorated(true);
frame.getRootPane().setBorder(BorderFactory.createMatteBorder(10, 10, 10, 10, Color.RED));
frame.pack();
frame.setLocationRelativeTo(f);
frame.setResizable(false);
frame.setVisible(true);
}
}
public void actionPerformed(ActionEvent e) {
if(e.getActionCommand().equals("Button")) {
frame.setVisible(false);
namePlayer=text.getText();
runGetNameDialog=false;
if (namePlayer.length()!=0){
go=true;
}
}
else if(e.getActionCommand().equals("Text")) {
String t= text.getText();
text.setText(t);
text.selectAll();
}
}
@Override
public void keyTyped(KeyEvent e) {
}
@Override
public void keyReleased(KeyEvent event) {
}
@Override
public void keyPressed(KeyEvent event) {
if (event.getExtendedKeyCode() == KeyEvent.getExtendedKeyCodeForChar('a')) {
System.out.println("OK");
}
System.out.println("GETNAME");
String t= text.getText();
text.setText(t);
text.selectAll();
}
}
/*
private void readConfig() {
try {
InputStream is = this.getClass().getResourceAsStream("/config");
BufferedReader br=new BufferedReader(new InputStreamReader(is, "utf-8"));
lineConfig = br.readLine();
} catch (Exception e){
e.printStackTrace();
}
}
*/
/*
private void writeConfig() {
try {
OutputStream is = this.getClass().getResourceAsStream("/config");
BufferedReader br=new BufferedReader(new InputStreamReader(is, "utf-8"));
lineConfig = br.readLine();
} catch (Exception e){
e.printStackTrace();
}
}
*/
//}
|