Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8655477
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T15:02:24+00:00 2026-06-12T15:02:24+00:00

I edited a JFreeChart real time graph and now I get this error when

  • 0

I edited a JFreeChart real time graph and now I get this error when I try to run it. When I run it, the GUI will pop up its just the graph doesn’t have the random data stream in.
Any ideas would be a great help.

public class Therm extends ApplicationFrame implements ActionListener{

private static TimeSeries ts;
JTextArea text = new JTextArea("25");
JTextArea degreeC = new JTextArea("degrees C");
JTextArea degreeF = new JTextArea("degrees F");


public Therm(final String title){
super(title);


ts = new TimeSeries("Data", Millisecond.class);
TimeSeriesCollection data = new TimeSeriesCollection(ts);

JFreeChart chart = create(data);
JFrame frame = new JFrame("GraphTest");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
ChartPanel label = new ChartPanel(chart);
frame.getContentPane().add(label);  


ChartPanel chartPanel = new ChartPanel(chart);
JButton buttonC = new JButton("Celsius");
JButton buttonF = new JButton("Farenheit");
JButton button1 = new JButton("Toggle Extension (60 and 300 seconds)");
JButton buttonOff = new JButton("Turn Box");
buttonC.setActionCommand("C");
buttonC.addActionListener(this);
buttonF.setActionCommand("F");
buttonF.addActionListener(this);
button1.setActionCommand("ADD");
button1.addActionListener(this);
buttonOff.setActionCommand("off");
buttonOff.addActionListener(this);



Font font = new Font ("Verdana", Font.BOLD, 26);
text.setFont(font);
degreeC.setFont(font);
degreeF.setFont(font);


JPanel graph = new JPanel(new BorderLayout());
graph.add(chartPanel);
chartPanel.setPreferredSize(new java.awt.Dimension(700,300));
setContentPane(graph);


JPanel content = new JPanel(new GridLayout(3,2));
content.setLayout(new GridLayout(3,2));
content.add(text);
content.add(degreeC);
content.add(buttonC);
content.add(buttonF);
content.add(button1);
content.add(buttonOff);
add(content,BorderLayout.SOUTH);
chartPanel.setPreferredSize(new java.awt.Dimension(700,300));

} 

private JFreeChart create(final XYDataset data){
    JFreeChart chart = ChartFactory.createTimeSeriesChart(
        "Thermometer Reading",
        "Time",
        "Degrees",
        data,
        true,
        true,
        false
    );

    final XYPlot plot = chart.getXYPlot();
    ValueAxis axisy = plot.getDomainAxis();
    axisy.setFixedAutoRange(60000.0);
    axisy = plot.getRangeAxis();
    axisy.setRange(10.0,50.0);
    return chart;
    }



public void actionPerformed(final ActionEvent e) {
    if (e.getActionCommand().equals("C")) {  
        degreeC.setText("degrees C");
    }
    if (e.getActionCommand().equals("F")){
        degreeC.setText("degrees F");
    }
    if (e.getActionCommand().equals("off")){

    }
}


public static void main(String[] args) throws IOException{
    gen myGen = new gen();
    new Thread(myGen).start();



    final Therm prog = new Therm("Thermometer Graph");
    prog.pack();
    prog.setVisible(true);
}



static class gen implements Runnable{
    public void run() {
        while(true) {
            int num = 25 + (int)(Math.random() * ((40 - 30) + 1));
            System.out.println(num);
            ts.addOrUpdate(new Millisecond(), num);
            System.out.println("HI");
            try {
                Thread.sleep(20);
            }
            catch (InterruptedException ex) {
                System.out.println(ex);
            }

        }
    }
}
}

EDIT: here is the new code that receives the error “”syntax error, insert “Classbody” to complete Class Declaration”” at ‘gen’

static class gen{
    while(true) {
        // don't forget to make num final!
        final int num = 25 + (int)(Math.random() * ((40 - 30) + 1));
        System.out.println(num);
        SwingUtilities.invokeLater(new Runnable(){
          public void run() {
            ts.addOrUpdate(new Millisecond(), num);                
          }
        });
        // ts.addOrUpdate(new Millisecond(), num);
        System.out.println("HI");
        try {
            Thread.sleep(20);
        }
        catch (InterruptedException ex) {
            System.out.println(ex);
        }
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T15:02:26+00:00Added an answer on June 12, 2026 at 3:02 pm

    The TimeSeries is a Swing GUI model and probably should only be updated on the Swing event thread.

    What happens if you add the update to the event queue like so:

        while(true) {
            // don't forget to make num final!
            final int num = 25 + (int)(Math.random() * ((40 - 30) + 1));
            System.out.println(num);
            SwingUtilities.invokeLater(new Runnable(){
              public void run() {
                ts.addOrUpdate(new Millisecond(), num);                
              }
            });
            // ts.addOrUpdate(new Millisecond(), num);
            System.out.println("HI");
            try {
                Thread.sleep(20);
            }
            catch (InterruptedException ex) {
                System.out.println(ex);
            }
        }
    

    If this doesn’t help, please print the entire stacktrace of your exception and indicate any lines in your class that the stacktrace refers to.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Edited:- Updated One What's wrong with this code. Now I am getting error on
Edited Now my code is like this: #!/usr/bin/perl # import packages use Net::POP3; use
Edited with the entire code: line 17 is now 33. I ran this code
Edited at the request of commenters. I hope this is compliant. First post! Trying
Edited: I want to get the actual with of the document with JS. I
Edited Question: This should be clear. using System; namespace UpdateDateTimeFields { class Program {
Edited: SOLUTION FOUND. This is strange and not the best solution, but I just
EDITED to show real example How can I call a generic function from a
edited: This is what i need: sendpost = function(a,b,c){ return jQuery.post('inc/operations.php', {a:b}, c, json);
EDITED I m using this select query with left join: $updaterbk = SELECT j1.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.