0

i have tried to add a slider,i need to pass the value to another window when i press the button,but am not getting the button on the window am new to swing and cant identify the error

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JSlider;

public class Sliding extends JFrame{  

public Sliding() {  

JSlider slider = new JSlider(JSlider.HORIZONTAL, 0, 50, 25);  
slider.setMinorTickSpacing(2);  
slider.setMajorTickSpacing(10);  

JButton b=new JButton("click"); 
b.setBounds(100,150,80,30);
add(b);
setVisible(true);

slider.setPaintTicks(true);  
slider.setPaintLabels(true);  

JPanel panel=new JPanel();  
panel.add(slider);  
add(panel);  
}  

public static void main(String s[]) {  
Sliding frame=new Sliding();  
frame.pack();  
frame.setVisible(true);  

}  
}  
Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
halfe
  • 85
  • 1
  • 2
  • 9
  • Start with finding out what layout manager is used by default in a frame.. I'm almost sure this is a duplicate. Give me a minute. In the meantime, see [The Use of Multiple JFrames, Good/Bad Practice?](http://stackoverflow.com/q/9554636/418556) (not directly about the question, just good advice). – Andrew Thompson Feb 06 '16 at 07:22

1 Answers1

1

replace add(b); with add(b,BorderLayout.SOUTH);

sami zahwan
  • 147
  • 4
  • how to fetch the value from the slider on button click – halfe Feb 06 '16 at 07:35
  • b.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { System.out.println(slider.getValue()); } }); – sami zahwan Feb 06 '16 at 07:44