Jump to content

Noob Question: How do you get Java Graphics to work?

Coolmaster
Go to solution Solved by Coolmaster,

Ok I figured it out myself. Followed this guide 

 

I'm just testing out how 2D graphics work in Java, and I'm following this https://docs.oracle.com/javase/tutorial/2d/overview/rendering.html to just try out some of the methods and I can't get it to work.

 

Here's my code:

package com.company;
import java.awt.Graphics2D;

public class Main {

    public static void main(String[] args) {
        public void paint (Graphics g) {
            Graphics2D g2 = (Graphics2D) g;
        }
        g.drawString("Hello", 10, 10);
    }

}

I get the error "illegal start of expression 7:9", and I don't know what that means.

 

I'm using IntelliJ and there is an error after "paint" and the "g" after it. And  "Graphics g" is red and wherever "g" is it is also red, and when you hover over it, it says "Cannot resolve symbol 'g'".

 

This is probably a stupid question but how do you get it to work?

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×