0

When I try to test run the below code on Eclipse, the Java applet shows up, and only shows me a square. But it doesn't show the (rect2) rectangle

GRect Rect2 = new GRect (300, 75, 200, 100) ;
Rect2.setFilled (true) ; 
Rect2.setColor (Color.RED) ; 
add (Rect2) ; 

or the (GLabel) "hello world".

   GLabel Label = new GLabel ("Hello, world, 100, 75") ;     
   Label.setFont(new Font("Courier New", Font.ITALIC, 12));    
   Label.setColor (Color.RED);    add (Label) ;

The whole code:

import acm.graphics.*; 
import acm.program.* ; 
import java.awt.* ; 

public class Test extends GraphicsProgram  {
    private static final long serialVersionUID = 3365078119967111934L;

    public void run () { 
        GLabel Label = new GLabel ("Hello, world, 100, 75") ; 
        Label.setFont(new Font("Courier New", Font.ITALIC, 12));
        Label.setColor (Color.RED);
        add (Label) ; 

        GRect Rect1 = new GRect (10, 10, 50, 50) ;
        add(Rect1) ; 

        GRect Rect2 = new GRect (300, 75, 200, 100) ;
        Rect2.setFilled (true) ; 
        Rect2.setColor (Color.RED) ; 
        add (Rect2) ; 
    }     
}
demongolem
  • 9,474
  • 36
  • 90
  • 105
Shazza
  • 41
  • 1
  • 4
  • You need to show us a little more of the code - including the bit that is working and the panel these controls are on – Elemental Apr 16 '13 at 09:35
  • Here is the whole code. The only thing that is working is the GRect1. The GRect2 isn't showing up on the eclipse. – Shazza Apr 16 '13 at 11:43

1 Answers1

0

The rectangle is being drawn outside of the original window. If you just drag the applet window to make it bigger, you will see a filled in red rectangle.

So my solution for you is to simply set the initial size of the window:

setSize(800, 800);

And the parameters to your GLabel are wrong. Do like this:

GLabel Label = new GLabel ("Hello world", 100, 75) ; 
demongolem
  • 9,474
  • 36
  • 90
  • 105