62,623
社区成员
发帖
与我相关
我的任务
分享if(e.getItemSelectable()==cho) {
String str=cho.getSelectedItem();
text.setText(str);
}
或者:
String str = "":
f(e.getItemSelectable()==cho)
str=cho.getSelectedItem();
text.setText(str);
public void itemStateChanged(ItemEvent e)
{
String str; //#1
if(e.getItemSelectable()==cho)
str=cho.getSelectedItem(); //#2
text.setText(str); //#3
}
JButton jbutton_1=new JButton("jbutton");
JButton jbutton_2=new JButton("jbutton"); //两个按钮标签一样
jbutton_1.setActionCommand("jbutton_1"); //设置按钮1的ActionCommand值为"jbutton_1"
jbutton_2.setActionCommand("jbutton_2"); //设置按钮2的ActionCommand值为"jbutton_2"
System.out.println(jbutton_1.getLabel()); //输出:jbutton
System.out.println(jbutton_2.getLabel()); //输出:jbutton
System.out.println(jbutton_1.getActionCommand()); //输出:jbutton_1
System.out.println(jbutton_2.getActionCommand()); //输出:jbutton_2
if(e.getItemSelectable()==cho)
String str=cho.getSelectedItem();
if(e.getItemSelectable()==cho)
{
String str=cho.getSelectedItem();
str=new String("...");
//可以对str进行任何操作
}