Hi
I have been coding Java for a couple of days, having come from a C background.
I have an application that displays a JFrame with a JFreeChart object held in the centre and three buttons in the south layout.
I have registered action listeners to the button, and the idea is to re draw the graph with a moving average series.
I can see my callback, but am unable to redraw the chart. What do I need to do to get the frame to redraw?
thanks
elliot
Code:public void graphData() {
String[] chartInfo = { "Gold Price USD", "Date /(Yr/)", "Price /(USD/)" };
JButton monthBtn = new JButton("M");
JButton sixMBtn = new JButton("6M");
JButton yearBtn = new JButton("1Y");
final TimeSeriesChart tsc = new TimeSeriesChart("Gold Price (USD)", "Date (Yr)", "Price (USD)");
final int[] yIntArr = new int[ySeries.length];
for (int i = 0; i < ySeries.length; i++) {
yIntArr[i] = (int) ySeries[i];
}
final JFrame graphFrame = new JFrame();
BorderLayout bl = new BorderLayout();
graphFrame.setLayout(bl);
graphFrame.add(tsc.createPanel(xSeries, yIntArr, "null"), BorderLayout.CENTER);
JPanel southPanel = new JPanel();
monthBtn.addActionListener(new ActionListener (){
public void actionPerformed(ActionEvent e){
graphFrame.add(tsc.createPanel(xSeries, yIntArr, "month"), BorderLayout.CENTER);
graphFrame.repaint();
}
});
sixMBtn.addActionListener( new ActionListener (){
public void actionPerformed(ActionEvent e){
graphFrame.add(tsc.createPanel(xSeries, yIntArr, "sixmonth"), BorderLayout.CENTER);
graphFrame.repaint();
}
});
yearBtn.addActionListener( new ActionListener (){
public void actionPerformed(ActionEvent e){
graphFrame.add(tsc.createPanel(xSeries, yIntArr, "year"), BorderLayout.CENTER);
graphFrame.repaint();
System.out.println("here.......");
}
});
southPanel.add(monthBtn);
southPanel.add(sixMBtn);
southPanel.add(yearBtn);
graphFrame.add(southPanel, BorderLayout.SOUTH);
graphFrame.setVisible(true);
graphFrame.pack();
}

