2
What I’m trying to do is, when I call an Enum, and instantiate, it shows up with an X value, 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 administers 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 class of the mouseListener:
//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 click on the "IMAGEM1" the Enum receives another value, that is, the enumeration receives the value enumeration = Enumeration.VAR2;
, only, instead of changing something or changing the image, it doesn’t happen at all, and worse, it changes the Enum, and even putting System.out.println
to check, does not give any message on the console saying whether or not changed...
I only mentioned part of the code that I’m having problems, because mouse events, change values and etc, I’m not having any problems.
show all chunk of code because in this one it will really be difficult to catch the error
– user6026
the ideal would be you create a Minimum, Complete and Verifiable Example, It’s a little hard to understand your doubt at the moment
– Math