?? simpledraw.java
字號:
//SimpleDraw
import java.awt.*;
import javax.swing.*;
public class SimpleDraw
{
public static void main(String[] args)
{
DrawFrame frame = new DrawFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.show();
}
}
class DrawFrame extends JFrame
{
public DrawFrame()
{
setTitle("簡單圖形繪制");
setSize(WIDTH, HEIGHT);
// 將panel加入到frame
DrawPanel panel = new DrawPanel();
Container contentPane = getContentPane();
contentPane.add(panel);
}
public static final int WIDTH = 300;
public static final int HEIGHT = 200;
}
class DrawPanel extends JPanel
{
public void paintComponent(Graphics g)
{
super.paintComponent(g);
int x1 = 50;
int y1 = 50;
int x2 = 50;
int y2 = 150;
int radius = 100; //半徑
int startAngle = - 90; //起始角度
int arcAngle = 180; //弧的角度
//畫線
g.drawLine(x1, y1, x2, y2);
//畫弧
g.drawArc(x1 - radius / 2 , y1 ,
radius, radius, startAngle, arcAngle);
Polygon p = new Polygon();
x1 += 150;
y1 += 50;
radius /= 2;
int i;
for (i = 0; i < 6; i++)
p.addPoint(
(int)(x1 + radius * Math.cos(i * 2 * Math.PI / 6)),
(int)(y1 + radius * Math.sin(i * 2 * Math.PI / 6)));
//畫六邊形
g.drawPolygon(p);
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -