Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Java-Beginners Circles and Triangles
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


andora
Circles and Triangles
0 Answer(s)      2 years and 9 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();
            }


}

Advertisement
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
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
java
java  Design a simple applet that can draw shapes such as rectangles, circles, Lines and ovals. Set them to different colors
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
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
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
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
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
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
 

 

 

DMCA.com