Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public ReplayData replayData;
- frame = new JFrame();
- frame.setBounds(100, 100, 1920, 1080);
- frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- frame.getContentPane().setLayout(null);
- // ERROR HERE WHEN ADDING TO FRAME, APPLICATION RUNS FINE IF COMMENTED
- //frame.add(replayData); // Add replay data to jframe
- JButton button_KMeans = new JButton("View K-Means");
- button_KMeans.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent arg0) {
- kMeans.initialize();
- kMeans.kMeanCluster();
- kMeans.PrintResults();
- //for (Point p : kMeans.getPoints() )
- Point temp = new Point();
- for (int i = 0; i < kMeans.TOTAL_DATA; i++)
- {
- //JOptionPane.showMessageDialog(new JFrame(),kMeans.TOTAL_DATA, "Dialog",
- // JOptionPane.ERROR_MESSAGE);;
- p.setX((int)TrackerData.getRecordNumber(i).getEyeX());
- p.setY((int)TrackerData.getRecordNumber(i).getEyeY());
- JOptionPane.showMessageDialog(new JFrame(),p.getX(), "Dialog",
- JOptionPane.ERROR_MESSAGE);
- JOptionPane.showMessageDialog(new JFrame(),p.getY(), "Dialog",
- JOptionPane.ERROR_MESSAGE);
- // GET ERROR HERE when adding these points to replayData. everything look fine in that class unless i'm missing something
- // java.lang.NullPointerException at MainWindow$3.actionPerformed(MainWindow.java:189)
- replayData.addPoint(p); // Add points to JPanel
- }
- //replayData.draw();
- }
- });
- import java.awt.Graphics;
- import java.awt.Point;
- import java.util.ArrayList;
- import javax.swing.JPanel;
- public class ReplayData extends JPanel {
- public ArrayList<DataPoint> points;
- // Initialise records
- public ReplayData()
- {
- points = new ArrayList<DataPoint>();
- }
- public void ReplaceData() {
- points = new ArrayList<DataPoint>();
- }
- public void addPoint(DataPoint point) {
- points.add(point);
- }
- @Override
- public void paintComponent(Graphics g) {
- super.paintComponent(g);
- for (DataPoint p : points)
- g.fillRect(p.x, p.y, 2, 2);
- }
- public void draw() {
- repaint();
- }
- public DataPoint(int X, int Y)
- {
- x = X;
- y = Y;
- }
- public int getX() {
- return x;
- }
- public void setX(int x) {
- this.x = x;
- }
- public int getY() {
- return y;
- }
- public void setY(int y) {
- this.y = y;
- }
- int x,y;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement