Results 1 to 10 of 10
  1. #1
    mike28 is offline Member
    Join Date
    Oct 2011
    Posts
    20
    Rep Power
    0

    Default problem using color constructor

    Hi

    i am new to java gui, i have trouble using color constructor.

    please tell me what the problem .

    thank you

    Java Code:
    import java.applet.*;
    import java.awt.*;
    
    public class AnAppletSubclass1c extends Applet
    {
    	Color c = new Color(5,25,205);
    
    	public void Color(int r,int g,int b);
    
    	public void init()
    	{
    		System.err.println("Hello from AnAppletSubClass.init - the current value of n is " + n);
    		c = Color.magenta;
    	}
    	public void paint(Graphics g) {
    		setBackground(c);
    		System.err.println("Hello from AnAppletSubClass.paint-- the current value of n is " + n);
    		n++;
    	}
    
    
    	int n = 0;
    }
    Java Code:
    <HTML>
    	<HEAD>
    		<TITLE> An Applet Subclass 1c </TITLE>
    	</HEAD>
    <BODY>
    
    	<p>Here is the output of my  Program:</p>
    	<APPLET CODE="AnAppletSubclass1c.class" WIDTH=150 HEIGHT=100>
    
    
    	</APPLET>
    </BODY>
    </HTML>

  2. #2
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

    Default Re: problem using color constructor

    Maybe you should tell us what the problem is. Provide full errors if you got them. We need information to help you out.

  3. #3
    mike28 is offline Member
    Join Date
    Oct 2011
    Posts
    20
    Rep Power
    0

    Default Re: problem using color constructor

    i just dont know have to use color constructor
    my error is "error: missing method body, or declare abstract
    public void Color(int r,int g,int b); "

    thank you

  4. #4
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

    Default Re: problem using color constructor

    Well, you have a method called 'public void Color(int r, int g, int b);' first of which that is wrong, is that you didn't declare it abstract and it has no body, so an error for that. Next, you don't need to define constructors of existing classes. Remove the line and your code should work fine.

  5. #5
    mike28 is offline Member
    Join Date
    Oct 2011
    Posts
    20
    Rep Power
    0

    Default Re: problem using color constructor

    thank you

    it works but what if i want to use one of the Color class constructors ex:" Color(int r, int g, int b)"

  6. #6
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

    Default Re: problem using color constructor

    You are, when you use an import statement you get access to any class in the import statement, or the directory is you use the asterisk (*). You don't define the constructors (or anything else for existing, imported classes), you simply use them. Check the API to see all the things you have access to in a class.

  7. #7
    mike28 is offline Member
    Join Date
    Oct 2011
    Posts
    20
    Rep Power
    0

    Default Re: problem using color constructor

    Thank you

    ok if you going to take a look at this website Java Platform SE 6 , its says there i have to Creates an opaque sRGB color with the specified red, green, and blue values in the range (0 - 255). The actual color used in rendering depends on finding the best match given the color space available for a given output device. Alpha is defaulted to 255.

    please if you have any clue please help me

    thank you

  8. #8
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: problem using color constructor

    I think that sunde know what the API states. Your problem is that you cannot create your own pseudo-method. Just get rid of this line:

    Java Code:
    public void Color(int r,int g,int b);
    It's not doing anything useful but is just causing errors.

  9. #9
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

    Default Re: problem using color constructor

    I think one of the problems you are running into is the thought that the onus is on you, but it is not. The Constructors you see in the constructor summary are defined in the java class library, when you use an import statement, you are getting access to them. Erase the line Fubar mentioned and it should work fine.

  10. #10
    mike28 is offline Member
    Join Date
    Oct 2011
    Posts
    20
    Rep Power
    0

    Default Re: problem using color constructor

    Thank you guys now i understand it , very helpful :)

Similar Threads

  1. problem with constructor
    By esallender in forum New To Java
    Replies: 5
    Last Post: 01-17-2011, 11:41 AM
  2. Color problem
    By dewitrydan in forum New To Java
    Replies: 6
    Last Post: 08-10-2010, 01:38 AM
  3. Constructor Problem
    By Aggy in forum New To Java
    Replies: 9
    Last Post: 01-19-2010, 10:42 PM
  4. Problem with Constructor
    By ToastyBainey in forum New To Java
    Replies: 3
    Last Post: 03-09-2009, 02:36 AM

Posting Permissions

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