使用 windowsbuilder,我在 eclipse 中创建了一个小 gui。 在按钮的操作事件中,我编写了以下代码:
progressBar.setValue(0);
但这不起作用。 “进度条无法解析” 请帮忙! ps:我是Java新手 编辑:
JButton allButton = new JButton("Klick Mich!");
allButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
progress1.setValue(50);
main.infoBox("Hallo Welt!", "Hallo Welt!");
}
});
编辑2:
JProgressBar progress1 = new JProgressBar();
progress1.setStringPainted(true);
progress1.setBounds(20, 124, 408, 23);
frame.getContentPane().add(progress1);
}
编辑3 [完整代码] http://pastebin.com/68z1Mpen
最佳答案
您在访问jprogressbar后已经创建了它。您必须在访问之前创建
像这样
JProgressBar progress1 = new JProgressBar();
JButton allButton = new JButton("Klick Mich!");
allButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
progress1.setValue(50);
main.infoBox("Hallo Welt!", "Hallo Welt!");
}
});
当你打电话时
progress1.setValue(50);
progress1
未声明。这就是您收到错误的原因
关于java - 无法从按钮访问 JProgressbar [Java],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31317261/