【发布时间】:2013-04-18 14:32:31
【问题描述】:
我正在尝试使用 JPanel 的子类在屏幕上显示一个填充的椭圆 当我尝试将此子类的对象添加到带有 FlowLayout 的 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);
【问题讨论】:
标签: java swing jframe jpanel flowlayout