【发布时间】:2012-03-09 14:00:12
【问题描述】:
我有一个组合框,您可以在从表中获取值的代码中看到。 因此,在我单击确定后,表的值会发生变化。 如何在不关闭和打开 jframe 的情况下查看组合框的这些新值? 我今天对 java.awt.EventQueue.invokeLater 和其他工作人员进行了很多研究,但我无法让它发挥作用,我对 java 和一般编程很陌生。 所以这里是代码:
public class Compo extends JFrame implements ActionListener
{//start of class Compo
//start of variables
private JComboBox<String> CompoBox;
private String array[];
private JButton okButton;
private JPanel panel;
//end of variables
public Compo ()
{//start of Compo method
super("Example");
panel=new JPanel(null);
//table = new String[3];
array= new String[3];
array[0]="alpha";
array[1]="beta";
array[2]="charlie";
CompoBox= new JComboBox<>(array);
CompoBox.setBounds(50, 70, 100, 20);
panel.add(CompoBox);
okButton=new JButton("ok");
okButton.setBounds(50, 120, 70, 30);
okButton.setActionCommand("ok");
okButton.addActionListener(this);
panel.add(okButton);
add(panel);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setSize(200, 200);
setVisible(true);
}//end of compo method
@Override
public void actionPerformed(ActionEvent event)
{//start of actionperformed
String testString=event.getActionCommand();
if (testString.equals("ok"))
{//start of if
for (int i = 0; i < array.length; i++)
{
String sample= array[i];
array[i]=sample+"aa";
}
}//end of if
}//end of aciton performed
}//end of class Compo
【问题讨论】:
-
我在这里订阅的 3 天内如何改进它?
-
请学习java命名约定并遵守它们
-
现在的问题是按钮只在第一次点击时才起作用!