whytho
whytho

Reputation: 33

why does the graphics on java output nothing?

Below is code I received directly from my teacher but it outputs nothing! all I see is a blank window open and nothing is displayed in it. I can not understand why please help!

import java.awt.*;
import javax.swing.*;
public class IntroToGraphics extends JFrame
{

    /**
     * 
     */
    public IntroToGraphics() {
        // TODO Auto-generated constructor stub
        super("howdy");
        setSize(1500,850);
        setVisible(true);
    }
    public void Paint(Graphics g) {
            g.drawString("Hello World",1000,450);
            g.fillRect(200,200,50,50);
    }
    public static void main (String[]args) {
        new IntroToGraphics();
    }
}

If anything isn't clear please let me know and I will fix it promptly.

Upvotes: 1

Views: 54

Answers (1)

Nipuna Priyamal
Nipuna Priyamal

Reputation: 368

The method Paint name should be paint. In addition, it is better to use @Override annotation since you have overridden the paint method.enter image description here

The Output will be

enter image description here

Upvotes: 1

Related Questions