📄 drawpolygon.java
字号:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class DrawPolygon extends JFrame {
public DrawPolygon (){
super( " Draw Polygon " );
setSize( 280, 235 );
setVisible( true );
}
public void paint( Graphics g ){
super.paint(g);
int xValues[] = { 10, 20, 50, 30, 20, 15 };
int yValues[] = { 50, 50, 60, 80, 80, 60 };
Polygon polygon1 = new Polygon( xValues, yValues, 6 );
g.drawPolygon( polygon1 );
int xValues2[] = { 70, 90, 100, 80, 70, 65, 60 };
int yValues2[] = { 80, 100, 110, 140, 130, 110, 90 };
g.drawPolyline( xValues2, yValues2, 7 );
int xValues3[] = { 120, 130, 150, 190 };
int yValues3[] = { 40, 70, 80, 60 };
g.fillPolygon( xValues3, yValues3, 4 );
Polygon polygon2 = new Polygon();
polygon2.addPoint( 165, 135 );
polygon2.addPoint( 175, 150 );
polygon2.addPoint( 270, 200 );
polygon2.addPoint( 200, 220 );
polygon2.addPoint( 130, 180 );
g.fillPolygon( polygon2 );
}
public static void main( String args[] ){
DrawPolygon app = new DrawPolygon ();
appDefaultCloseOperation(JFrame.EXIT_ON_CLOSE );
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -