2 Replies - 185 Views - Last Post: 31 January 2013 - 06:20 PM Rate Topic: -----

#1 Sethoroth999  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 29-January 13

There is a syntax error in passing "Graphics g" to the subclas

Posted 29 January 2013 - 08:40 PM

Could someone help me with debugging this Java applet that exhibits inheritance?

I can finish the rest once i can build this.

Here is the program I have so far:
// This program should create a poorly drawn nyan cat (=^_^/>=)[]/
// However I cannot start plugging in numbers until I discove the correct syntax

import java.awt.*;
import java.applet.*;


public class GraphicsLab04st extends Applet	//main class
{
public void paint(Graphics g)
{
CatMath one = new CatMath(g,55); // place holdr number!!!!!!!!!!!!!!!!

}
}


class Cat	//super class
{
private Color catColor;

public Cat(Graphics g, Color cc, int x)	// constructor
{

catColor = cc;	 // set cat color
g.setColor(catColor);
// cat body

g.fillOval(75,275,100,100); // Head
g.fillRect(x+5,325,50,50);	// Ears
g.fillRect(x+95,325,50,50);	// Body
g.fillRect(x+95,325,50,50);	// Legf1
g.fillRect(x+95,325,50,50);	// Legf2
g.fillRect(x+95,325,50,50);	// Legb1
g.fillRect(x+95,325,50,50);	// Legb2
//tail
Polygon tail = new Polygon();
tail.addPoint(400,70);//base
tail.addPoint(550,200);
tail.addPoint(500,350);//top
tail.addPoint(300,350);

g.drawPolygon(tail);
// rounded edgdes
g.fillOval(75,275,100,100); // paw1
g.fillOval(75,275,100,100);	// paw2
g.fillOval(75,275,100,100);	// paw3
g.fillOval(75,275,100,100);	// paw4
g.fillOval(75,275,100,100);	//tail roundness


}

class NyanCat extends Cat	// subclass
{
private int x;

public NyanCat (Graphics g, Color cc) // constructor
{
super(g,Color cc,int x1);
x = x1;
Poptart(g);
Rainbow(g);
}

public void Poptart (Graphics g)
{
g.fillRect(x+95,325,50,50);//base
g.fillRect(x+95,325,50,50);// frosting

int count = 0;
while (count <	24 )
{
g.fillOval(75,275,100,100); // sprinkles top
g.fillOval(75,275,100,100);	// sprinkles bottom
count++;
}
}

public void Rainbow (Graphics g)
{
g.setColor(Color.red);	 //
g.fillRect(x+95,325,50,50);	// r
g.setColor(Color.orange);	 //
g.fillRect(x+95,325,50,50);	// o
g.setColor(Color.yellow);	 //
g.fillRect(x+95,325,50,50);	// y
g.setColor(Color.green);	 //
g.fillRect(x+95,325,50,50);	// g
g.setColor(Color.blue);	 // b
g.fillRect(x+95,325,50,50);	//
g.setColor(Color.MAGENTA);	// v
g.fillRect(x+95,325,50,50);	//


}
}
}

class Mathmatics
{
public Plus (Graphics g)
{
g.setColor(Color.red);
g.fillRect(x+95,325,50,50);	// plus sign
g.fillRect(x+95,325,50,50);	//
}

public Equals (Graphics g)
{
g.setColor(Color.red);
g.fillRect(x+95,325,50,50);	// equal sign
g.fillRect(x+95,325,50,50);	//
}

}
class CatMath
{


public Train(Graphics g, int x)
{

Cat random = new Cat(g,Color.orange,x+200);	 // place holder numbers!!!!!!!!!!
NyanCat awesome = new NyanCat(g,Color.grey,x+500); // place holder numbers!!!!!!!!!!
Mathmatics signs = new Mathmatics(g);
}




}



}

}





//

Is This A Good Question/Topic? 0
  • +

Replies To: There is a syntax error in passing "Graphics g" to the subclas

#2 farrell2k  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 797
  • View blog
  • Posts: 2,422
  • Joined: 29-July 11

Re: There is a syntax error in passing "Graphics g" to the subclas

Posted 30 January 2013 - 12:04 AM

You're going about this the complete wrong way. While you can draw like that in your constructor, your subclass should just have a draw(g) which you can call in your Applet's paint().

A lot of your code is missing, and you haven't told us what your Applet is supposed to do and what it does, so I can't help.
Was This Post Helpful? 1
  • +
  • -

#3 Sethoroth999  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 29-January 13

Re: There is a syntax error in passing "Graphics g" to the subclas

Posted 31 January 2013 - 06:20 PM

View Postfarrell2k, on 30 January 2013 - 12:04 AM, said:

You're going about this the complete wrong way. While you can draw like that in your constructor, your subclass should just have a draw(g) which you can call in your Applet's paint().

A lot of your code is missing, and you haven't told us what your Applet is supposed to do and what it does, so I can't help.


Thank you, all I needed was to "just have a draw(g) ".
I will place my info outside of the code in the future.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1