Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Nov 14th, 2004, 12:39 PM   #1
T3FLoN
Newbie
 
Join Date: Nov 2004
Posts: 21
Rep Power: 0 T3FLoN is on a distinguished road
Hi guyz im relatively new to the java seen but i kno the basics...well im making my self a telephone interface got my keypad and display field to interact with eachother.
Also ive implemented a JSlider into the mix.

Well my problem is that i cant get my slider to adjust my JLabel witch is called ("Volume:"+changeVar) changeVar ranges from 0 to 100 and changes in realtime as the slider is moved. Thats my goal.

Ive looked on many sites but most of them have a bunch of unneeded code and use a textField and not a label.

Was hopeing to find a simplified example to use on my program.
Any input is appreciated. TX in advance.
:banana:
__________________
<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
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
Old Nov 15th, 2004, 3:12 AM   #3
drunkenCoder
Newbie
 
drunkenCoder's Avatar
 
Join Date: Nov 2004
Posts: 8
Rep Power: 0 drunkenCoder is on a distinguished road
Quote:

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);
}
}
});
You have to update the JLabel text yourself inside of the if statement in the ChangeListener.
like this:
volLabel.setText("Volume:"+value);
drunkenCoder is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 11:52 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC