当前位置: 技术问答>java相关
请问我在一个applet中动态的写了很多的JLabel(每个JLabel都没有具体的名称),如何在点击某一个JLabel时出发鼠标事件,得到该JLabel的文本
来源: 互联网 发布时间:2015-05-23
本文导语: 请具体的说明后,一定给分,很急!!谢谢! | 我帮你写了个,看看 import java.awt.*; import java.applet.*; import javax.swing.*; import java.awt.event.*; public class LabelText extends JApplet { JPanel jp=new JPa...
请具体的说明后,一定给分,很急!!谢谢!
|
我帮你写了个,看看
import java.awt.*;
import java.applet.*;
import javax.swing.*;
import java.awt.event.*;
public class LabelText extends JApplet {
JPanel jp=new JPanel();
JL jlObj=new JL();
String str;
public void init() {
getContentPane().add(jp);
jp.add(jlObj);
}
class JL extends JLabel
{
JL()
{
setText("click me ");
addMouseListener(new PanelMouseProcess());
}
private void getLabelText()
{
str=getText();
str=str+" ok ";
setText(str);
}
class PanelMouseProcess extends MouseAdapter
{
public void mouseClicked(MouseEvent e)
{
getLabelText();
}
}
}
}
import java.awt.*;
import java.applet.*;
import javax.swing.*;
import java.awt.event.*;
public class LabelText extends JApplet {
JPanel jp=new JPanel();
JL jlObj=new JL();
String str;
public void init() {
getContentPane().add(jp);
jp.add(jlObj);
}
class JL extends JLabel
{
JL()
{
setText("click me ");
addMouseListener(new PanelMouseProcess());
}
private void getLabelText()
{
str=getText();
str=str+" ok ";
setText(str);
}
class PanelMouseProcess extends MouseAdapter
{
public void mouseClicked(MouseEvent e)
{
getLabelText();
}
}
}
}