【发布时间】:2013-10-29 14:55:15
【问题描述】:
我必须制作一个显示其自己源代码的小程序。这就是我所拥有的:
//Reference the required Java libraries
import java.applet.Applet;
import java.awt.*;
//The applet code
public class FirstApplet extends Applet {
public void paint(Graphics g) {
//Draw a rectangle width=250, height=100
g.drawRect(0,0,250,600);
//Set the color to blue
g.setColor(Color.blue);
//Write the message to the web page
g.drawString("\n //Reference the required Java libraries\n import java.applet.Applet;\n import java.awt.*; \n //The applet code\n public class FirstApplet extends Applet {\n public void paint(Graphics g) {\n //Draw a rectangle width=250, height=100\n g.drawRect(0,0,250,100); \n //Set the color to blue\n g.setColor(Color.blue); \n //Write the message to the web page\n g.drawString",10,50);
}
}
但是,\n 并没有换行。我的文字水平继续,直到完成。如何在 g.drawString 字段中创建新行?
【问题讨论】:
-
将y值增加上一行的文字高度?
-
我试着把矩形变大,还是不行。