gpt4 book ai didi

java - drawOval 的意外行为

转载 作者:太空宇宙 更新时间:2023-11-04 13:00:47 24 4
gpt4 key购买 nike

我遇到了drawOval函数的问题。我用它来画圆,但结果看起来不像圆。我认为这种行为是在 Jpanel 达到一定高度后发生的。向下滚动直到最后,您可以得到如下图所示的结果。有谁能解释一下吗?

Result after Execute the sample program

import java.awt.*;
import java.awt.geom.*;
import javax.swing.*;

public class TestMain
{
public static void main(String[] args)
{
JFrame f = new JFrame();
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JScrollPane jsp = new JScrollPane();
jsp.setViewportView(new TestPanel());
f.getContentPane().add(jsp);
f.setSize(500,400);
f.setLocation(200,200);
f.setVisible(true);
}
}

class TestPanel extends JPanel
{
public TestPanel()
{
setPreferredSize(new Dimension(1960 , 77660240));
setBackground(Color.white);
}

protected void paintComponent(Graphics g)
{
super.paintComponent(g);
Graphics2D g2 = (Graphics2D)g;
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
g2.drawRect(30, 77660141, 100, 20);
g2.drawOval(15, 77660141, 10, 10);
g2.draw(new Ellipse2D.Double(140, 77660141,
10,
10));
g2.draw(new Ellipse2D.Double(160, 77660141,
10,
10));
g2.draw(new Ellipse2D.Double(180, 77660141,
10,
10));
g2.draw(new Ellipse2D.Double(200, 77660141,
30,
30));
}
}

最佳答案

将面板的尺寸更改为更合理的值,例如:1000,它将正常工作。

关于java - drawOval 的意外行为,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34962845/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com