jeudi 9 février 2017

Relation and implementation of Graphics and paint?

Vote count: 0

The Problem: I am having trouble with the Graphics class and paint(). Nothing displays when I run this code. I need help understanding the Graphics() object and how to use the paint() method. I don't understand why nothing is showing up here.

My Context: I used to work in Processing, but I haven't coded in a while. Now I'm getting back to it and starting to learn Java, so I'm pretty new and learning as I go.

package colorschemegen;

import java.awt.Graphics;
import java.awt.Color;
import javax.swing.JFrame;
import static javax.swing.JFrame.EXIT_ON_CLOSE;

public class ColorSchemeGen {
    JFrame window= new JFrame("Color Scheme Generator");

    public ColorSchemeGen() {
        window.setTitle("Color Scheme Generator");
        window.setSize(600,600);
        window.setVisible(true);
        window.setDefaultCloseOperation(EXIT_ON_CLOSE);
    }

    public void paint(Graphics g){
        int w = (window.getWidth())/5;
        g.setColor(Color.getHSBColor(100,100,100));
        g.fillRect(100,100,200,200);
    }


   public static void main(String[] args) {
       ColorSchemeGen t= new ColorSchemeGen();
       t.paint(null);
   }

}

asked 13 secs ago

Let's block ads! (Why?)



Relation and implementation of Graphics and paint?

Aucun commentaire:

Enregistrer un commentaire