此处显示的文字无论出于何种原因都不会出现在代码中。
它应该如下所示:
有问题的代码:
import java.awt.Canvas;
import java.awt.Graphics;
import java.awt.Color;
import javax.swing.JFrame;
public class CRlab31 extends Canvas
{
public static void main (String[] args)
{
JFrame w=new JFrame("Graphics");
w.setSize(800,600);
w.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
CRlab31 canvas=new CRlab31();
w.add(canvas);
w.setVisible(true);
}
public void paint(Graphics g)
{
g.setColor(Color.green);
g.drawRect(50,20,100,200);
g.fillOval(160,20,100,200);
g.setColor(Color.blue);
g.fillRect(200,400,200,20);
g.drawOval(200,430,200,100);
g.setColor(Color.black);
g.drawString("Graphics are pretty neat.",500,100);
int x=getWidth()/2;
int y=getHeight()/2;
g.drawString("The first letter of this string is at ("+x+","+y+")",x,y);
}
}
我在这里应该做些什么来使文本实际显示在示例中?