0
请我需要你的帮助,即时尝试做到这一点,我想现在3-4天,我不能。 我有2个类MainForm和Class2。 我在Class1中的方法内有一个JLablel,我想通过按下Class2中的按钮来修改它。修改一个无效方法内的JLabel
public class MainForm {
private JFrame frame;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
MainForm window = new MainForm();
window.frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the application.
*/
public MainForm() {
initialize();
}
/**
* Initialize the contents of the frame.
*/
private void initialize() {
frame = new JFrame();
frame.setBounds(400, 200, 488, 322);
frame.setTitle("ShutDown");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().setLayout(null);
frame.setResizable(false);
/**
* Time BOX
*/
JComboBox<String> timeBox = new JComboBox<String>();
timeBox.setBounds(73, 142, 90, 20);
timeBox.addItem("Days");
timeBox.addItem("Hours");
timeBox.addItem("Minutes");
timeBox.addItem("Seconds");
timeBox.addItem("Right now");
timeBox.setSelectedItem("Minutes");
frame.getContentPane().add(timeBox);
String getTimeBox = timeBox.getSelectedItem().toString();
/**
* The label info.
*/
JLabel labelInfo = new JLabel("");
labelInfo.setBounds(73, 209, 310, 14);
frame.getContentPane().add(labelInfo);
labelInfo.setText(getTimeBox);
}
和2类
Class2
JButton okButton = new JButton("OK");
okButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
}
我想多和永诺不工作,什么我需要在该按钮写代码即可获得从时间盒(组合框)的selectedItem属性 ,并把它到那个标签?