Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

Problem with mouse listener in jlabel array

$
0
0
Hi! So I'm making a game of air traffic control and I'm having a problem with my mouse listener. It is supposed to select a cell with left click and then move the airplane to the cell selected with right click. But I found out that it is not saving the left click coordinates or that when I right click it resets them. It only works for the index [0][0].
My code for the listener is this:
public class cliqueRato implements MouseListener {  
    private final int j, k;
    int a,b;
    JLabel aviaos=new JLabel(new ImageIcon("src/imagens/aviaonormalseleccionado.png"));  
    ImageIcon aviao=new ImageIcon("src/imagens/aviaonormal.jpg");  
    ImageIcon aviaoselec=new ImageIcon("src/imagens/aviaonormalseleccionado.png");  
    public cliqueRato(int j, int k){  
        this.j=j;  
        this.k=k;  
    }  
    public void mouseClicked(MouseEvent e){  
        
      
          
    }  
    public void mouseEntered(MouseEvent e) {  
        // TODO Auto-generated method stub  
          
    }  
    public void mouseExited(MouseEvent e) {  
        // TODO Auto-generated method stub  
          
    }  
    public void mousePressed(MouseEvent e) {  
            if(e.getButton()==MouseEvent.BUTTON1){  
            janela.grelha[j][k].setIcon(aviaoselec);  
            a=j;  
            b=k;  
        }  
              
          
        else{  
              
            if(e.getButton()==MouseEvent.BUTTON3){  
                janela.grelha[a][b].setIcon(null);  
                janela.grelha[j][k].setIcon(aviao);  
              
            }  
              
        } 
          
    }  
    public void mouseReleased(MouseEvent e) {  
          
          
    }  
} 


The left click works perfectly, I'm only having problems with the right click

Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>