code:
package BouncingBalls;
import java.awt.*;
import javax.swing.*;
public class Main {
public static void main(
String[] args) {
JPanel p = new JPanel();
p.setPreferredSize(new Dimension(400, 400));
p.setVisible(true);
}
}
Simply, why the JPanel is not visible when running this. Nothing appears and there are no errors.
Thanks
ANSWER:
import java.awt.*;
import javax.swing.*;
public class Main {
public static void main(String[] args) {
JFrame f = new JFrame("My Frame");
f.setDefaultCloseOperation(f.EXIT_ON_CLOSE);
JPanel p = new JPanel();
p.setPreferredSize(new Dimension(400, 400));
f.getContentPane().add(p);
f.pack();
f.setVisible(true);
}
}