Home Answers Viewqa Java-Beginners Circles and Triangles

 
 


andora
Circles and Triangles
0 Answer(s)      a year and 2 months ago
Posted in : Java Beginners

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 Pages:
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
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
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 : image.jsp <%@ page contentType="image
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
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
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-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
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
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
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 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
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
What is Trilateration?
intersecting points of the two circles surrounding city A and city B. Now if you could... very precisely, as these three circles can intersect each other at just one point... trilateration we are dealing with spheres instead of circles. It is a little tricky
Drawing
Java NotesDrawing The java.awt.Graphics class (see GUI Graphicsis the basis for drawing simple graphics (lines, circles, text, ...). It is easy to use, and can be used with the Color class to set the drawing color and Font class
Example - CirclePanel.java
/** * methods/CirclePanel.java - Component to draw circles. * This class...) { super.paintComponent(g); // Try drawing some example circles
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
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
Basics of Global Positioning System
is divided into a series of triangles for accurate 3D measurements of distances
Ajax Framework
capabilities for JavaScript: functions to draw circles, ellipses (ovals), oblique lines, polylines and polygons (for instance triangles, rectangles) dynamically
Summary: GUI Graphics
drawing here. } } java.awt.Polygon Straight-sided shapes (eg, triangles) can
Summary: Graphics
Straight-sided shapes (eg, triangles) can be created with Polygon class
Pragati Maidan Travel in New Delhi
build with several triangular panels around the outside of the hall. The triangles
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
Example - CircleMain.java
); // Note 2 this.setTitle("Circles"); this.pack
Show XOR Mode
the current color and the new specified color. We have defined four circles

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.