swing多个JTextArea组成的控件数组问题

lqsmn613 2009-10-06 10:05:49
JTextArea t01 = new JTextArea();

JTextArea t02 = new JTextArea();

JTextArea t03 = new JTextArea();

JTextArea t04 = new JTextArea();

JTextArea t05 = new JTextArea();

JTextArea t06 = new JTextArea();

JTextArea t07 = new JTextArea();

JTextArea t11 = new JTextArea();

JTextArea t12 = new JTextArea();

JTextArea t13 = new JTextArea();

JTextArea t14 = new JTextArea();

JTextArea t15 = new JTextArea();

JTextArea t16 = new JTextArea();

JTextArea t17 = new JTextArea();

JTextArea t21 = new JTextArea();

JTextArea t22 = new JTextArea();

JTextArea t23 = new JTextArea();

JTextArea t24 = new JTextArea();

JTextArea t25 = new JTextArea();

JTextArea t26 = new JTextArea();

JTextArea t27 = new JTextArea();

JTextArea t31 = new JTextArea();

JTextArea t32 = new JTextArea();

JTextArea t33 = new JTextArea();

JTextArea t34 = new JTextArea();

JTextArea t35 = new JTextArea();

JTextArea t36 = new JTextArea();

JTextArea t37 = new JTextArea();

JTextArea t41 = new JTextArea();

JTextArea t42 = new JTextArea();

JTextArea t43 = new JTextArea();

JTextArea t44 = new JTextArea();

JTextArea t45 = new JTextArea();

JTextArea t46 = new JTextArea();

JTextArea t47 = new JTextArea();

JTextArea t51 = new JTextArea();

JTextArea t52 = new JTextArea();

JTextArea t53 = new JTextArea();

JTextArea t54 = new JTextArea();

JTextArea t55 = new JTextArea();

JTextArea t56 = new JTextArea();

JTextArea t57 = new JTextArea();

JTextArea[] textArea_day = new JTextArea[] { t01, t02, t03, t04, t05, t06,
t07, t11, t12, t13, t14, t15, t16, t17, t21, t22, t23, t24, t25,
t26, t27, t31, t32, t33, t34, t35, t36, t37, t41, t42, t43, t44,
t45, t46, t47, t51, t52, t53, t54, t55, t56, t57 };


我定义的一个控件数组,一个textArea_day的for循环里,通过textArea_day[i].addMouseListener(...);的方法给予每个JTextArea添加个鼠标监听,如果在监听事件中,取得:发生鼠标事件的是哪一个JTextArea。
比如说:textArea_day[i].取得数组内的txx.通过txx来对某个JTextArea进行操作??可以嘛?
...全文
155 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
JavaerRobertLi 2009-10-06
  • 打赏
  • 举报
回复
何必打那么多行呢?不好维护

建立一个新类继承JTextArea就是了

public class JMyTextArea extends JTextArea
{
public JMyTextArea(int num)
{
super();
this.num=num;
}
public getNum(){return num;}
private int num;
}
接下来凡是用到JTextArea的地方就用你的JMyTextArea
建立的时候这样:

JMyTextArea[] textArea_day = new JMyTextArea[57];

for(int i=0;i<57;i++)
{
textArea_day[i]=new JMyTextArea(i);
textArea_day[i].addMouseListener(...);
}

鼠标单机事件后,通过getNum()获得是哪个TextArea被点了。
提示:MouseListener写为内嵌类
我的方案仅供参考,以提供思路

50,530

社区成员

发帖
与我相关
我的任务
社区描述
Java相关技术讨论
javaspring bootspring cloud 技术论坛(原bbs)
社区管理员
  • Java相关社区
  • 小虚竹
  • 谙忆
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧