I made a class called Robit (bad spelling on purpose) and it defines a square with the paint(Graphics g)
method. I'm extending JFrame and all that works fine i just cant get the squares to paint
import java.awt.*;
public class Robit {
int[] location = new int[4];
double[] vectors = new double[2];
Color mainColor;
public Robit(Color color, int x) {
mainColor = color;
switch (x) {
case 0:
location[0] = 50;
break;
case 1:
location[0] = 700;
break;
default:
location[0] = 350;
break;
}
location[1] = 400;
location[2] = 50;
location[3] = 50;
}
public void paint(Graphics g) {
g.setColor(mainColor);
g.fillRect(location[0], location[1], location[2], location[3]);
}
public int getX() {
return location[0];
}
public int getY() {
return location[1];
}
}
`thats the class im instantiating, heres where i make it import java.awt.Color; import javax.swing.*;
public class Frame extends JFrame {
public Frame(){
setLayout(null);
Robit r1 = new Robit(Color.red, 0);
Robit r2 = new Robit(Color.blue, 1);
}
}
and the main class
import javax.swing.JFrame;
public class App {
public static void main(String[] args) {
Frame f = new Frame();
f.setSize(800, 450);
f.setResizable(false);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setVisible(true);
}
}