I'm a bit new to programming right now and am trying to make Pong in java. However I'm not able to make any graphics show up.
Main Class
public class Pong1 {
public static Frame frame = new Frame();
public static Panel panel = new Panel();
public static void main(String[] args) {
initUI();
}
public static void initUI(){
frame.setLayout(new BorderLayout());
frame.add(BorderLayout.CENTER, panel);
frame.pack();
frame.setVisible(true);
}
public static int getPanelWidth(){
return panel.getWidth();
}
public static int getPanelHeight(){
return panel.getHeight();
}
}
JFrame Class
package pong1;
import java.awt.Dimension;
import javax.swing.JFrame;
public class Frame extends JFrame{
Frame(){
setTitle("Pong");
setDefaultCloseOperation(EXIT_ON_CLOSE);
setResizable(true);
setMinimumSize(new Dimension(800,500));
setLocationRelativeTo(null);
}
}
In this final class is the JPanel class where I override and call paintComponent. However, nothing shows up.
public class Panel extends JPanel{
Panel(){
setPreferredSize(new Dimension(800,500));
setMinimumSize(new Dimension(800,500));
}
@Override
protected void paintComponent(Graphics g){
super.paintComponent(g);
Graphics2D g2 = (Graphics2D) g;
g2.setColor(Color.blue);
g2.fillOval(100,100,100,100);
}
I've looked at dozens of other posts and I've tried many different things, and yet nothing shows up. Does anyone know what is going on?