我以this example to draw polygons为基础制作了自己的多边形抽屉,但保留了最重要的部分:
public class Main extends JPanel {
public void paintComponent(Graphics g) {
super.paintComponent(g);
// polygon maker
}
public static void main(String[] args) {
JFrame frame = new JFrame();
frame.setTitle("DrawPoly");
frame.setSize(1000, 1000);
frame.setLocationRelativeTo(null);
frame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
Container contentPane = frame.getContentPane();
contentPane.add(new Main());
frame.show();
}
}
我发现,如果多边形的坐标值为负,则它们会从屏幕上消失,而我看不到它们的整体。为此,我想象到某种滚动或缩放到在主内部创建的JFrame或内容窗格的某种方式。如何使用链接的代码作为基础实现简单的滚动?
我发现如果多边形的坐标值为负,则它们会从屏幕上消失