繁体   English   中英

如果我使用mouselistener具有标签的数组列表,那么单击标签时如何获得索引?

[英]If I have an arraylist of labels using mouselistener, how do I get an index when a label is clicked?

我正在打纸牌游戏。 它具有一个Jlabels数组列表,对应于玩家拥有的每张卡。

单击纸牌jlabel时,如何获取单个JLabel的索引,以便可以调用使用给定索引播放纸牌的playcard()方法?

JLabel temp = new JLabel(icon);
            temp.setBounds(new Rectangle(new Point(shift, 550), temp.getPreferredSize()));
            temp.addMouseListener(this);
            currentdeck.add(temp);
//for loop that adds each jlabel to currentdeck
public void mousePressed(MouseEvent arg0) 
    {
        JLabel label = (JLabel)arg0.getSource();
        //int i = (how would I get the index)?

if(MouseInfo.getPointerInfo().getLocation().getX()>=label.getX()&&MouseInfo.getPointerInfo().getLocation().getY()>=label.getY())
        {
            UNO.playcard(int i);
        }
    }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM