📄 drawtest.java
字号:
import java.awt.*;public class DrawTest extends Frame { public DrawTest() { setLayout(new BorderLayout()); DrawPanel display = new DrawPanel(); add("Center", display); } public boolean handleEvent(Event e) { switch (e.id) { case Event.WINDOW_DESTROY: System.exit(0); return true; default: return false; } } public static void main(String args[]) { DrawTest drawTest = new DrawTest(); drawTest.setTitle("画图程序"); drawTest.setSize(500,300); drawTest.show(); }}class DrawPanel extends Panel { public void paint(Graphics g) { g.drawLine(10,10,30,30); // 画线 g.drawLine(15,20,15,20); // 画点 g.drawRect(40,10,60,30); // 画矩形 g.fillRect(120,10,60,30); g.drawRoundRect(200,10,50,30,20,20); // 画圆角矩形 g.fillRoundRect(280,10,50,30,40,30); g.drawRoundRect(360,10,50,30,50,30); g.draw3DRect(20,60,80,60,true); // 画立体矩形 g.fill3DRect(120,60,80,60,false); int Poly1_x[]={230,263,315,272,267}; int Poly1_y[]={60,40,115,94,126}; int Poly1_pts=Poly1_x.length; int Poly2_x[]={380,413,465,422,417}; int Poly2_y[]={60,40,115,94,126}; int Poly2_pts=Poly2_x.length; g.drawPolygon(Poly1_x,Poly1_y, Poly1_pts); g.fillPolygon(Poly2_x,Poly2_y, Poly2_pts); g.drawOval(30,150,60,60); // 画椭圆 g.fillOval(130,150,80,60); g.drawArc(210,150,100,60,35,-140); // 画弧 g.fillArc(310,150,100,60,35,65); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -