Results 1 to 4 of 4
  1. #1
    tehsumo is offline Member
    Join Date
    Feb 2012
    Posts
    9
    Rep Power
    0

    Default How to create a JFrame window and create a circle.

    So I have been learning java for about a year now, and I have a pretty good understanding of it but I am starting to get lost when it comes to inheritance, polymorphism, and graphics. Specifically the graphics part is what I am lost on. So the assignment is as follows:

    Implement the following class, You will need to define the two methods specified; all other methods are inherited. The draw() method should draw a small circle and the label:
    public class LabeledPoint extends java.awt.Point
    {
    public LabeledPoint(int x, int y, String t)
    // constructs a Point with a text label describing its position
    public void draw (Graphics g)
    // draws a small circle and the label in the specified position
    private String text;
    }
    Write a tester program for the LabeledPoint class that generates and displays 20 random points in a JFrame window.

    So I am pretty much lost and have no idea where to go. I have created the tester method in another class that creates an array of LabeledPoint but from there I have no idea how to create the draw method to create the circles. I have tried a few different ideas but I have no idea how to pass the parameters to the draw method. Can any one help me in the right direction or post a link that would help me out?

  2. #2
    Alkor is offline Member
    Join Date
    Feb 2012
    Posts
    39
    Rep Power
    0

    Default Re: How to create a JFrame window and create a circle.


  3. #3
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,404
    Rep Power
    20

    Default Re: How to create a JFrame window and create a circle.

    Moved from New to Java

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  4. #4
    tehsumo is offline Member
    Join Date
    Feb 2012
    Posts
    9
    Rep Power
    0

    Default Re: How to create a JFrame window and create a circle.

    I read up over that and it didn't quite answer all my questions. I guess I understand how to use the paint method, but in this situation I am susposed to have the actual drawing done by the LabelPoint Class. Would something like this work to satisfy the assignment requirements
    public class LabeledPoint
    {
    public void draw(Graphics G)
    {
    g.fillOval(0,0,10,10);
    }
    }//end LabeledPoint
    public class LPtester extends JFrame
    {

    public void paint(Graphics g)
    {
    Labeledpoint tst=new Labeledpoint;
    tst.draw(g);
    }
    }

    I would have to create a JFrame in the tester class, but would this be a start/ a way to utilize the draw method rather than the paint method for creating the images?

Similar Threads

  1. Alternative way to create a circle propagation?
    By Kratos321 in forum New To Java
    Replies: 8
    Last Post: 05-26-2011, 04:23 AM
  2. How to create a Popup window
    By sarwar1234 in forum New To Java
    Replies: 2
    Last Post: 09-29-2010, 04:38 PM
  3. Why doesn't this create a window?
    By Addez in forum New To Java
    Replies: 7
    Last Post: 09-17-2009, 05:15 PM
  4. Create Window from HINSTANCE
    By apkernMe in forum AWT / Swing
    Replies: 0
    Last Post: 09-17-2009, 11:39 AM
  5. Replies: 0
    Last Post: 08-03-2007, 04:21 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •