Question: What is wrong with this Java code? I am trying to run a java applet with the garden.jpg picture in the background. It runs for
What is wrong with this Java code? I am trying to run a java applet with the garden.jpg picture in the background. It runs for me without the background image.
import java.applet.Applet;
import java.awt.Graphics;
import java.awt.*;
//create a class Poem
public class Flowers extends Applet
{
//Declare Image variable
Image image;
// Initialize the image and size size
public void init()
{
setSize(1400, 800);
image = getImage(getCodeBase(), \"garden.jpg\");
Flowers bgp = new Flowers();
bgp.setLayout(new FlowLayout());
this.image = image;
}
// Override the paint method
public void paint(Graphics g)
{
// set image on graphics panel
g.drawImage(image, 0, 0, this);
// Flower 1
g.setColor(Color.black);
g.drawLine(250, 400, 250, 300);
g.fillOval(200, 200, 100, 100);
g.setColor(Color.yellow);
g.fillArc(215, 120, 70, 100,-60, 360);
g.fillArc(110, 210, 100, 50,20, 360);
g.fillArc(290, 210, 100, 50,-140,360);
g.setFont(new Font(\"Times New Roman\", Font.BOLD, 20));
g.setColor(Color.blue);
g.drawString(\"This is a yellow sunflower\", 160, 420);
// Flower 2
g.setColor(Color.black);
g.drawLine(550, 400, 550, 300);
g.fillOval(500, 200, 100, 100);
g.setColor(Color.orange);
g.fillArc(515, 110, 70, 100,-60, 360);
g.fillArc(410, 210, 100, 50,20, 360);
g.fillArc(590, 210, 100, 50,-140,360);
g.setFont(new Font(\"Times New Roman\", Font.BOLD, 20));
g.setColor(Color.MAGENTA);
g.drawString(\"This is an orange sunflower\", 450, 420);
// Flower 3
g.setColor(Color.black);
g.drawLine(850, 400, 850, 300);
g.fillOval(800, 200, 100, 100);
g.setColor(Color.green);
g.fillArc(815, 110, 70, 100,-60, 360);
g.fillArc(710, 210, 100, 50,20, 360);
g.fillArc(890, 210, 100, 50,-140,360);
g.setFont(new Font(\"Times New Roman\", Font.BOLD, 20));
g.setColor(Color.red);
g.drawString(\"This is a green flower\", 750, 420);
// Flower 4
g.setColor(Color.black);
g.drawLine(1150, 400, 1150, 300);
g.fillOval(1100, 200, 100, 100);
g.setColor(Color.red);
g.fillArc(1115, 110, 70, 100,-60, 360);
g.fillArc(1010, 210, 100, 50,20, 360);
g.fillArc(1190, 210, 100, 50,-140,360);
g.setFont(new Font(\"Times New Roman\", Font.BOLD, 20));
g.setColor(Color.black);
g.drawString(\"This is a red flower\", 1070, 420);
}
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
