java 如何用鼠标点击button后,获得button上的字符

java 如何用鼠标点击button后,获得button上的字符,第1张

在Button上注册监视器,然后用button的getLabel()方法。

具体代码

Button button=new Button("获得按钮字符");

buttonaddActiontListener(new ActionListener()

{

public void actionPerformed(ActionEvent e)

{Button temp=(Button)egetSource();

Systemoutprintln(tempgetLabel):

}

}

);

/

  返回选择状态的按钮索引列表,未选择返回空List。

  @param buttonList

  @return

 /

public static List<Integer> getSelectIndexList(List<JToggleButton> buttonList){

//buttonGroupgetSelection()getActionCommand();

List<Integer> indexList = new ArrayList<Integer>();

if(buttonList!=null && buttonListsize()>0){

for(int i=0;i<buttonListsize();i++){

if(buttonListget(i)isSelected()){

indexListadd(IntegervalueOf(buttonListget(i)getActionCommand()));

}

}

}

return indexList;

}

这个是设置按钮列表的代码

JRadioButton jr = new JRadioButton();

jrsetActionCommand(""+i);  //设置按钮对应的命令值为i的值(我这个是设置为数组下标)

buttonGroupadd(jr);  //加入按钮组

buttonListadd(jr); //加入按钮列表

a和b页面之间的关系是什么?

他们之间需要有个关系,比如a是父页面,b是通过a打开的子页面,这样的话在a中的点击内容可以通过父页面和子页面之间的关系中b中呈现出来,反之亦然。

父页面和子页面的交互lz可以百度,网上大把,内容比较多,我就不干copy、paste的活儿了。

以上就是关于java 如何用鼠标点击button后,获得button上的字符全部的内容,包括:java 如何用鼠标点击button后,获得button上的字符、java swing 获取按钮信息、java怎么才能点击a按钮就可以获得b按钮的信息等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/10160173.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-05-05
下一篇2023-05-05

发表评论

登录后才能评论

评论列表(0条)

    保存