title: Drawing antialiased shapes and rotating them in Java
body: <p><strong>Background</strong></p>
  
  <p>Im total Java newbie, today I started learning it (with <a href="http://thenewboston.org" rel="nofollow noreferrer">thenewboston.org</a>). I already know how to make simple windows/forms/gui, how to draw lines etc.</p>
  
  <p>My goal is to create in Java gauge like this:</p>
  
  <p><img src="https://i.stack.imgur.com/qgoji.png" alt="enter image description here"></p>
  
  <p>This is gauge which I created in .NET C# WPF, and now I want to rewrite this to Java.</p>
  
  <p><strong>Main question</strong>:</p>
  
  <p>How to create triangle or other shape with some transparency and rotate it?</p>
  
  <p>I tried to draw something by using Graphics object like this:</p>
  
  <pre><code>public void paint(Graphics g){
     g.drawLine(0, 0, 100, 100);
  }
  </code></pre>
  
  <p>But I think this is wrong direction, because when I put something on graphics - it just stays there, I can't move or rotate it. </p>
  
  <p>I have to clear whole graphics and draw it again to make kind of "animation", or there is easier way?</p>
  
  <hr>
  
  <p>Edit:
  I already know how to antialias (<a href="https://stackoverflow.com/users/522444/hovercraft-full-of-eels">Hovercraft Full Of Eels</a> already helped me in this - thanks).</p>
  
  <hr>
  
  <p>Edit2:</p>
  
  <p>My code actually looks like this:</p>
  
  <pre><code>import java.awt.BasicStroke;
  import java.awt.Color;
  import java.awt.Dimension;
  import java.awt.Graphics;
  import java.awt.Graphics2D;
  import java.awt.Point;
  import java.awt.RenderingHints;
  import javax.swing.JFrame;
  import javax.swing.JPanel;
  
  public class MainWindow extends JPanel {
  
      private Point p1 = new Point(100, 100);
      private Point p2 = new Point(740, 450);
  
      public MainWindow() {
          this.setPreferredSize(new Dimension(800, 600));
      }
  
      @Override
      protected void paintComponent(Graphics g) {
  
          super.paintComponent(g);
          drawLines(g);
      }
  
      private void drawLines(Graphics g)
      {
          Graphics2D g2d = (Graphics2D) g;
  
          g2d.setColor(Color.DARK_GRAY);
          g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);     
          g2d.setStroke(new BasicStroke(4, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));
  
          g.drawLine(p1.x, p1.y, p2.x, p2.y);
  
      }
  
      private void display() {
          JFrame f = new JFrame("Main Window");
          f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          f.add(this);
          f.pack();
          f.setLocationRelativeTo(null);
          f.setVisible(true);
      }
  
      public static void main(String[] args) {
  
          new MainWindow().display();
      }
  
  }
  </code></pre>