我嘗試使用JPanel 的子類在屏幕上顯示填充的橢圓形,當我嘗試使用FlowLayout將此子類的對象添加到JFrame時,橢圓形顯示不正確我不'不知道問題是什麼。請問你能幫幫我嗎?使用FlowLayout將JPanel添加到JFrame
這裏是我的代碼
@Override
protected void paintComponent(Graphics g) {
super.paintComponent(g);
g.setColor(Color.BLACK);
g.fillOval(0, 0, 50, 50);
}
在主
JFrame frame = new JFrame("Ball");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(300,300);
frame.setVisible(true);
frame.setLocationRelativeTo(null);
frame.setLayout(new FlowLayout());
BallPanel ball = new BallPane();
frame.add(ball);