The idea of program is to change the images between them.
Images here is stored in Icon Labels. If i click on image(label), i need to memorize this image, and change with the second image. Like a puzzle game.
I can to return the last two clicked image, but when i try to make changes between them, he dosn't work.
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
class Fereastra extends Frame implements MouseListener{
public Panel p = new Panel();
int countClick=0;//Count the click numbers
public String value1 = new String(); // first clicked image
public String value2 = new String(); //second clicked image
public String AUX = new String(); // the variable who make changes between images
public String pathValue = new String(); //variable who give the path of image
// Labels, here is stored images like icons.
public JLabel l;
public JLabel l2;
public JLabel l3;
//Path to images
public String path1=new String("hel1.jpg");
public String path2=new String("hel2.jpg");
public String path3=new String("eams.jpg");
public Fereastra(){
super("puzzle");
setSize(300,300);
myRepaint(); //draw Images
p.add(l);
p.add(l2);
p.add(l3);
add(p);
l.addMouseListener(this);
l2.addMouseListener(this);
l3.addMouseListener(this);
pack();
}
public void myRepaint(){ //draw images
l = new JLabel(new ImageIcon(path1));
l2= new JLabel(new ImageIcon(path2));
l3= new JLabel(new ImageIcon(path3));
}
public void mouseClicked(MouseEvent e) {
countClick+=1; //if cl
if(e.getComponent()==l){
pathValue=path1;
}
if(e.getComponent()==l2){
pathValue=path2;
}
if(e.getComponent()==l3){
pathValue=path3;
}
//the last two images between i need to do changes is stored in "value1" & "value2"
if(countClick==1)
{
value1=pathValue; System.out.println(value1);
}
if(countClick==2){
value2=pathValue; System.out.println(value2);
//Here i try to make the changes
AUX=value1;
value1=value2;
value2=AUX;
repaint();
}
countClick=0; //reset count
}
public void mouseEntered(MouseEvent e) {
}
public void mousePressed(MouseEvent e){
}
public void mouseReleased(MouseEvent e){
}
public void mouseExited(MouseEvent e){
}
}
public class ImageIconss{
public static void main(String args[]){
new Fereastra().show();
}
}
Please provide with any advice and help!