Circles and Triangles

Circles and Triangles

How can I draw the triangle inside the ellipse with 3 mouse clicked(or how can i do an outside triangle circle with 3 mouse clicked)?? This is my code for triangle with 3 mouse Clicked but I don't know how to put it in the circle(or ellipse).Can somebody help me please??

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.awt.geom.*;

public class TriangleComponent extends JComponent
{   private int[] positionX;
    private int[] positionY;
    private int clicks; 
    public TriangleComponent()
    { JFrame f=new JFrame();
        f.getContentPane().add(this);
       f.setSize(640, 480);
      f.setVisible(true);
      clicks = 0;
      MouseListener listener = new MouseTriListener();
      addMouseListener(listener);
      positionX = new int[3];
      positionY = new int[3];
    }

    public void paintComponent(Graphics g)
    {
        Graphics2D g2 = (Graphics2D) g;
        Point2D.Double r1 = new Point2D.Double(positionX[0], positionY[0]);
        Point2D.Double r2 = new Point2D.Double(positionX[1], positionY[1]);
        Point2D.Double r3 = new Point2D.Double(positionX[2], positionY[2]);

        Line2D.Double post1 = new Line2D.Double(r1, r2);
        Line2D.Double post2 = new Line2D.Double(r2, r3);
        Line2D.Double post3 = new Line2D.Double(r3, r1);

        g2.draw(post1);
        g2.draw(post2);
        g2.draw(post3);
    }

        class MouseTriListener implements MouseListener
        {
            public void mousePressed (MouseEvent event)
            {
                positionX[clicks] = event.getX();
                positionY[clicks] = event.getY();
                clicks++;
                if (clicks % 3 ==0)
                {
                    repaint();
                    clicks = 0;
                }
            }

            public void mouseReleased(MouseEvent event) {}
            public void mouseClicked(MouseEvent event) {}
            public void mouseEntered(MouseEvent event) {}
            public void mouseExited(MouseEvent event) {}
        }
          public static void main(String[] args)
            {
             new TriangleComponent();
            }


}
View Answers









Related Tutorials/Questions & Answers:
Circles and Triangles
Circles and Triangles  How can I draw the triangle inside the ellipse with 3 mouse clicked(or how can i do an outside triangle circle with 3 mouse clicked)?? This is my code for triangle with 3 mouse Clicked but I don't know how
Attaching circles
Attaching circles  How to attach circles with a distance joints
Advertisements
RASTER TRIANGLES!!! - Java Beginners
RASTER TRIANGLES!!!  Hi Sir, Sorry i think in my previous post, I don't know y the triangles didn't appear properly, so now im gonna only draw 1..., the number of triangles per row to be 4 and the number of rows to be 2. So
ModuleNotFoundError: No module named 'Circles'
ModuleNotFoundError: No module named 'Circles'  Hi, My Python... 'Circles' How to remove the ModuleNotFoundError: No module named 'Circles... to install padas library. You can install Circles python with following command
ModuleNotFoundError: No module named 'Circles'
ModuleNotFoundError: No module named 'Circles'  Hi, My Python... 'Circles' How to remove the ModuleNotFoundError: No module named 'Circles... to install padas library. You can install Circles python with following command
ModuleNotFoundError: No module named 'Circles'
ModuleNotFoundError: No module named 'Circles'  Hi, My Python... 'Circles' How to remove the ModuleNotFoundError: No module named 'Circles... to install padas library. You can install Circles python with following command
ModuleNotFoundError: No module named 'Circles'
ModuleNotFoundError: No module named 'Circles'  Hi, My Python... 'Circles' How to remove the ModuleNotFoundError: No module named 'Circles... to install padas library. You can install Circles python with following command
write a program in C to print following triangles on the screen
write a program in C to print following triangles on the screen  write a program in C to print following triangles on the screen
how to create triangles around square
how to create triangles around square   7 6 8 5 9 4 5 6 7 8 9 10
how to create triangles around square
how to create triangles around square   7 6 8 5 9 4 5 6 7 8 9 10
how to draw lines,circles, rectangles on JSP.
how to draw lines,circles, rectangles on JSP.  how to draw lines,circles, rectangles on JSP. Kindly provide solutions asap
how to draw lines,circles, rectangles on JSP (using Java Graphics)
how to draw lines,circles, rectangles on JSP (using Java Graphics)  how to draw lines,circles, rectangles on JSP (using Java Graphics)   Hello Anuj Try the Following Code :ADS_TO_REPLACE_1 image.jsp <%@ page
how to draw multilple circles in a circular form and connect them with lines - Java Beginners
how to draw multilple circles in a circular form and connect them with lines  Hi, Can anyone explains me , how to draw multiple circles using a single applet or swings in a circular form and connect them with lines. It should
circles - Java Beginners
more circles - Java Beginners
even more circles - Java Beginners
Canvas
RASTER TRAINGLES!!! - Java Beginners
: Question is as follows: Write an application that outputs rows of large triangles...) the number of triangles to be output in each row (c) the number of rows of triangles to be output. In the example output above the triangle size
program
works in graphical representations like numbers are taken in circles and computation... in rectangles or circles wat ever it may be. the theme of program is to show algorithm working through graphical representations like circles,rectangles,colored
java
java  Design a simple applet that can draw shapes such as rectangles, circles, Lines and ovals. Set them to different colors
Java programming help - Java Beginners
()); System.out.print("The number of triangles you want to output in each row...("The number of rows of triangles you want to output : "); int noOfRows...; Rows<=c; Rows++){ for(int triangles=1; triangles<=b; triangles
print a rectangle - Java Beginners
()); System.out.print("The number of triangles you want to output in each row...("The number of rows of triangles you want to output : "); int noOfRows...=1; Rows<=c; Rows++){ for(int triangles=1; triangles<=b; triangles
POLES and ZEROS diagram - Swing AWT
POLES and ZEROS diagram  Hi there My question regarding GUI. Actually I drew a circle and now I want to add zeros(small circles like "o") and poles("x"). Now I want to add zeros by clicking the mouse inside circles
Java applet
Java applet  I wanted as many clicks are there ,circles should be displayed there. I tried this code but it erases previous circles. plz help. public void mouseClicked(MouseEvent m) { x=m.getX(); y=m.getY
Java applet
Java applet  I wanted as many clicks are there ,circles should be displayed there. I tried this code but it erases previous circles. plz help. public void mouseClicked(MouseEvent m) { x=m.getX(); y=m.getY
coding shape
coding shape  i need to write a simple java program. the system must be in an applet and allows a user to choose whether to draw shapes such as circles, rectangles or lines on the screen. also, user can add circles by choosing
rob
on the input number the program will draw those shapes (either squares or circles
rob
number the program will draw those shapes (either squares or circles
rob
on the input number the program will draw those shapes (either squares or circles
rob
number the program will draw those shapes (either squares or circles
rob
squares or circles. In the following examples the user has chosen Square
rob
the program will draw those shapes (either squares or circles
java-graph help - Java Beginners
java-graph help  sir/madam I wanted to design a shortest path Algorithm. i wanted to show the shortest path in graphical format in the way it looks in the books.I have drawn circlec and lines between the circles but am not able
nested for-loop
nested for-loop  hi.write a program that will prompt the user for a positive integer(num) and then display two triangles with num number of lines to represent the following patterns of asterisks. the input num must be validated
Java Program
with anything, then it will immediately disappear and cause all other circles
Java Program
with anything, then it will immediately disappear and cause all other circles
Moire Pattern Java Program
Moire Pattern Java Program  **strong text**What you are seeing in the screenshot are two sets of concentric circles. The centers of the circles are 100 pixels apart. The circles have a width of 5, and the diameter of a circle
Moire Pattern 2 Java
Moire Pattern 2 Java   textWhat you are seeing in the screenshot are two sets of concentric circles. The centers of the circles are 100 pixels apart. The circles have a width of 5, and the diameter of a circle is 20 pixels larger
Cricket stadium ticket booking design
getting what I wanted.The code goes here for drawing circles: <style>...; </div> Further I want to draw lines between the two circles for showing
What is Trilateration?
of the two intersecting points of the two circles surrounding city A and city B... locate yourself very precisely, as these three circles can intersect each other... of circles. It is a little tricky to visualize. Here, we have to imagine the radii from
Applet - Java Beginners
// tall thin triangles. g.drawLine(pt[0].x, pt[0].y
Sine Table in JSP
of triangles were the same, while the sides could be as long or short as you wanted
DrawingCircle - Swing AWT
); this.setTitle("Draw Circles"); this.setSize(200,150
caller tunes case study
introduced â??caller tune serviceâ?? in select circles and it became a huge hit. Hence the company decided to extend the service to different circles. The company also
java compilation - UML
java compilation  Every circle has a center and a radiuus. Given the radius , we can determine the circles area and circumference. Given the center, we can determine its position in the x-y plane. The center of a circle
Show XOR Mode
four circles showing the XOR mode on the forth circle. The logical pixel
Influence of Social Media on Society
limited to the academic circles as nowadays even common people take part
Basics of Global Positioning System
in which the area is divided into a series of triangles for accurate 3D measurements
Pragati Maidan Travel in New Delhi
of the hall. The triangles are used to create a consistent pattern that will make
Displaying the same image in a JPanel and using scroll - HELP - Java Beginners
circles; private JPanel drawingPane; private final Color colors...()); area = new Dimension(0,0); circles = new Vector

Ads