JAVA如何在点击事件中取得label文字 10
publicclasssdsadextendsJFrame{privateJLabellabel;publicsdsad(){label=newJLabel("一",Sw...
public class sdsad extends JFrame {
private JLabel label;
public sdsad (){
label= new JLabel("一", SwingConstants.CENTER);
label.setForeground(Color.black);
this.add(label);
label.addMouseListener(new clickAction());
}
}
class clickAction implements MouseListener{
public void mouseClicked(MouseEvent e){}
public void mouseEntered(MouseEvent e) {}
public void mouseExited(MouseEvent e) {}
public void mousePressed(MouseEvent e) {}
public void mouseReleased(MouseEvent e) {}
}
}
刚打不知道有没有错!
想问的是在clickAction如何取得label的"一"
还是不行呀~~~
lass clickAction implements MouseListener{
public void mouseClicked(MouseEvent e){}
public void mouseEntered(MouseEvent e) {}
public void mouseExited(MouseEvent e) {}
public void mousePressed(MouseEvent e) {
String str = label.getText()
JOptionPane.showMessageDialog(null,str);
}
public void mouseReleased(MouseEvent e) {}
}
} 展开
private JLabel label;
public sdsad (){
label= new JLabel("一", SwingConstants.CENTER);
label.setForeground(Color.black);
this.add(label);
label.addMouseListener(new clickAction());
}
}
class clickAction implements MouseListener{
public void mouseClicked(MouseEvent e){}
public void mouseEntered(MouseEvent e) {}
public void mouseExited(MouseEvent e) {}
public void mousePressed(MouseEvent e) {}
public void mouseReleased(MouseEvent e) {}
}
}
刚打不知道有没有错!
想问的是在clickAction如何取得label的"一"
还是不行呀~~~
lass clickAction implements MouseListener{
public void mouseClicked(MouseEvent e){}
public void mouseEntered(MouseEvent e) {}
public void mouseExited(MouseEvent e) {}
public void mousePressed(MouseEvent e) {
String str = label.getText()
JOptionPane.showMessageDialog(null,str);
}
public void mouseReleased(MouseEvent e) {}
}
} 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询