I had to make an applet that shows its own source code. This is what I have:
//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);
}
}
However, the \n is not making a new line. My text continues horizontally until finished. How would I crate new lines inside the g.drawString field?