What I'm trying to do is that when I call an Enum, and instantiate it, it appears with value X, and when I'm messing with it in the code, it changes the value to whatever I want. >
Example:
//Classe dos enums
public class Enumers{
public enum Enumeration{
VAR1, VAR2, VAR3;
}
}
The class that manages the enums:
//Classe em que estou tentando mudá-lo
public class ExtensionMouse implements MouseListener, MouseMotionListener, ActionListener {
public Enumers.Enumeration enumeration = Enumeraton.VAR1;
public MainMenu menu = new MainMenu();
public Point mousePoint;
public int z = 0;
public void paint(Graphics g) {
Graphics2D g2 = (Graphics2D) g;
switch (enumeration) {
case VAR1:
//A imagem "IMAGEM1" já está setada e funcionando //corretamente
break;
case VAR2:
menu.paint(g2); //A imagem "IMAGEM2" já está setada também e funcionando
break;g
}
}
@Override
public void mousePressed(MouseEvent arg0) {
int mouse = arg0.getButton();
mousePoint = arg0.getPoint();
switch (enumeration) {
case VAR1:
for (int i = 0; i < 3; i++) {
if (menu.mI.getRetBts(i).contains(mousePoint)) {
if (mouse == MouseEvent.BUTTON1) {
if (i == 0) {
enumeration = Enumeration.VAR2;
} else if (i == 1) {
System.out.println("mudou Menu");
} else if (i == 2) {
System.exit(0);
}
}
}
}
break;
default:
break;
}
}
@Override
public void actionPerformed(ActionEvent arg0) {
switch (enumeration) {
case VAR1:
break;
case VAR2:
enumeration = Enumeration.VAR2;
break;
case VAR3:
break;
default:
break;
}
}
}
The mouseListener class:
//Classe do mouse
public class MouseAdaptador implements MouseListener, ActionListener, MouseMotionListener
{
ExtensionMouse eM = new ExtensionMouse();
@Override
public void mousePressed(MouseEvent e)
{
eM.mousePressed(e);
}
@Override
public void actionPerformed(ActionEvent arg0) {
}
@Override
public void mouseMoved(MouseEvent arg0) {
eM.mouseMoved(arg0);
}
}
The MainLoop class
public class MainLoop extends JPanel implements ActionListener
{
private static final long serialVersionUID = 1L;
//Instances
ExtensionMouse eM = new ExtensionMouse();
//
public MainLoop()
{
addMouseListener(new MouseAdaptador());
addMouseMotionListener(new MouseAdaptador());
setDoubleBuffered(true);
}
public void paint(Graphics g)
{
eM.paint(g);
}
public void actionPerformed(ActionEvent arg0)
{
eM.update();
eM.actionPerformed(arg0);
}
}
The problem comes later, when I put the method of mouseClicked()
or mousePressed()
, that when the mouse clicks on "IMAGE1" the enum receives another value, that is, the enumeration receives the value enumeration = Enumeration.VAR2;
, only that, instead of changing something or changing the image, it does not happen at all, and worse, it changes the enum, and even putting System.out.println
to check, it does not give any message on the console saying if it changed or not ...
I just quoted part of the code that I'm having problems, because mouse events, change values and etc, I do not have any problems.