I started experimenting with JFrame and my first task I wanted to accomplish was drawing a 50px square with the fillRect()
or drawRect()
method. Unfortunately after running, the program showed a rectangle instead of a square.
My code:
package javaapp;
import java.awt.Graphics;
import javax.swing.JFrame;
public class JavaApp extends JFrame{
public JavaApp() {
setTitle("Voorbeeld");
setSize(250, 250);
setResizable(false);
setVisible(true);
setDefaultCloseOperation(EXIT_ON_CLOSE);
}
public void paint (Graphics g){
g.fillRect(0, 0, 50, 50);
}
public static void main(String[] args) {
new JavaApp();
}
}