Reputation: 65
With the windowsbuilder i've created a little gui in eclipse. And in the action event of a button ive written this code:
progressBar.setValue(0);
but that does not work. "progressBar cannot be resolved" Please Help! ps: i'm new to Java EDIT:
JButton allButton = new JButton("Klick Mich!");
allButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
progress1.setValue(50);
main.infoBox("Hallo Welt!", "Hallo Welt!");
}
});
EDIT2:
JProgressBar progress1 = new JProgressBar();
progress1.setStringPainted(true);
progress1.setBounds(20, 124, 408, 23);
frame.getContentPane().add(progress1);
}
EDIT3 [COMPLETE CODE] http://pastebin.com/68z1Mpen
Upvotes: 0
Views: 55
Reputation: 5395
Make a JProgressBar progress1
a class field to access it from inner class
public class main {
private JProgressBar progress1;
private JFrame frame;
...
}
and declare it by:
progress1 = new JProgressBar();
or make JProgressBar progress1
final.
Upvotes: 0
Reputation: 9900
you have created jprogressbar after you access it.you have to create before access
like this
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!");
}
});
when you call
progress1.setValue(50);
progress1
isn't declared .so that's why you are getting a error
Upvotes: 1