title: Trouble with getting Path2D.Double to change with .transform
body: <p>My program is supposed to allow users to input the first six numbers of a matrix into text fields and then hit an apply button, changing the Path2D using the .transform method with the arguments being the six inputted numbers. My problem is that whenever I type something in and hit apply, the transformation is extremely different than it should be and the original arrow remains behind as well.</p>
  
  <p>It's really bizarre and I have no clue where the problem is coming from. Everything should be in the right spot with the Affine Transform, but the transformation is coming out all wrong.</p>
  
  <p>This is what it should look like:
  <a href="https://i.stack.imgur.com/vJqEd.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/vJqEd.png" alt="enter image description here"></a></p>
  
  <p>This is what it looks like for me:
  <a href="https://i.stack.imgur.com/T65AB.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/T65AB.png" alt="enter image description here"></a></p>
  
  <p>I will put the full code below so you can run it yourself to see if you might be able to figure it out. Thank you!</p>
  
  <pre><code>import javax.swing.*;
  import java.awt.*;
  import java.awt.event.*;
  import java.awt.geom.AffineTransform;
  import java.awt.geom.GeneralPath;
  import java.awt.geom.Path2D;
  import javax.swing.event.*;
  
  public class Project3 extends JPanel implements ActionListener {
  
      public static Project3 p = new Project3();
      Path2D.Double arrow = new Path2D.Double();
      public static JTextField
              num1 = new JTextField("1"), num2 = new JTextField("0"),
              num3 = new JTextField("0"), num4 = new JTextField("0"),
              num5 = new JTextField("1"), num6 = new JTextField("0");
  
      public Project3() {
          setBackground(Color.WHITE);
      }
  
      public Path2D.Double drawArrow() {
          arrow.setWindingRule(GeneralPath.WIND_EVEN_ODD);
          arrow.moveTo(0, 0);
          arrow.lineTo(0, -100); 
          arrow.moveTo(0, -200);
          arrow.lineTo(100, -100);
          arrow.lineTo(50, -100);
          arrow.lineTo(50, 100);
          arrow.quadTo(0, 0, -50, 100);
          arrow.lineTo(-50, -100);
          arrow.lineTo(-100, -100);
          arrow.lineTo(0, -200);
          arrow.closePath();
          return arrow;
      }
  
      @Override
      public void paintComponent(Graphics g) {
          super.paintComponent(g);
          Graphics2D g2 = (Graphics2D) g;
          g2.translate(250, 250);
          GradientPaint gradient = new GradientPaint(0, 0, Color.LIGHT_GRAY, 15, 15, Color.BLACK, true);
          g2.setPaint(gradient);
          g2.setStroke(new BasicStroke(12, BasicStroke.CAP_ROUND, BasicStroke.JOIN_MITER));
          g2.draw(drawArrow());
      }
  
      public static void main(String[] args) {
          JFrame frame = new JFrame("Project 3");
          frame.setSize(500, 600);
          frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  
          Container cp = frame.getContentPane();
          cp.setLayout(new BorderLayout());
  
          JPanel panel = new JPanel();
          panel.setLayout(new BorderLayout());
          cp.add(panel, BorderLayout.CENTER);
          panel.add(p, BorderLayout.CENTER);
          panel = new JPanel();
          panel.setLayout(new GridLayout(0, 2));
          cp.add(panel, BorderLayout.SOUTH);
  
          JPanel textPanel = new JPanel();
          textPanel.setLayout(new GridLayout(2, 3));
          panel.add(textPanel);
          textPanel.add(num1);
          textPanel.add(num2);
          textPanel.add(num3);
          textPanel.add(num4);
          textPanel.add(num5);
          textPanel.add(num6);
  
          JPanel btPanel = new JPanel();
          btPanel.setLayout(new GridLayout(0, 1));
          panel.add(btPanel);
          JButton apply = new JButton("Apply");
          apply.addActionListener(p);
          btPanel.add(apply);
          JButton reset = new JButton("Reset");
          reset.addActionListener(p);
          btPanel.add(reset);
  
          frame.setVisible(true);
  
      }
  
      @Override
      public void actionPerformed(ActionEvent e) {
          String command = e.getActionCommand();
          switch (command) {
              case "Apply":
                  double args1 = Double.parseDouble(num1.getText());
                  double args2 = Double.parseDouble(num2.getText());
                  double args3 = Double.parseDouble(num3.getText());
                  double args4 = Double.parseDouble(num4.getText());
                  double args5 = Double.parseDouble(num5.getText());
                  double args6 = Double.parseDouble(num6.getText());          
                  arrow.transform(new AffineTransform(args1, args2, args3, args4, args5, args6));
                  repaint();
                  break;
              case "Reset":
                  arrow.transform(new AffineTransform(1, 0, 0, 0, 1, 0));
                  repaint();
                  break;
          }
      }
  
  }
  </code></pre>