Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/jpa/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
为什么';“我的java”;GRect“;关于eclipse的课堂作业?_Java_Applet_Acm Java Libraries - Fatal编程技术网

为什么';“我的java”;GRect“;关于eclipse的课堂作业?

为什么';“我的java”;GRect“;关于eclipse的课堂作业?,java,applet,acm-java-libraries,Java,Applet,Acm Java Libraries,当我尝试在Eclipse上测试运行下面的代码时,Java小程序出现了,并且只显示了一个方块。但它不显示(rect2)矩形 GRect Rect2 = new GRect (300, 75, 200, 100) ; Rect2.setFilled (true) ; Rect2.setColor (Color.RED) ; add (Rect2) ; 或者(GLabel)“你好,世界” 整个代码: import acm.graphics.*; import acm.program.* ;

当我尝试在Eclipse上测试运行下面的代码时,Java小程序出现了,并且只显示了一个方块。但它不显示(rect2)矩形

GRect Rect2 = new GRect (300, 75, 200, 100) ;
Rect2.setFilled (true) ; 
Rect2.setColor (Color.RED) ; 
add (Rect2) ; 
或者(GLabel)“你好,世界”

整个代码:

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) ; 
    }     
}

正在原始窗口外部绘制矩形。如果拖动小程序窗口使其变大,您将看到一个填充的红色矩形

因此,我的解决方案是只需设置窗口的初始大小:

setSize(800, 800);
而且GLabel的参数是错误的。这样做:

GLabel Label = new GLabel ("Hello world", 100, 75) ; 

您需要向我们展示更多的代码-包括正在工作的位和这些控件所在的面板-这里是整个代码。唯一有效的是GRect1。GRect2没有出现在日食上。
GLabel Label = new GLabel ("Hello world", 100, 75) ;