-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain3.java
More file actions
119 lines (103 loc) · 3.45 KB
/
Copy pathMain3.java
File metadata and controls
119 lines (103 loc) · 3.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
package hackathon1;
import java.awt.Color;
import java.awt.Component;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.Random;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextArea;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.ValueAxis;
import org.jfree.chart.plot.XYPlot;
import org.jfree.data.time.Millisecond;
import org.jfree.data.time.TimeSeries;
import org.jfree.data.time.TimeSeriesCollection;
import com.mysql.jdbc.ResultSetImpl;
public class Main3 {
//@SuppressWarnings("deprecation")
static TimeSeries ts = new TimeSeries("data", Millisecond.class);
public static void main(String[] args) throws InterruptedException
{
}
public Main3()
{
gen myGen = new gen();
new Thread(myGen).start();
TimeSeriesCollection dataset = new TimeSeriesCollection(ts);
JFreeChart chart = ChartFactory.createTimeSeriesChart(
"Body Motion",
"Time",
"Rate",
dataset,
true,
true,
false
);
final XYPlot plot = chart.getXYPlot();
ValueAxis axis = plot.getDomainAxis();
axis.setAutoRange(true);
axis.setFixedAutoRange(60000.0);
JFrame f = new JFrame("Body motion");
//f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
ChartPanel label = new ChartPanel(chart);
f.getContentPane().add(label);
//Suppose I add combo boxes and buttons here later
f.pack();
f.setVisible(true);
}
static class gen implements Runnable
{
// private Random randGen = new Random();
public void run() {
int time = 1;
int num = 0;
while(true)
{
//System.out.println(num); //12
int value=time;
Connection con = null;
String url = "jdbc:mysql://localhost:3306/";
String db = "hackathon";
String driver = "com.mysql.jdbc.Driver";
String user = "root";
String pass = "root";
try{
Class.forName(driver);
con = DriverManager.getConnection(url+db, user, pass);
PreparedStatement st=con.prepareStatement("select * from motion where time=?");
st.setLong(1,value);
ResultSet res=st.executeQuery();
res.next();
//num.setText(Integer.toString(res.getInt(1)));
num =res.getInt(2);
System.out.println(num);
System.out.println(time);
con.close();
}
catch(Exception e)
{
Component p2 = null;
//JOptionPane.showMessageDialog(p2,"Error");
}
ts.addOrUpdate(new Millisecond(), num);
++time;
try
{
Thread.sleep(200);
} catch (InterruptedException ex)
{
System.out.println(ex);
}
}
}
}
}