Skip to content
Snippets Groups Projects
Commit 819ce512 authored by niklasBr's avatar niklasBr
Browse files

Added mouseClick event

parent 9f040197
No related branches found
No related tags found
No related merge requests found
...@@ -40,28 +40,29 @@ public class Plotter { ...@@ -40,28 +40,29 @@ public class Plotter {
class PlotterPanel extends JPanel { class PlotterPanel extends JPanel {
final int ZERO_POINT_X = 400; final int ZERO_POINT_X = 400;
final int ZERO_POINT_Y = 300; final int ZERO_POINT_Y = 300;
ValuesToDraw valuesToDraw; ValuesToDraw valuesToDraw;
PlotterPanel(ValuesToDraw valuesToDraw) { PlotterPanel(ValuesToDraw valuesToDraw) {
this.valuesToDraw = valuesToDraw; this.valuesToDraw = valuesToDraw;
}
public Dimension getPreferredSize() { addMouseListener(new MouseAdapter() {
return new Dimension(800,600); public void mousePressed(MouseEvent e) {
} drawNextLine();
}
protected void paintComponent(Graphics g) { });
super.paintComponent(g);
g.drawLine(400, 0, 400, 600); }
g.drawLine(0, 300, 800, 300);
private void drawNextLine() {
int[] xCords = valuesToDraw.getXCords(); int[] xCords = valuesToDraw.getXCords();
int[] yCords = valuesToDraw.getYCords(); int[] yCords = valuesToDraw.getYCords();
...@@ -80,10 +81,32 @@ class PlotterPanel extends JPanel { ...@@ -80,10 +81,32 @@ class PlotterPanel extends JPanel {
yCordsFromZeroPoint[i] = yCords[i] + ZERO_POINT_Y; yCordsFromZeroPoint[i] = yCords[i] + ZERO_POINT_Y;
} }
Graphics g = new Graphics()
g.drawPolyline(xCordsFromZeroPoint, yCordsFromZeroPoint, 21); g.drawPolyline(xCordsFromZeroPoint, yCordsFromZeroPoint, 21);
}
public Dimension getPreferredSize() {
return new Dimension(800,600);
}
protected void paintComponent(Graphics g) {
super.paintComponent(g);
g.drawLine(400, 0, 400, 600);
g.drawLine(0, 300, 800, 300);
int[] test = new int[]{-20, -19, -18, -17, -16, -15, -14, -13, -12, -11, -10,
-9, -8, -7, -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20};
int[] test2 = new int[]{-20, -19, -18, -17, -16, -15, -14, -13, -12, -11, -10,
-9, -8, -7, -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20};
g.drawPolyline(test, test2, 21);
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment