Linking between classes


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: Linking between classes

  1. #1
    Join Date
    Dec 2004
    Posts
    46

    Linking between classes

    Just quick query, with what I have been reading.

    How do I link between the circle class I have and the RunCircle class which creates a circle.


    Code for Circle Class:

    Code:
        
        import java.awt.*;
        import java.applet.*;
    
        public class Circle extends Applet
    {
       public void paint(Graphics g)
       {
         Circle myCircle = new Circle 
         g.setColor(Color.black);
          g.drawOval(85,45,75,75);
          
       }
    }






    Code for RunCircle (Correct)

    Code:
    import java.awt.*;
    public class RunCircle
    {
        public static void main(String[] args)
        {
            Frame frame = new Frame();
            Circle myCircle = new Circle(100,50,50); // is this line that is linked to the circle class??
            frame.setSize(300.300);
            frame.setBackground(Color.yellow);
            frame.add(myCircle);
            frame.setVisible(true);
        }
    }


    Iím doing some self-study reading a book and this properly isnít the best way of going about it mixing frames and applets but thatís what I am doing.

    Thanks

  2. #2
    Join Date
    Jun 2004
    Posts
    10
    You have described delegation which I prefer over inheritance. Here's a link that contains some basic information on the subject: http://www.cs.man.ac.uk/arch/people/...es/node10.html

  3. #3
    Join Date
    Dec 2004
    Location
    San Bernardino County, California
    Posts
    1,468
    how are you activating your applet? do you need to "initialize" and "start" it within your main method?

    Try adding

    myCircle.init();
    myCircle.start();

    before your frame.setxxx stuff and see if you get something new ...

    An applet needs to be initialized and started. If you are looking at an applet over the internet, the html page which refers to the applet includes the <applet> code which cues the browser to do that. If you are creating an application, then your application needs to do it.
    Last edited by nspils; 02-21-2005 at 01:04 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
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center