-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPuzzleFixWorking.java
158 lines (130 loc) · 7.04 KB
/
PuzzleFixWorking.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
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.*; //IMPORT ALL .AWT METHODS
import java.awt.event.*;
import javax.swing.*; //IMPORT ALL JAVAX SWING CLASSES/METHODS
import javax.swing.border.*;
import java.util.*;
import java.lang.*;
import java.lang.Object;
import javax.swing.ImageIcon;
public class PuzzleFixWorking extends JFrame implements ActionListener
{
/*
setDefaultCloseOperation(SecondAttempt.DISPOSE_ON_CLOSE);
setSize(600,600);
setVisible(true);
* */
/*MattButton*/JButton JTileArray[] = new /*MattButton*/JButton[12];//Declare Array To Hold JButtons
Icon GreyBoxGlobalStorageIcon = new ImageIcon("bart0.jpg");
String GreyBoxGlobalStorageString = GreyBoxGlobalStorageIcon.toString();
public PuzzleFixWorking()
{
setSize(444,410); //Set Size Of JFrame
Populate(); //Jump & Link To JPanel Creation & Working
}
public void Populate() //Code Jump & Link
{
JPanel WindowContents = new JPanel(); // Create New JPanel Called WindowContects
BorderLayout borderlayout = new BorderLayout(); //Creates BorderLayout Object
WindowContents.setLayout(borderlayout); //Sets Border Layout Using BorderLayout Object
WindowContents.setSize(600,600); //Set Size Of Windows Contents
WindowContents.setVisible(true); //Set Window Contents To Be Visible
WindowContents.setLayout(new GridLayout(3, 4)); //Sets Ordered Grid LAyout For JPanel
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Icon IconArray[] = new ImageIcon[12]; //Create Array For Images
IconArray[0] = new ImageIcon("bart0.jpg"); //Step Through Populate Each Array Entry With Each Image
IconArray[1] = new ImageIcon("bart1.jpg");
IconArray[2] = new ImageIcon("bart2.jpg");
IconArray[3] = new ImageIcon("bart3.jpg");
IconArray[4] = new ImageIcon("bart4.jpg");
IconArray[5] = new ImageIcon("bart5.jpg");
IconArray[6] = new ImageIcon("bart6.jpg");
IconArray[7] = new ImageIcon("bart7.jpg");
IconArray[8] = new ImageIcon("bart8.jpg");
IconArray[9] = new ImageIcon("bart9.jpg");
IconArray[10] = new ImageIcon("bart10.jpg");
IconArray[11] = new ImageIcon("bart11.jpg"); //Final Step Through
int counter = 0; //Initialise Counter For While Loop
while(counter<12)
{
JButton tile = new JButton(IconArray[counter]); //Create New JButton With Image called Tile
tile.addActionListener(this); //AddActionListener To This Tile
JTileArray[counter] = tile ; //Walks Over Creating JTiles With Each BartImage To Corresponding Button In J Tile Array
counter = counter + 1; //
}
counter = counter-counter;
while(counter<12)
{
WindowContents.add(JTileArray[counter]); //Add Each JTile From Array To Panel
counter = counter + 1;
}
counter = counter - counter; //ResetLoop Counter
//JTileArray[0].setVisible(false); //Sets First J Tile To False
setContentPane(WindowContents); //Set The JPanel (WindowsContents To JFrame)
}
public static void main(String [] args)
{
PuzzleFixWorking ShowMe = new PuzzleFixWorking();
ShowMe.setVisible(true);
}
@Override
public void actionPerformed(ActionEvent e)
{
JButton something = (JButton) e.getSource(); //Something Stores The Tile That Clicks The Button
Icon StoreClickedImage = something.getIcon();
//JTileArray[0].setIcon(StoreClickedImage);
int isolatedcounter = 0;
while(isolatedcounter < 12)
{
JButton ReplacerTile = JTileArray[isolatedcounter]; //Stores (All Array) Walked Over Copy Of Button In Replacer Tile To Interact With
Icon ReplacerTileImage = ReplacerTile.getIcon(); //Stores The Image Of The WalkedOverTile in ReplacerTileImage As Icon
String StoreClickedImageString = StoreClickedImage.toString(); //Converts The Image Of The Clicked Tile To A String Ready For Comparison
String ReplacerTileImageString = ReplacerTileImage.toString(); //Converts The Image Of The WalkedOverTile Iteration To A String Ready For Comparison
if(ReplacerTileImageString.compareTo(GreyBoxGlobalStorageString) == 0 && e.getSource() == JTileArray[isolatedcounter+1]/* || e.getSource() == JTileArray[isolatedcounter-1] || e.getSource() == JTileArray[isolatedcounter+4] || e.getSource() == JTileArray[isolatedcounter-4]*/)
{
JTileArray[isolatedcounter].setIcon(StoreClickedImage); //If The String Of The Original Grey Box Is Found replace it's icon with the one of the swuare that has been clicked
Icon GreyBox = new ImageIcon("bart0.jpg"); //Stores The Grey Box As An Image
JButton tile2 = new JButton(GreyBox); //Assigns The Grey Box To A JButton
something.setIcon(GreyBox);
isolatedcounter = 12;
}
if(ReplacerTileImageString.compareTo(GreyBoxGlobalStorageString) == 0 && e.getSource() == JTileArray[isolatedcounter-1] /*|| e.getSource() == JTileArray[isolatedcounter+4] || e.getSource() == JTileArray[isolatedcounter-4]*/)
{
JTileArray[isolatedcounter].setIcon(StoreClickedImage); //If The String Of The Original Grey Box Is Found replace it's icon with the one of the swuare that has been clicked
Icon GreyBox = new ImageIcon("bart0.jpg"); //Stores The Grey Box As An Image
JButton tile2 = new JButton(GreyBox); //Assigns The Grey Box To A JButton
something.setIcon(GreyBox);
isolatedcounter = 12;
}
if(ReplacerTileImageString.compareTo(GreyBoxGlobalStorageString) == 0 && e.getSource() == JTileArray[isolatedcounter+4] /*|| e.getSource() == JTileArray[isolatedcounter-4]*/)
{
JTileArray[isolatedcounter].setIcon(StoreClickedImage); //If The String Of The Original Grey Box Is Found replace it's icon with the one of the swuare that has been clicked
Icon GreyBox = new ImageIcon("bart0.jpg"); //Stores The Grey Box As An Image
JButton tile2 = new JButton(GreyBox); //Assigns The Grey Box To A JButton
something.setIcon(GreyBox);
isolatedcounter = 12;
}
if(ReplacerTileImageString.compareTo(GreyBoxGlobalStorageString) == 0 && e.getSource() == JTileArray[isolatedcounter-4])
{
JTileArray[isolatedcounter].setIcon(StoreClickedImage); //If The String Of The Original Grey Box Is Found replace it's icon with the one of the swuare that has been clicked
Icon GreyBox = new ImageIcon("bart0.jpg"); //Stores The Grey Box As An Image
JButton tile2 = new JButton(GreyBox); //Assigns The Grey Box To A JButton
something.setIcon(GreyBox);
isolatedcounter = 12;
}
isolatedcounter = isolatedcounter + 1;
/*PSEUDO CODE BABY
* Walkover all the tiles
* Check If Each Tile Is Equal To A String Of The Image Grey Box
* For The Tile That Contains The Image
* Assign The StoredImage Of The ClickTile To The Tile That IS Found To Have Grey Box
* (Implementation Requires converting each image to a string From Comparison then using string compare)
* Allow Program To Run As Normally Because Later Turns The One That Has Been clicked Grey
* This allows the grey to move continuosly while swapping tiles
* */
}
isolatedcounter = isolatedcounter - isolatedcounter;
}
}