java - Stuck on drawing a set of data points (x,y) -
edited cmilbys suggestion, i'm getting error when adding "replaydata frame.
here replaydata class + paint method
public class replaydata extends jpanel { /** * */ private static final long serialversionuid = 1l; private arraylist<point> points; // create new list of points when ready call redraw() public void replacedata() { points = new arraylist<point>(); } public void addpoint(point point) { points.add(point); } @override public void paintcomponent(graphics g) { super.paintcomponent(g); (point p : points) g.fillrect(p.x, p.y, 2, 2); } public void draw() { repaint(); } } and here try call print of records have been retrieved csv
jbutton button_kmeans = new jbutton("view k-means"); button_kmeans.addactionlistener(new actionlistener() { public void actionperformed(actionevent arg0) { kmeans.initialize(); kmeans.kmeancluster(); //for (point p : kmeans.getpoints() ) // slow? data sets going large point temp = new point(); (int = 0; < kmeans.total_data; i++) { temp.x = (int)trackerdata.getrecordnumber(i).geteyex(); temp.y = (int)trackerdata.getrecordnumber(i).geteyey(); replaydata.addpoint(temp); // add points jpanel } replaydata.draw(); // how make data shows on 5 seconds, or on 30 etc? } }); i'm getting errors when adding instance of replaydata frame
at javax.swing.jframe.addimpl(unknown source)
at java.awt.container.add(unknown source)
private replaydata replaydata; private void initialize() { frame = new jframe(); frame.setbounds(100, 100, 1920, 1080); frame.setdefaultcloseoperation(jframe.exit_on_close); frame.getcontentpane().setlayout(null); frame.add(replaydata); // if comment line program starts fine
in paintcomponent method should call super.paintcomponent. correct uncomment that.
secondly, replaydata class extends jpanel. because of need use jframe's add method , add instance of class jframe. allow have 1 point though. recommend re-structure class have array of points , not 2 integer variables appears be. example
class replaydate extends jpanel { private list<point> points; public replacedata() { points = new arraylist<point>(); } public void addpoint(point point) { points.add(point); } @override public void paintcomponent(graphics g) { super.paintcomponent(g); (point p : points) g.fillrect(point.x, point.y, 2, 2); } public void draw() { repaint(); } } // in main class private replaydata replaydata; private void initialize() { frame = new jframe(); frame.setbounds(100, 100, 1920, 1080); frame.setdefaultcloseoperation(jframe.exit_on_close); frame.getcontentpane().setlayout(null); frame.add(replaydata); // add replay data jframe jbutton button_kmeans = new jbutton("view k-means"); button_kmeans.addactionlistener(new actionlistener() { public void actionperformed(actionevent arg0) { kmeans.initialize(); kmeans.kmeancluster(); (point p : kmeans.getpoints() replaydata.addpoint(p); // add points jpanel replaydata.draw(); } } this allow add number of points , draw them all. hope answered question. if still confused leave comment , try explain little more.
edit: few more problems... first: when setting size of jframe, yours seems work since said nothing it, however, i've never used method. future reference can done this.
jframe.getcontentpane().setpreferredsize(new dimension(width, height)); as when add replaydata instance jframe, i'm not sure one... copied code compiler , worked fine me. post more code or send me project , can take deeper look.
lastly, you're worried speed. how large datasets? depends on computer. computer has 2.4 ghz intel core i5. since 1 hertz '1/second', assuming did math right, , in ideal world 2.4 billion operations per second. isn't actual case point datasets of ~10,000, notice small delay, seconds.
Comments
Post a Comment