Having problem with Compiling a java class

Having problem with Compiling a java cla

Page 1 of 1

2 Replies - 3382 Views - Last Post: 26 December 2005 - 07:40 PM Rate Topic: -----

#1 Adamking  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 26-December 05

Having problem with Compiling a java class

Posted 26 December 2005 - 07:34 AM

I am not able to compile the following java program and appreciate your assistance:

import java.awt.*;
import javax.swing.*;
import java.util.*;

public class house
{

Graphics g;
public void drawHouse (g)
{

g.setBackground (Color.black);
g.setColor(Color.white);
// front
g.fillRectangle(100,100,300,100);
// roof
g.drawLine(100,100,250,25);
g.drawLine(250,25,400,100);
// windows
g.setColor(Color.blue);
g.fillRectangle(125,125,20,20);
g.fillRectangle(355,125,20,20);
// door
g.setColor(Color.red);
g.fillRectangle(240,150,30,50);
}
}

Is This A Good Question/Topic? 0
  • +

Replies To: Having problem with Compiling a java class

#2 Jayman  Icon User is offline

  • Student of Life
  • member icon

Reputation: 418
  • View blog
  • Posts: 9,532
  • Joined: 26-December 05

Re: Having problem with Compiling a java class

Posted 26 December 2005 - 01:43 PM

Try this it should take care of the problem. Use the JApplet init() method to set background color. And you just need to shorten the word fillRectangle to fillRect. Also have to extend the Japplet class so that your class inherits its methods.

See following code:

import java.awt.*;
import javax.swing.*;
import java.util.*;

public class House extends JApplet
{

public void init()
{
Container c=getContentPane();
c.setBackground(Color.black);
}

public void paint (Graphics g)
{

super.paint(g);

g.setColor(Color.white);
// front
g.fillRect(100,100,300,100);
// roof
g.drawLine(100,100,250,25);
g.drawLine(250,25,400,100);
// windows
g.setColor(Color.blue);
g.fillRect(125,125,20,20);
g.fillRect(355,125,20,20);
// door
g.setColor(Color.red);
g.fillRect(240,150,30,50);
}
}

Enjoy!
Was This Post Helpful? 0
  • +
  • -

#3 Adamking  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 26-December 05

Re: Having problem with Compiling a java class

Posted 26 December 2005 - 07:40 PM

It is worked. Thanks very much.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1