Advertisement
Guest User

Untitled

a guest
Apr 1st, 2015
220
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.49 KB | None | 0 0
  1. public ReplayData replayData;
  2.  
  3. frame = new JFrame();
  4. frame.setBounds(100, 100, 1920, 1080);
  5. frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  6. frame.getContentPane().setLayout(null);
  7.  
  8. // ERROR HERE WHEN ADDING TO FRAME, APPLICATION RUNS FINE IF COMMENTED
  9. //frame.add(replayData); // Add replay data to jframe
  10.  
  11. JButton button_KMeans = new JButton("View K-Means");
  12. button_KMeans.addActionListener(new ActionListener() {
  13. public void actionPerformed(ActionEvent arg0) {
  14. kMeans.initialize();
  15. kMeans.kMeanCluster();
  16. kMeans.PrintResults();
  17.  
  18. //for (Point p : kMeans.getPoints() )
  19.  
  20. Point temp = new Point();
  21. for (int i = 0; i < kMeans.TOTAL_DATA; i++)
  22. {
  23. //JOptionPane.showMessageDialog(new JFrame(),kMeans.TOTAL_DATA, "Dialog",
  24. // JOptionPane.ERROR_MESSAGE);;
  25. p.setX((int)TrackerData.getRecordNumber(i).getEyeX());
  26. p.setY((int)TrackerData.getRecordNumber(i).getEyeY());
  27.  
  28. JOptionPane.showMessageDialog(new JFrame(),p.getX(), "Dialog",
  29. JOptionPane.ERROR_MESSAGE);
  30. JOptionPane.showMessageDialog(new JFrame(),p.getY(), "Dialog",
  31. JOptionPane.ERROR_MESSAGE);
  32.  
  33. // GET ERROR HERE when adding these points to replayData. everything look fine in that class unless i'm missing something
  34. // java.lang.NullPointerException at MainWindow$3.actionPerformed(MainWindow.java:189)
  35. replayData.addPoint(p); // Add points to JPanel
  36. }
  37. //replayData.draw();
  38. }
  39. });
  40.  
  41. import java.awt.Graphics;
  42. import java.awt.Point;
  43. import java.util.ArrayList;
  44. import javax.swing.JPanel;
  45.  
  46. public class ReplayData extends JPanel {
  47.  
  48. public ArrayList<DataPoint> points;
  49.  
  50. // Initialise records
  51. public ReplayData()
  52. {
  53. points = new ArrayList<DataPoint>();
  54. }
  55.  
  56. public void ReplaceData() {
  57. points = new ArrayList<DataPoint>();
  58. }
  59.  
  60. public void addPoint(DataPoint point) {
  61. points.add(point);
  62. }
  63.  
  64. @Override
  65. public void paintComponent(Graphics g) {
  66. super.paintComponent(g);
  67.  
  68. for (DataPoint p : points)
  69. g.fillRect(p.x, p.y, 2, 2);
  70. }
  71.  
  72. public void draw() {
  73. repaint();
  74. }
  75.  
  76. public DataPoint(int X, int Y)
  77. {
  78. x = X;
  79. y = Y;
  80. }
  81.  
  82. public int getX() {
  83. return x;
  84. }
  85.  
  86. public void setX(int x) {
  87. this.x = x;
  88. }
  89.  
  90. public int getY() {
  91. return y;
  92. }
  93.  
  94. public void setY(int y) {
  95. this.y = y;
  96. }
  97.  
  98. int x,y;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement