title: Drawing a triangle using mouse clicks in java graphics
body: <p>this is my code. It worked for drawing a circle but I am having troubles drawing a triangle now.. A triangle should appear using mouse clicks but it is showing a triangle immediately after running the application. Please help. Thanks.</p>
  
  <pre><code>    package mouse;
  
  import java.awt.*;
  
  import javax.swing.*;
  
  import java.awt.event.ActionEvent;
  import java.awt.event.ActionListener;
  import java.awt.event.MouseEvent;
  import java.awt.event.MouseListener;
  
  import javax.swing.event.*;
  
  import java.awt.geom.*;
  
  public class triangle extends JFrame implements ActionListener, MouseListener {
      int xx[]= {20, 50, 80};
      int yy[]= {80, 30, 80};
  
  
  
      public triangle () {
          setSize(2000,2000);
          addMouseListener(this);
      }
  
      public static void main(String[] args) {
          //TODO code application logic here
          java.awt.EventQueue.invokeLater(new Runnable() {
                public void run() {
                     triangle frame = new triangle();
                     frame.setVisible(true);
                }
          });
      }
  
      public void actionPerformed(ActionEvent ae) {
  
      }
  
      public void drawPolygon(int x, int y, int i)
      {
          Graphics g = this.getGraphics();
          g.setColor(Color.BLACK);
          g.drawPolygon(xx, yy, 3);
  
      }
  
      int x, y;
  
      public void mouseClicked(MouseEvent e) {
          x = e.getX();
          y = e.getY();
  
          repaint();
      }
  
  
      @Override
      public void paint(Graphics g) {
          drawPolygon(x, y, 3);
      }
  
  
  
      public void mouseExited(MouseEvent e) {
  
      }
  
      public void mousePressed(MouseEvent e) {
  
      }
  
      public void mouseReleased(MouseEvent e) {
  
      }
  
      public void mouseEntered(MouseEvent e) {
  
      }
  }``
  </code></pre>