| Author |
using a bean
|
Candy Bortniker
Ranch Hand
Joined: Mar 17, 2003
Posts: 123
|
|
I have built a java bean that contains a jslider, it is to be used to set and change the value of a color in a circle. I'm having trouble accessing my getter in the bean because I get a compile error: C:\Candy\Java\CircleTest.java:57: cannot resolve symbol symbol : method getValue () location: class BlueSliderBean blue.getValue(); ^ Here is what the code looks like: What do I need to do to access getValue()
|
 |
Ernest Friedman-Hill
author and iconoclast
Marshal
Joined: Jul 08, 2003
Posts: 24045
|
|
Things to check: Is there really a method called getValue() which takes no arguments? Capitalization and spelling count! Is it in the BlueSliderBean class? Is it public?
|
[Jess in Action][AskingGoodQuestions]
|
 |
Candy Bortniker
Ranch Hand
Joined: Mar 17, 2003
Posts: 123
|
|
|
The answer is "yes" to all of these things.
|
 |
Ernest Friedman-Hill
author and iconoclast
Marshal
Joined: Jul 08, 2003
Posts: 24045
|
|
|
Well, the compiler seems to disagree. Can we see the code for BlueSliderBean?
|
 |
Candy Bortniker
Ranch Hand
Joined: Mar 17, 2003
Posts: 123
|
|
import java.awt.*; import java.awt.event.*; import java.beans.*; import javax.swing.*; import javax.swing.event.*; public class BlueSliderBean { public static void main (String[] args) { BlueSliderBeanFrame frame = new BlueSliderBeanFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.pack(); frame.show(); } } class BlueSliderBeanFrame extends JFrame implements DocumentListener { public static final int DEFAULT_WIDTH = 350; public static final int DEFAULT_HEIGHT = 100; JSlider slider = new JSlider(0,255); private JPanel sliderPanel; private JLabel integerlbl; private JTextField textField; private ChangeListener listener; private int value = 0; public BlueSliderBeanFrame() { setTitle("BlueSliderBean"); setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT); sliderPanel = new JPanel(); sliderPanel.setLayout(new FlowLayout(FlowLayout.LEFT)); //listens for slider listener = new ChangeListener() { public void stateChanged(ChangeEvent event) { //update text field when the slider value changes JSlider source = (JSlider)event.getSource(); if (source.getValueIsAdjusting()) { int fps = (int)source.getValue(); } integerlbl.setText("" + source.getValue()); } }; //add a filled slider slider.setPaintTicks(true); slider.setMajorTickSpacing(20); slider.setMinorTickSpacing(5); slider.putClientProperty("JSlider.isFilled", Boolean.TRUE); addSlider(slider, "Filled"); //add the text field that displays the slider value integerlbl = new JLabel(); textField = new JTextField(2); textField.getDocument().addDocumentListener(this); Container contentPane = getContentPane(); contentPane.add(sliderPanel, BorderLayout.CENTER); contentPane.add(textField, BorderLayout.EAST); //Need actionlistener contentPane.add(integerlbl, BorderLayout.SOUTH); }//close constructor public void changedUpdate(DocumentEvent e){} public void insertUpdate(DocumentEvent e) { updateSlider(); } public void removeUpdate(DocumentEvent e) { updateSlider(); } private void updateSlider() { int val = 0; try { val = Integer.parseInt(textField.getText()); } catch (NumberFormatException e) { //fix if you wish } slider.setValue(val); } public void propertyChange(PropertyChangeEvent e) { if (textField.equals(e.getPropertyName())) { Number value = (Number)e.getNewValue(); if (slider != null && value != null) { slider.setValue(value.intValue()); } } } public void addSlider(JSlider s, String description) { s.addChangeListener(listener); JPanel panel = new JPanel(); panel.add(s); panel.add(new JLabel(description)); sliderPanel.add(panel); } public void setValue(int val) { value = val; } public int getValue() { return value; } }//close SliderBeanFrame
|
 |
Ernest Friedman-Hill
author and iconoclast
Marshal
Joined: Jul 08, 2003
Posts: 24045
|
|
You've shown me two classes here, BlueSliderBean and BlueSliderBeanFrame. BlueSliderBean only has a main() routine. All the other methods are in BlueSliderBeanFrame; so in your original code snippet showing the error, the compiler is absolutely right to say there's no blue.getValue(). P.S. Please use those UBB "Code" tags!
|
 |
Candy Bortniker
Ranch Hand
Joined: Mar 17, 2003
Posts: 123
|
|
Ok, I have taken out the class that had the main and change the BlueSliderBeanFrame to BlueSliderBean but I still get the same error. Any more suggestions?
|
 |
Candy Bortniker
Ranch Hand
Joined: Mar 17, 2003
Posts: 123
|
|
I have that part of the bean working. Thanks for your help. Can you help with this problem? The slider that I made in the bean doesn't show on the text program. Here is the code for the test:
|
 |
 |
|
|
subject: using a bean
|
|
|