Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

How do I get a print statement to print in a drawing panel? The project states:

ID: 3757717 • Letter: H

Question

How do I get a print statement to print in a drawing panel? The project states: In the main method, before the call to startGame, print the following on the screen in black at position x=10 and y = 15.

This is what I currently have, but it wont print in the drawing panel:

import java.awt.*;

public class Project2 {
public static void main(String[] args) {
DrawingPanel panel = new DrawingPanel(500, 400);
Graphics g = panel.getGraphics( );
  
int x = 10;
int y = 15;
System.out.println("Project 2 by: Name");
startGame(panel, g);
}
  
public static void startGame(DrawingPanel panel, Graphics g) {
int x = 0;
int y = 270;
int deltaX = 1;
int deltaY = -3;
for (int t = 0; t <= 1000; t++) {
panel.sleep(50);
  
}
}
}

Explanation / Answer

sol : set the background color of panel to black and for text use white as shown in code and to print statement use drawstring ( " your text " , x , y )

import java.awt.*;

public class Project2 {
public static void main(String[] args) {
DrawingPanel panel = new DrawingPanel(500, 400);

panel.setBackground(Color.BLACK);
Graphics g = panel.getGraphics( );
g.setColor(Color.WHITE);
g.drawString("Project 2 by: Name", 10, 15);
startGame(panel, g);
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote