diff --git a/Aufgabe4/Ast.java b/Aufgabe4/Ast.java index 672355e5269cb3edf902756f04df43533e8f2983..93ecf5b5eaafc9c6c3b791904a95893291f53570 100644 --- a/Aufgabe4/Ast.java +++ b/Aufgabe4/Ast.java @@ -6,7 +6,6 @@ public abstract class Ast { } - } class AstExpression extends Ast { diff --git a/Aufgabe4/Plotter.java b/Aufgabe4/Plotter.java index eb6518b1332fe463bff3c1f1b756087746748a4c..6e61b22b00238e7ea168f1894eb7c7dbbda73dfa 100644 --- a/Aufgabe4/Plotter.java +++ b/Aufgabe4/Plotter.java @@ -2,9 +2,7 @@ import javax.swing.SwingUtilities; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.BorderFactory; -import java.awt.Color; -import java.awt.Dimension; -import java.awt.Graphics; +import java.awt.*; import java.awt.event.MouseEvent; import java.awt.event.MouseAdapter; import java.awt.geom.Line2D; @@ -41,10 +39,19 @@ public class Plotter { class PlotterPanel extends JPanel { + 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}; - final int ZERO_POINT_X = 400; - final int ZERO_POINT_Y = 300; + + + + final int ZERO_POINT_X = 300; + final int ZERO_POINT_Y = 400; ValuesToDraw valuesToDraw; @@ -56,38 +63,52 @@ class PlotterPanel extends JPanel { addMouseListener(new MouseAdapter() { public void mousePressed(MouseEvent e) { - drawNextLine(); - } - }); + System.out.println("maus gedrückt"); + + + int[] xCordsWithOffset = new int[41]; + int[] yCordsWithOffset = new int[41]; - } - private void drawNextLine() { + int i = 0; - int[] xCords = valuesToDraw.getXCords(); - int[] yCords = valuesToDraw.getYCords(); + int[] xCords = valuesToDraw.getXCords(); - System.out.println(Arrays.toString(xCords)); + for(int cord : xCords) { - int[] xCordsFromZeroPoint = new int[41]; - int[] yCordsFromZeroPoint = new int[41]; + xCordsWithOffset[i] = (ZERO_POINT_X + (cord * -1 * 10)); + i++; + } + System.out.println(Arrays.toString(xCordsWithOffset)); - for(int i = 0; i < 41; i++) { - xCordsFromZeroPoint[i] = xCords[i] + ZERO_POINT_X; - } + int j = 0; - for(int i = 0; i < 41; i++) { - yCordsFromZeroPoint[i] = yCords[i] + ZERO_POINT_Y; - } + int[] yCords = valuesToDraw.getYCords(); - Graphics g = new Graphics() + for(int cord : yCords) { + System.out.print("cords=" + cord); + yCordsWithOffset[j] = ZERO_POINT_Y + (cord * 10); + j++; + } + + System.out.println(Arrays.toString(yCordsWithOffset)); + + + test2 = xCordsWithOffset; + test = yCordsWithOffset; + + + + updateUI(); + } + }); - g.drawPolyline(xCordsFromZeroPoint, yCordsFromZeroPoint, 21); } + public Dimension getPreferredSize() { return new Dimension(800,600); } @@ -99,18 +120,35 @@ class PlotterPanel extends JPanel { 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); + //x=0, y=20 + g.drawLine(375, 100, 425, 100); + //x=0, y=-20 + g.drawLine(375, 500, 425, 500); + //x=-20, y=0 + g.drawLine(200,275 , 200, 325); + //x=20, y=0 + g.drawLine(600,275 , 600, 325); + + drawPoints(g); + + + } + + + private void drawPoints(Graphics g){ + + + + Graphics2D g2d = (Graphics2D) g; + + g2d.drawPolyline(test, test2, 41); + } + } diff --git a/Aufgabe4/SwingPaintDemo3.java b/Aufgabe4/SwingPaintDemo3.java deleted file mode 100644 index 6df66efc8dec867574aa28710495931a9f653f1a..0000000000000000000000000000000000000000 --- a/Aufgabe4/SwingPaintDemo3.java +++ /dev/null @@ -1,114 +0,0 @@ -/* - * Copyright (c) 1995, 2008, Oracle and/or its affiliates. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * - Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * - Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * - Neither the name of Oracle or the names of its - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS - * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, - * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - - -import javax.swing.SwingUtilities; -import javax.swing.JFrame; -import javax.swing.JPanel; -import javax.swing.BorderFactory; -import java.awt.Color; -import java.awt.Dimension; -import java.awt.Graphics; -import java.awt.event.MouseEvent; -import java.awt.event.MouseAdapter; - -public class SwingPaintDemo3 { - - public static void main(String[] args) { - SwingUtilities.invokeLater(new Runnable() { - public void run() { - createAndShowGUI(); - } - }); - } - - private static void createAndShowGUI() { - System.out.println("Created GUI on EDT? "+ - SwingUtilities.isEventDispatchThread()); - JFrame f = new JFrame("Swing Paint Demo"); - f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); - f.add(new MyPanel()); - f.pack(); - f.setVisible(true); - } -} - -class MyPanel extends JPanel { - - private int squareX = 50; - private int squareY = 50; - private int squareW = 20; - private int squareH = 20; - - public MyPanel() { - - setBorder(BorderFactory.createLineBorder(Color.black)); - - addMouseListener(new MouseAdapter() { - public void mousePressed(MouseEvent e) { - moveSquare(e.getX(),e.getY()); - } - }); - - addMouseMotionListener(new MouseAdapter() { - public void mouseDragged(MouseEvent e) { - moveSquare(e.getX(),e.getY()); - } - }); - - } - - private void moveSquare(int x, int y) { - int OFFSET = 1; - if ((squareX!=x) || (squareY!=y)) { - repaint(squareX,squareY,squareW+OFFSET,squareH+OFFSET); - squareX=x; - squareY=y; - repaint(squareX,squareY,squareW+OFFSET,squareH+OFFSET); - } - } - - - public Dimension getPreferredSize() { - return new Dimension(250,200); - } - - protected void paintComponent(Graphics g) { - super.paintComponent(g); - g.drawString("This is my custom Panel!",10,20); - g.setColor(Color.RED); - g.fillRect(squareX,squareY,squareW,squareH); - g.setColor(Color.BLACK); - g.drawRect(squareX,squareY,squareW,squareH); - } - - -} diff --git a/Aufgabe4/ValuesToDraw.java b/Aufgabe4/ValuesToDraw.java index ace35f7f0295992bf29f52859189312e16869a3f..4b8b062d7c8b53722f294dc9dc3cba29b404e137 100644 --- a/Aufgabe4/ValuesToDraw.java +++ b/Aufgabe4/ValuesToDraw.java @@ -13,16 +13,21 @@ public class ValuesToDraw { public int[] getXCords() { + if(i > xCordArrays.size() - 1) + i = 0; + return xCordArrays.get(i++); } public int[] getYCords () { - return new int[]{-20, -19, -18, -17, -16, -15, -14, -13, -12, -11, -10, + int[] yCords = 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}; + return yCords; + } } diff --git a/Aufgabe4/expressions.txt b/Aufgabe4/expressions.txt index 4853f59b3bfe953cd141589fdf7ca4309b90025f..5c449bfc2f753afeab88e0536675f52339348df9 100644 --- a/Aufgabe4/expressions.txt +++ b/Aufgabe4/expressions.txt @@ -1,7 +1,8 @@ -3+3+x +x +x^2 +4+3+x (3^2)-5 1+2+3+4+5 -(22*2)-5 -5+5+55 1+x -x+2 \ No newline at end of file +x+2 +x^10 \ No newline at end of file diff --git a/Aufgabe4/main.java b/Aufgabe4/main.java index b56a7caa05e60b2dd5f07ef1980a3f3c715c2af2..dd2853fc03c5d1b02783a6e80ef21d7a9bedada9 100644 --- a/Aufgabe4/main.java +++ b/Aufgabe4/main.java @@ -9,10 +9,6 @@ public class main { - - - - // values above integer space will produce errors ArrayList<String> stringsFromFile = new ArrayList<>(); @@ -87,10 +83,8 @@ public class main { ValuesToDraw valuesToDraw = new ValuesToDraw(arraysOfXValues); - Plotter.plot(valuesToDraw); - + Plotter.plot(valuesToDraw); - //printAst(result); }