Need Help to Draw and Drag Triangle - URGENT

Hi everyone - I am developing various proofs of the pythagora's theorem
and the following code draws a triangle on screen and the proof follows -
but i need to know how to drag the triangle such tht 1 angle is always set to 90 degrees.
i.e. i need to resize the triangle by dragging its vertex points by which the1 angle remains at 90 no matter what the size.
The proof has got some graphics code hardcoded in it - i.e. LINES AND POLYGONS have been hardcoded
i need to reconfigure that such that everytime the user increases the size of the triagnle and clicks on next it draws the lines and polygons in the correct area and place
PLEASE HELP
the code is as follows
MAIN CLASS
import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.*;
import java.awt.event.*;
import java.text.*;
import javax.swing.*;
public class TestProof {
    TestControl control;          // the controls for the visual proof
    TestView view;          // the drawing area to display proof
    // called upon class creation
    public TestProof() {
        view = new TestView();
view.setBackground(Color.WHITE);
        control = new TestControl(view);
        Frame f = new Frame("Pythagoras");
        f.add(view,"Center");
        f.add(control,"South");
        f.setSize(600,600);
        f.setBackground(Color.lightGray);
        f.addMouseMotionListener(
        new MouseMotionListener() { //anonymous inner class
            //handle mouse drag event
            public void mouseMoved(MouseEvent e) {
                System.out.println("Mouse  " + e.getX() +","  + e.getY());
            public void mouseDragged(MouseEvent e) {
                System.out.println("Draggg: x=" + e.getX() + "; y=" + e.getY());
        JMenu File = new JMenu("File");
        JMenuItem Exit = new JMenuItem("Exit");
        Exit.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ExitActionPerformed(evt);
        JMenuBar menuBar = new JMenuBar();
        menuBar.add(File);
   File.add(Exit);
        f.add(menuBar,"North");
        f.show();
    private JMenuBar getMenuBar() {
        JMenu File = new JMenu("File");
        JMenuItem Exit = new JMenuItem("Exit");
        Exit.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ExitActionPerformed(evt);
        JMenuBar menuBar = new JMenuBar();
        menuBar.add(File);
             File.add(Exit);   
        return menuBar;
    private void ExitActionPerformed(java.awt.event.ActionEvent evt) {
        // TODO add your handling code here:
        System.exit(0);
    // for standalone use
    public static void main(String args[]) {
  TestProof TP = new TestProof();
}Test VIEW
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.geom.*;
import java.text.*;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class TestView extends Canvas {
    int TRANSLUCENT = 1;
    int sequence;          // sequencer that determines what should be drawn
    // notes matter
    int noteX = 100;     // note coordinates
    int noteY = 60;
    int fontSize = 11;     // font size
    int lineSpacing     // space between two consecutive lines
    = fontSize + 2;
    Font noteFaceFont;     // font used to display notes
    // objects matter
    Polygon tri;          // right-angled triangle with sides A, B, and C
    Polygon tri1;
    Polygon sqrA;          // square with side of length A
    Polygon sqrB;          // square with side of length B
    Polygon sqrC;          // square with side of length C
    Polygon parA;          // parallelogram of base A and height A
    Polygon parB;          // parallelogram of base B and height B
    Polygon poly1;
    Polygon poly2;
    Polygon poly3;
    Polygon poly4;
    Polygon poly5;
    Polygon poly6;
    int X0 = 350;          // coordinates of triangle
    int Y0 = 350;
    int A = 90;//60;          // triangle size
    int B = 120;//80;
    int C = 150;//100;
    //CORDS of 2nd triangle
    int X1 = 350;
    int Y1 = 500;
    // notes: three lines per note
    String notes[] = {
        // note 0
        // note 1
        // note 2
        // note 3
        // note 4
        // note 5
        // note 6
        // note 7
        // note 8
        // note 9
        // note 10
        // note 11
        // note 12
        // note 13
        // note 14
    // constructor
    public TestView() {
        addMouseMotionListener(
        new MouseMotionListener() { //anonymous inner class
            //handle mouse drag event
            public void mouseMoved(MouseEvent e) {
                System.out.println("Mouse  " + e.getX() +","  + e.getY());
            public void mouseDragged(MouseEvent e) {
                System.out.println("Draggg: x=" + e.getX() + "; y=" + e.getY());
        // set font
        noteFaceFont = new Font("TimesRoman", Font.PLAIN, fontSize);
        // (coordinates specified w.r.t. to P0, unless otherwise specified)
        // create the triangle
        tri = new Polygon();
        tri.addPoint(0, 0);                    // add P0 coordinate
        tri.addPoint(A*A/C, -A*B/C);          // add A3 coordinate
        tri.addPoint(C, 0);                    // add C1 coordinate
        tri.translate(X0, Y0);               // place triangle
        tri1 = new Polygon();
        tri1.addPoint(0,0);                    // add P0 coordinate
        tri1.addPoint(A*A/C +38, +A*B/C);          // add A3 coordinate
        tri1.addPoint(C, 0);                    // add C1 coordinate
        tri1.translate(X1, Y1);
        // create square of side A
        sqrA = new Polygon();
        sqrA.addPoint(0, 0);               // add P0 coordinate
        sqrA.addPoint(-A*B/C, -A*A/C);          // add A1 coordinate
        sqrA.addPoint(-A*(B-A)/C, -A*(A+B)/C);     // add A2 coordinate
        sqrA.addPoint(A*A/C, -A*B/C);          // add A3 coordinate
        sqrA.translate(X0, Y0);               // place square
        // create square of side B
        // warning: the coordinate of this object are specified relative to C1
        sqrB = new Polygon();
        sqrB.addPoint(0, 0);               // add C1 coordinate
        sqrB.addPoint(B*A/C, -B*B/C);          // add B1 coordinate
        sqrB.addPoint(B*(A-B)/C, -B*(A+B)/C);     // add B2 coordinate
        sqrB.addPoint(-B*B/C, -B*A/C);          // add A3 coordinate
        sqrB.translate(X0 + C, Y0);               // place square
        // create square of side C
        sqrC = new Polygon();
        sqrC.addPoint(0, 0);               // add P0 coordinate
        sqrC.addPoint(C, 0);               // add C1 coordinate
        sqrC.addPoint(C, C);               // add C2 coordinate
        sqrC.addPoint(0, C);               // add C3 coordinate
        sqrC.translate(X0, Y0);               // place square
        poly1 = new Polygon();
        poly1.addPoint(405,279);
        poly1.addPoint(413,350);
        poly1.addPoint(432,500);
        poly1.addPoint(442,571);
        poly1.addPoint(500,500);
        poly1.addPoint(500,350);
        poly2 = new Polygon();
        poly2.addPoint(279,297);
        poly2.addPoint(404,280);
        poly2.addPoint(571,254);
        poly2.addPoint(500,350);
        poly2.addPoint(350,350);
        //Polygon 3
        poly3 = new Polygon();
        poly3.addPoint(404,280);
        poly3.addPoint(350,350);
        poly3.addPoint(414,350);
        poly4 = new Polygon();
        poly4.addPoint(350,350);
        poly4.addPoint(350,500);
        poly4.addPoint(442,572);
        poly4.addPoint(433,500);
        poly4.addPoint(414,350);
        poly5 = new Polygon();
        poly5.addPoint(476,183);
        poly5.addPoint(332,225);
        poly5.addPoint(278,295);
        poly5.addPoint(404,279);
        poly5.addPoint(571,254);
        poly6= new Polygon();
        poly6.addPoint(405,278);
        poly6.addPoint(332,224);
        poly6.addPoint(476,182);
        // create parallelogram of height A
        parA = new Polygon();
        parA.addPoint(0, 0);               // add P0 coordinate
        parA.addPoint(0, C);               // add C3 coordinate
        parA.addPoint(A*A/C, C - A*B/C);          // add Q0 coordinate
        parA.addPoint(A*A/C, -A*B/C);          // add A3 coordinate
        parA.translate(X0,Y0);               // place parallelogram
        // create parallelogram of height B
        // warning: the coordinate of this object are specified from C1
        parB = new Polygon();
        parB.addPoint(0, 0);               // add C1 coordinate
        parB.addPoint(-B*B/C, -B*A/C);          // add A3 coordinate
        parB.addPoint(A*A/C - C, C - A*B/C);     // add Q0 coordinate
        parB.addPoint(0, C);               // add C2 coordinate
        parB.translate(X0 + C, Y0);
        // place parallelogram
    // depending on the sequence number we draw certain objects
    public void paint(Graphics gfx) {
        super.paint(gfx);
        Graphics2D g = (Graphics2D) gfx;
        g.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
        RenderingHints.VALUE_ANTIALIAS_ON);
        // text first, then objects (and animation)
        // we always output some notes
        g.drawString(notes[3*sequence], noteX, noteY);
        g.drawString(notes[3*sequence + 1], noteX, noteY + lineSpacing);
        g.drawString(notes[3*sequence + 2], noteX, noteY + 2*lineSpacing);
        // the object are drawn in an order so that they are properly overlapped
        if(sequence == 13) {
            g.setColor(Color.green);
            g.fillPolygon(poly1);
            g.fillPolygon(poly2);
            g.fillPolygon(poly3);
            g.fillPolygon(poly4);
            g.fillPolygon(poly5);
            g.setColor(Color.RED);
            g.setColor(Color.GREEN);
            g.drawLine(413,351,433,499);
            g.setColor(Color.white);
            g.fillPolygon(tri);
            g.fillPolygon(tri1);
            g.fillPolygon(poly6);
        if(sequence == 12 ) {
            g.setColor(Color.green);
            g.fillPolygon(poly1);
            g.fillPolygon(poly2);
            g.fillPolygon(poly3);
            g.fillPolygon(poly4);
            g.fillPolygon(poly5);
            g.setColor(Color.BLACK);
        if(sequence == 11){
            g.setColor(Color.green);
            g.fillPolygon(poly1);
            g.fillPolygon(poly3);
            g.fillPolygon(poly4);
            g.setColor(Color.BLACK);
        if(sequence == 8 ){
            g.setColor(Color.green);
            g.fillPolygon(poly5);
            g.setColor(Color.MAGENTA);
            g.drawString("E",578,254);
            g.drawString("D",268,302);
            g.setColor(Color.black);
            g.drawArc(250,150,350,250,320,65);
        else if (sequence == 9 ){
            g.setColor(Color.green);
            g.fillPolygon(poly2);
            g.setColor(Color.MAGENTA);
            g.drawString("E",578,254);
            g.drawString("D",268,302);
            g.setColor(Color.black);
            g.drawArc(250,150,350,250,320,65);
        if( sequence == 10){
            g.setColor(Color.green);
            g.fillPolygon(poly2);
            g.fillPolygon(poly5);
            g.setColor(Color.black);
            g.setColor(Color.MAGENTA);
            g.drawString("E",578,254);
            g.drawString("D",268,302);
            g.setColor(Color.black);
            g.drawArc(250,150,350,250,320,65);
        if(sequence == 7){
            g.setColor(Color.green);
            g.fillPolygon(poly2);
            g.setColor(Color.MAGENTA);
            g.drawString("E",578,254);
            g.drawString("D",268,302);
            g.setColor(Color.black);
        if(sequence == 6){
            g.setColor(Color.yellow);
            g.fillPolygon(poly2);
            g.setColor(Color.green);
            g.fillPolygon(poly3);
            g.setColor(Color.blue);
            g.fillPolygon(poly4);
            g.setColor(Color.black);
            g.drawArc(250,175,350,275,300,65);
            //g.drawArc(250,150,350,250,320,65);
            g.drawLine( 606,309,599,299);
            g.drawLine(592,313, 599,299);
            g.drawString("+90 degrees",605,378);
        if (sequence == 5 ) {
            g.setColor(Color.yellow);
            g.fillPolygon(poly2);
            g.setColor(Color.black);
        if (sequence == 4) {
            g.setColor(Color.YELLOW);
            g.fillPolygon(poly1);
            g.setColor(Color.black);
            g.drawArc(319,310,250,195,89,-35);
            g.drawLine(499,319, 492,312);
            g.drawLine(499,319, 492,325);
            g.drawArc(200,180, 233,238,-120,-60);
            g.drawLine(200,298, 208,309);
            g.drawLine(200,298, 194,313);
            g.drawString("-90 degrees",227,347);
        if (sequence >= 3) {
            g.drawLine(404,279,442,572);
        // draw the squares
        if (sequence >= 2) {
            g.drawLine(278,296,572,254);
        // draw the squares
        if (sequence >= 1) {
            g.drawLine(333,224,476,182);
            g.drawPolygon(tri1);
        // always draw the triangle
        g.drawPolygon(tri);
        g.drawPolygon(sqrA);
        g.drawPolygon(sqrB);
        g.drawPolygon(sqrC);
        g.setColor(Color.MAGENTA);
        g.drawString("C", X0 + C/2 - fontSize/2, Y0 + lineSpacing);
        g.drawString("A",
        X0 + A*A/(2*C) - fontSize*A/B/2,
        Y0 - A*B/(2*C) - lineSpacing*A/B);
        g.drawString("B",
        X0 + C - B*B/(2*C) - fontSize*A/B/2,// the last "-" isn't log.
        Y0 - B*A/(2*C) - lineSpacing*A/B);
    public void redraw(int sequence) {
        this.sequence = sequence;
        repaint();
}TEST CONTROL
* TestControl.java
* Created on 28 February 2005, 11:16
import java.awt.*;
import java.awt.event.*;
import java.text.*;
import javax.swing.JFrame;
* @author  Kripa Bhojwani
public class TestControl extends Panel implements ActionListener {
  TestView view;
  int sequence;                    // event sequence
  // constructor
  public TestControl(TestView view) {
    Button b = null;
    Label label = new Label("A^2 ");
    this.view = view;          // initialize drawble area
    sequence = 0;               // initialize sequence
    b = new Button("Prev");
    b.addActionListener(this);
    add(b);
    b = new Button("Next");
    b.addActionListener(this);
    add(b);
    add(label);
  // exported method
  public void actionPerformed(ActionEvent ev) {
    String label = ev.getActionCommand();
    if (label.equals("Prev")) {
      if (sequence >0) {
     --sequence;
    else {
      if (sequence < 15) {
     ++sequence;
    this.setEnabled(false);          // disable the controls
    view.redraw(sequence);
    this.setEnabled(true);          // enable the controls
}Please help --- really need to sort this out...
THANKS

One of the problems you face is that it is hard to recognise which parts of your code are drawing the triangle. This is because you are writing code in a procedural way rather than an object oriented way.
In object oriented code you would have a triangle object that could draw itself. You would create the triangle object by specifying its sizes and angles in some way. Then it should be easy to change the triangles sizes and angles and ask all the drawn objects to redraw themselves.

Similar Messages

  • Need help with iphoto and dragging to external hard drive

    Hello,
    I have my iphoto very organized into Events and I recently just moved them to be in folders.  I would like to have only certain Events (or folders/albums) on the external hard drive.  The apple store rep said to go to Finder, Pictures, Iphoto, then right click to "Show Package Contents."  Then go to either "original" or "modified." From there I can drag into the hard drive.  However, I'm very confused because the "modified" or "original" are not organized at all by folders or events.  There are dates only.  What can I do to find, drag the events (each are named)?  Please help!
    Katie

    1. Ignore the Apple store rep.
    2. You need to clarify:
    I have my iphoto very organized into Events and I recently just moved them to be in folders
    Moved them to be where in folder? In iPhoto? In the FInder?
    I would like to have only certain Events (or folders/albums) on the external hard drive.
    In an iPhoto Library? Or in the Finder?
    Do not access the Library via the Finder or any other app. You risk damaging your Library and you will lose data.
    If you want to have some Events/Albums on an External Disk within iPhoto:
    Make sure the drive is formatted Mac OS Extended (Journaled)
    1. Quit iPhoto
    2. Copy the iPhoto Library from your Pictures Folder to the External Disk.
    Now you have two full versions of the Library.
    3. On the Internal library, trash the Events you don't want there
    Now you have a full copy of the Library on the External and a smaller subset on the Internal
    Some Notes:
    As a general rule: when deleting photos do them in batches of about 100 at a time. iPhoto can baulk at trashing large numbers at one go.
    You can choose which Library to open: Hold down the option (or alt) key key and launch iPhoto. From the resulting menu select 'Choose Library'
    You can keep the Library on the external updated with new imports using iPhoto Library Manager
    If you want to have them in Folders in the Finder
    Use the FIle > Export command to get photos out of iPhoto.
    This User Tip
    https://discussions.apple.com/docs/DOC-4921
    has details of the options in the Export dialogue.

  • I need help to find and open a job app that I exported, was able to fill out and sign and saved and now can't open it? What did I do wrong?

    I need help to find and open a job app that I exported, was able to fill out and sign and saved and now can't open it? What did I do wrong?

    What file format did you export it to?

  • Need help to import and syncronize HCM pagelets with Interaction Hub, how can I do that?

    Hi,
    I need help to import and synchronize HCM pagelets with Interaction Hub, how can I do that? The default page "Select Remote Content" of the WorkCenter "Unified Navigation WorkCenter" is not working as well, when I run the import/sync button I get the following error message:
    Integration Gateway: General Connection Failed (158,10836)
    This error is thrown when there is no valid response.
    Possible errors include:
    Bad gateway URL
    Sync Service Timeout set and Service actually timed out.
    Java exception thrown - Check Application Server for possible Java exception

    Do you have integration configured between the two systems?  It sounds like you don't from the error.  Here is a walk-through on setting up Unified Navigation although it assumes you have integration already working.  If you haven't done that, it's documented a hundred different places.
    http://remotepsadmins.com/2013/03/04/peoplesoft-unified-navigation-with-peoplesoft-applicatations-portal-interaction-hub/

  • I need help in downloading and installing a previously purchased version of Photoshop Elements 12: AD012822594 1057-0247-4177-3303-6451-8067  or   1057-0904-6949-7119-8323-9165

    I need help in downloading and installing a previously purchased version of Photoshop Elements 12: AD012822594 1057-0247-4177-3303-6451-8067  or   1057-0904-6949-7119-8323-9165

    Please do not share serial numbers  or Order numbers on Forums . Serial numbers and order numbers  are very confidential.
    You can only share serial number with Adobe Customer support staff.

  • I need help in downloading and installing a previously purchased version of Photoshop Elements 12: Serial number removed by moderator

    I need help in downloading and installing a previously purchased version of Photoshop Elements 12: <Serial number removed by moderator>

    Hi There,
    Kindly try: Troubleshoot installation | Photoshop Elements, Premiere Elements | Windows
    Thanks,
    Atul Saini

  • Need Help in installations and connecting displays. Please!

    Hello Everyone,
    Need Help in installations and connecting displays. Please!
    Im planning on installing in a cafe shop : (Store Self improvement)
    4 TV's (can be  Built in Wi-Fi) Store menus
    2 touch screen tablets.  To be use as Emenu (digital Menu)
    1 60' TV ( Built in Wi-Fi) as Entrainment displays and in store advertising
    What do I need to organize my project and make it looks cool and how to manageand controll all of the displays TV.

    TNSTAAFL
    I DO NOT work for Best Buy, Geek Squad and any way affiliated with them. I am a self-employed repairman. I specialize in TV's and desktop computers. I do not take sides. If BB is wrong I will say so. If you are a moron with a false sense of entitlement, then I will tell you.

  • I need help from chile and use a language translator to write and not turn my iphone4

    I need help from chile and use a language translator to write and not turn my iphone4

    http://support.apple.com/kb/TS3281       
    Not turn on

  • Please help me!--rendering makes the images or video blurry (very pixelated) deteriorates the image  Adobe Premier Elements 13  need help!  .jpg and mpeg images,  but I have never "rendered" before since I got APE 13 about 6 weeks ago.  I am desperate for

    Please help me!--rendering makes the images or video blurry (very pixelated) deteriorates the image  Adobe Premier Elements 13  need help!  .jpg and mpeg images,  but I have never "rendered" before since I got APE 13 about 6 weeks ago.  I am desperate for assistance!

    That's going to be a ridiculous waste of money and energy.
    First of all, the current ATI drivers don't support multiple GPUs, so at the moment even a single 4870X2 would be only a 'normal' 4870 (which is quite a speed beast already). GFX drivers evolve rapidly, so things might look different next month, but when it comes to Linux and hardware there's one Golden Rule: stay away from the newest stuff and wait for proper support to get coded.
    I also wonder what power supply could possibly cope with the differences between idle and full load; that's way beyond 400W. But then, I'm one of those "quiet&green" types where >100W idle is already a bit much.
    I kind of understand that you want to get it done and not worry about hardware for the next 10 years or so, but that's simply not how the hardware world works and never did. At least not for the average consumer.

  • I am new to this but need help. Lion and iCloud have never worked on my desk top or MacBook Pro.  Slow or Stop!  Is there any way to fix the problem?

    I am new to this but need help. Lion and iCloud have never worked on my desk top or MacBook Pro.  Slow or Stop!  Is there any way to fix the problem?

    We need more information. I'm not sure what you mean by both Lion and iCloud have never worked.

  • HT1338 Need help locating where and how to update Mac OS-X 10.6.5 to the latest Mountain Lion Software...thanx John

    I need help locating where and how to update Mac OS-X to Mountain Lion.....Thanx....Jay

    First update your 10.6 version to 10.6.8 from the software update under the Apple Menu.
    This will add direct access to the Mac App store via a new application.
    Now launch the App Store from your Applications folder - Its the new icon a letter A formed from a ruler pencil and pen on a blue circle !
    Once launched you need to add your iTunes account details or create an account add payment details etc...
    Sign in purchase download and follow install processes to upgrade to 10.8 Mountain Lion.
    OH and to be safe BEFORE you install backup your current system to an external drive !

  • This is a second try to get help. I need help to uninstall and reinstall Photoshop cc 2014

    Bridge is not working well, I need to reinstall Photoshop cc 2014 .  Someone from Communities was suppose to help me. 

    Hi John,
    I used the chat "Creative chat support"  this afternoon at around 14:40
    and the person, Karthik M , gave me a link to Technical Support.  I
    guess he could not help me, but he said he understood the issue.   With
    the link "Help, Adobe Installation problems",   I will follow the
    instructions  to clean ps cc2014 with CCleaner and reinstall the app.  
    It looks quite complicated  but I will give it a try and hopefully succeed.
    You have to understand when reading my previous messages, the issue is
    no longer "Retreiving Photoshop CC" but reinstalling Phoshop 2014 to try
    to repair Bridge.
    Thanks for caring,
    Suzanne Lanthier
    Le 2014-08-13 15:50, John T Smith a écrit :
    >
          This is a second try to get help. I need help to uninstall and
          reinstall Photoshop cc 2014
    created by John T Smith <https://forums.adobe.com/people/JohnTSmith>
    in /Adobe Creative Cloud/ - View the full discussion
    <https://forums.adobe.com/message/6637788#6637788>

  • MOVED: [Athlon64] Need Help with X64 and Promise 20378

    This topic has been moved to Operating Systems.
    [Athlon64] Need Help with X64 and Promise 20378

    I'm moving this the the Administration Forum.  It seems more apporpiate there.

  • Need help for Update and cancel SalesOrder

    Hi All,
    I  written java code for create sales order based on salesquotation,now i want to update and cancel sales order ,i need help to update and cancel salesorder.
    can give any related links for update and cancel salesorder.
    Thanks and Regards,
    Srinivas

    Hi srinivas.L
    It is simple, here is some sample code. You must use getbykey to get the document. Then once you got it you can make whatever changes you need. Then update it. where i have oOrder.Update() you can have oOrder.cancel
    Dim oOrder As SAPbobsCOM.Documents
            oOrder = oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oOrders)
            If oOrder.GetByKey(530) Then
                oOrder.Lines.SetCurrentLine(1)
                oOrder.Lines.WarehouseCode = "01"
                If oOrder.Update() <> 0 Then
                    MsgBox(oCompany.GetLastErrorDescription)
                End If
            Else
                MsgBox("Nothing found")
            End If
    Hope this helps

  • Need help in drawing inside the Oval and outside it

    I need help in something
    I have an array and I want the numbers to be around the oval and I have part of the array and I want to fill part of the oval
    and when I want to put a number I would like a line from the center to point at the number
    I know its hard to explain so I have picture maybe you will know hwo its work
    http://img265.imageshack.us/i/55788522.jpg/
    I have almost everything done the oval and all the code but I have no clue how to do what I explained

    import static java.lang.Math.*;
    import java.awt.*;
    import javax.swing.*;
    @SuppressWarnings("serial") public class Trefoil extends JComponent {
            setPreferredSize(new Dimension(400, 400));
        @Override protected void paintComponent(Graphics g) {
            Graphics2D g2 = (Graphics2D) g.create();
            int w = getWidth(), h = getHeight();
            g2.setColor(getBackground());
            g2.fillRect(0, 0, w, h);
            g2.setColor(getForeground());
            g2.translate(w/2, h/2);
            g2.setRenderingHint(
                RenderingHints.KEY_ANTIALIASING,
                RenderingHints.VALUE_ANTIALIAS_ON);
            int rays = 100;
            for(int i=0; i<rays; ++i) {
                double angle = i*(2 * PI)/rays;
                double flange = cos(1.5* angle - PI/4);
                int r = (int)(190 * flange * flange);
                int x = (int)(r* cos(angle));
                int y = (int)(r* sin(angle));
                g2.drawLine(0, 0, x, y);
            g2.dispose();
        public static void main(String[] args) {
            EventQueue.invokeLater(new Runnable(){
                public void run() {
                    JFrame f = new JFrame("Trefoil");
                    f.add(new Trefoil());
                    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                    f.pack();
                    f.setLocationRelativeTo(null);
                    f.setVisible(true);
    }

Maybe you are looking for

  • Just got a Mac in Cambodia, how to install apps from apps store?

    Hello Community, iTunes required my credit card payment address in Vietnam or Singapore or other country. Why not Cambodia? How to install apps if I am based in Cambodia? Regards/Rithy

  • Question regarding external display

    Hello, I may have posted this in the wrong section, but the forums are labeled oddly.  Anyway, I have an Insignia flat screen that I'd like to use as a second monitor for my laptop.  However, I have no clue if this laptop can even use one. Here's som

  • Oracle 8i Lite package problem

    Hi, I had downloaded Oracle 8i Lite for NT (approx. 105 MB), zip files data around 3 times and each time I get the error message that the zip archive is corrupted . Is it the problem with the archive at the Oracle site. Can anybody help me to get the

  • Order related & delivery related billing

    Hi all, I have a scenario which is explained as under: In the sales order i have the following line items: 1. ATM machine - 1 qty. This will be a stock item. 2. ATM installation - 1 qty. This will be a service item so non-stock item. 3. Cables - 500

  • Clasification with Document Properties

    Hi, I´m stock in creating a Clasification for my Documents, I have added in the System Administration -> System Configuration -> Knowledge Management -> Configuration -> Content Management -> User Interface -> Search -> Search Options Set > UISearch