Thread: Jslider Help
View Single Post
Old Nov 14th, 2004, 1:12 PM   #2
T3FLoN
Newbie
 
Join Date: Nov 2004
Posts: 21
Rep Power: 0 T3FLoN is on a distinguished road
just a little update on my progress.
i got my change listener working i added a System println to see if the value is changing, and yes it is but....

for some reason its not changing the value in my label.
Heres my code to maybe help you out on a suggestion.
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import javax.swing.event.*;

class Telephone extends JFrame
        implements ActionListener{
              //ChangeListener{

	private JTextField numBox;// keypad's text field
	private JSlider volume;// slider
	private JLabel low;//belongs to volume slider
	private JLabel high;//belongs to volume slider
	private JLabel volLabel;//belongs to volme slider
	private JTextField volField;//slider's text field

//variable to be stored for JSlider number position
	private static int value;

//button declerations
	private JButton b1;
	private JButton b2;
	private JButton b3;
	private JButton b4;
	private JButton b5;
	private JButton b6;
	private JButton b7;
	private JButton b8;
	private JButton b9;
	private JButton b10;
	private JButton b11;
	private JButton b12;
	private JButton bclr;

//fonts to be used
	Font buttonFont = new Font("Arial",Font.BOLD,32);
	Font textFieldFont = new Font("Arial",Font.BOLD,20);

	private Container c;//declaring container

	public static void main(String args[]){
 Telephone myPhone = new Telephone();
	}

	public Telephone(){

	//my JFrame's properties
 this.setBounds(100,80,630,350);
 this.setResizable(false);
 this.setTitle("Telephone");

  // textfield used by the keypad
 numBox = new JTextField();
 numBox.setBounds(50,52,260,40);
 numBox.setFont(textFieldFont);
 numBox.setBackground(Color.orange);

  // my slider aka volume bar also its components
// ChangeListener volumeListener = new volumeListener();
 volume = new JSlider();
 volume.setBounds(50,230,260,30);
 volume.setBackground(Color.orange);
// volume.addChangeListener(this);

    volume.addChangeListener(new ChangeListener() {
    // This method is called whenever the slider's value is changed
      public void stateChanged(ChangeEvent evt) {
         JSlider volume = (JSlider)evt.getSource();

        if (!volume.getValueIsAdjusting()) {
        // Get new value
          value = volume.getValue();
          System.out.println(value);
        }
      }
    });

 low = new JLabel("Low");
 low.setBounds(50,210,40,20);

 high = new JLabel("High");
 high.setSize(40,20);
 high.setLocation(290,210);

 volLabel = new JLabel("Volume:"+value);
 volLabel.setBounds(125,260,55,20);

// volField = new JTextField();
// volField.setBounds(190,260,30,20);
// volField.setBackground(Color.orange);
	// end of slider components
__________________
<span style='font-family:Courier'><span style='font-size:12pt;line-height:100%'><span style='color:orange'>☼☼☼ Just kill em all, and let God sort em out. ☼☼☼</span></span></span>
T3FLoN is offline   Reply With Quote