ADDING AN OBJECT INTO A JPANEL!
i want to add a Jslider into a panel(year_panel) and then add that year_panel into the GridWindow.
I have tried various ways but all in vain.Could somebody help me to put the Slider in the panel and the panel into the main Grid!
thanks a lot.
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.*;
import java.text.SimpleDateFormat;
public class Grid extends JFrame /*implements ActionListener*/
{
static final int FPS_INIT = 15;//initial frames per second
int frameNumber = 0;
int delay;
//Timer timer;
boolean frozen = false;
private JPanel date_panel,year_panel, month_panel,day_panel;
private String time=new String("");
private Date date=new Date();
//private Jslider framesPerSecond ;
public Grid() {
time=time + new Date().toString();
SimpleDateFormat formatter = new SimpleDateFormat("E, MMMM d, yyyy") ;
time = formatter.format(date) ;
date_panel=new JPanel();
year_panel=new JPanel();
month_panel=new JPanel();
day_panel=new JPanel();
date_panel.setLayout(new FlowLayout());
date_panel.add(new JLabel(time));
year_panel.setLayout(new FlowLayout());
/*these two lines*/
year_panel.add(new JLabel(framesPerSecond));
//year_panel.add(framesPerSecond);
month_panel.setLayout(new FlowLayout());
day_panel.setLayout(new FlowLayout());
JSlider framesPerSecond = new JSlider(JSlider.HORIZONTAL,
0, 31, FPS_INIT);
//framesPerSecond.addChangeListener(new SliderListener());
//Turn on labels at major tick marks.
framesPerSecond.setMajorTickSpacing(10);
framesPerSecond.setMinorTickSpacing(1);
framesPerSecond.setPaintTicks(true);
framesPerSecond.setPaintLabels(true);
framesPerSecond.setBorder(
BorderFactory.createEmptyBorder(0,0,10,0));
//Create the label for the animation.
//picture = new JLabel(new ImageIcon("images/doggy/T"
//+ frameNumber
//+ ".gif"),
// JLabel.CENTER);
Container contentPane = getContentPane();
contentPane.setLayout(new GridLayout(1,4));
contentPane.add(date_panel);
contentPane.add(year_panel);
//contentPane.add(framesPerSecond);
//contentPane.add(year_panel);
//contentPane.add(month_panel);
//contentPane.add(day_panel);
}
public static void main(String args[]) {
Grid gw = new Grid();
gw.setTitle("Date Slider");
gw.setSize(400,200);
gw.setVisible(true);
}
}

