![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: Nov 2004
Posts: 21
Rep Power: 0
![]() |
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> |
|
|
|
|
|
#2 |
|
Newbie
Join Date: Nov 2004
Posts: 21
Rep Power: 0
![]() |
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> |
|
|
|
|
|
#3 | |
|
Newbie
Join Date: Nov 2004
Posts: 8
Rep Power: 0
![]() |
Quote:
like this: volLabel.setText("Volume:"+value); |
|
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|