Moin zusammen
Ich hab da grad wieder mal eine "seltsame Erscheinung".
Ich habe ein Panel, dieses Panel hat einen MouseListener zugewiesen bekommen und bei MouseReleased sollte ein gewisser Code ausgeführt werden - komischerweise wird das immer zwei mal ausgeführt!?
Der MouseListener
Mein JFrame welches das besagte Panel "mapPanel" beinhaltet
Sieht jemand einen Fehler der für dieses Verhalten verantwortlich ist?
Gruss & Danke
RoyalFlush[/code]
Ich hab da grad wieder mal eine "seltsame Erscheinung".
Ich habe ein Panel, dieses Panel hat einen MouseListener zugewiesen bekommen und bei MouseReleased sollte ein gewisser Code ausgeführt werden - komischerweise wird das immer zwei mal ausgeführt!?
Der MouseListener
Code:
public class clickController implements MouseListener
{
public clickController()
{
}
public void mouseClicked(MouseEvent arg0)
{
}
public void mousePressed(MouseEvent arg0)
{
}
public void mouseReleased(MouseEvent arg0)
{
if (arg0.getButton() == 1)
{
System.out.println(" Links-Klick: " + arg0.getPoint());
System.out.println("Feld: x" + arg0.getX()/50 + " y" + arg0.getY()/50 );
realPlayer.setSelection(arg0.getX()/50,arg0.getY()/50);
}
else if (arg0.getButton() == 3)
{
System.out.println(" Rechts-Klick: " + arg0.getPoint());
System.out.println(realPlayer.getSelectionX() + " " + arg0.getX()/50 + " " + realPlayer.getSelectionY() + arg0.getY()/50);
if ((arg0.getX()/50 == realPlayer.getSelectionX()) && (arg0.getY()/50 == realPlayer.getSelectionY()))
{
}
else
{
gameWindow.getInstance().showStandardFieldPopup(arg0);
}
}
}
Mein JFrame welches das besagte Panel "mapPanel" beinhaltet
Code:
public class gameWindow extends JFrame
{
public static gameWindow instance = null;
private JPanel container = new JPanel();
private JMenuBar mainMenu = new JMenuBar();
private JMenu gameMenu = new JMenu();
private JPanel top = new JPanel();
private mapPanel map = new mapPanel();
private JPanel mainContent = new JPanel();
private JScrollPane sub = new JScrollPane(map);
private JPopupMenu standPop = new JPopupMenu();
public static gameWindow getInstance()
{
if (gameWindow.instance == null)
{
gameWindow.instance = new gameWindow();
}
return gameWindow.instance;
}
private gameWindow()
{
this.setUndecorated(true);
initWindow();
}
public void initWindow()
{
this.setTitle("Sunburst (c) 2008 by Royal Flush Entertainment");
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
this.setBackground(new Color(0,0,0));
this.setLayout(new FlowLayout());
// Vollbild-Modus simulieren
graphicsDeviceController.getInstance().setFullscreenMode(this);
// Container-Panel vorbereiten (Container-Panel)
this.container.setSize(1280,1024);
this.container.setSize(1280,1024);
this.container.setPreferredSize(new Dimension(1280,1024));
this.container.setMinimumSize(new Dimension(1280,1024));
this.container.setBackground(new Color(0,0,0));
this.container.setBorder(new LineBorder(new Color(0,0,0)));
// Map-Panel vorbereiten
this.map.setSize(5000,5000);
this.map.setPreferredSize(new Dimension(5000,5000));
this.map.setMinimumSize(new Dimension(5000,5000));
this.map.setBackground(new Color(0,0,0));
this.map.addMouseListener(new clickController()); // Hier wird der Listener aufs Panel gesetzt
// Main Content Panel (incl: SubPanel, RightInfoPanel
this.mainContent.setLayout(new BorderLayout());
this.mainContent.setSize(1280,580);
this.mainContent.setPreferredSize(new Dimension(1280,580));
this.mainContent.setMinimumSize(new Dimension(1280,580));
this.mainContent.setBackground(new Color(0,0,0));
this.mainContent.setBorder(new LineBorder(new Color(0,0,0)));
// Subpanel (Scrollpane für MapPanel)
this.sub.setSize(1080,568);
this.sub.setPreferredSize(new Dimension(1080,568));
this.sub.setMinimumSize(new Dimension(1080,568));
this.sub.setBackground(new Color(0,0,0));
this.sub.setBorder(new LineBorder(new Color(0,0,0)));
// Top Panel (für Spielinfos)
this.top.setSize(1280,100);
this.top.setPreferredSize(new Dimension(1280,100));
this.top.setMinimumSize(new Dimension(1280,100));
this.top.setBackground(new Color(0,0,0));
this.top.setBorder(new LineBorder(new Color(0,0,0)));
this.mainMenu.setBorderPainted(false);
this.mainMenu.setBackground(new Color(0,0,0));
JMenuItem fieldInfo = new JMenuItem();
fieldInfo.setText("Field Info");
this.standPop.add(fieldInfo);
// Panels hinzufügen
this.container.add(mainMenu);
this.gameMenu.setText("Game");
this.mainMenu.add(this.gameMenu);
this.add(this.standPop);
this.mainContent.add(sub, java.awt.BorderLayout.WEST);
this.container.add(this.top);
this.container.add(this.mainContent);
this.add(container);
this.setEnabled(true);
this.setVisible(true);
}
public void showStandardFieldPopup(MouseEvent e)
{
this.standPop.show(e.getComponent(),e.getX(),e.getY());
}
}
Sieht jemand einen Fehler der für dieses Verhalten verantwortlich ist?
Gruss & Danke
RoyalFlush[/code]