0

Hi everyone, I am trying to write and application that will display a smiley face with a gray background and yellow face. This is what I have so far but it won't run. Can you please help me and show me how to get the application running? Thank you in advance.

import java.awt.Graphics;
import java.awt.Color;
import java.awt.Canvas;

public class Smileyface extends Canvas {
  public static void main(String[] args) {
    public smileyface() {
    setSize(800, 600);
    setBackground(Color.GRAY);
    setVisible(true);
  }

  public void smileyface(Graphics window) {
    smileyFace(window);
  }

  public void smileyFace(Graphics window) {
    window.setColor(Color.YELLOW);
    window.drawString("SMILEY FACE LAB ", 35, 35);

    window.setColor(Color.YELLOW);
    window.fillOval(210, 100, 400, 400); // face

    window.setColor(Color.WHITE);
    window.fillOval(290, 180, 40, 40); // left cornea
    window.fillOval(490, 180, 40, 40); // right cornea

    window.setColor(Color.BLACK);
    window.fillOval(300, 190, 20, 20); // left iris
    window.fillOval(500, 190, 20, 20); // right iris

    window.fillArc(310, 200, 200, 200, 0, -180); // smile
  }
}
}
2
Contributors
2
Replies
11
Views
4 Years
Discussion Span
Last Post by Nawaf15
0

"it won't run" ....
can you be a bit more specific about that?

EDIT:
a few hints: your constructor is wrong:
it's inside the main method, which goes against Java syntax (actually, you try to write your entire class inside your main method, which is all kinds of wrong).

it's name isn't the same as the name of your class, which is also wrong.

correct these two. the code 'll "run", it won't do what you want yet, but it'll run.

Edited by stultuske

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.