Java 矩形圆形 jvjy.java

程序设计:谢山水 2003.10.1.

// 矩形圆形:线宽、颜色、分段颜色、背景色、波峰数、显示速度
// 画图方向:向左画、向右画、向上画、向下画、同时向右和向下画
// 位置:水平、垂直多条正弦波

import java.awt.*;

public class jvjy extends Frame { // 图形程序设计 jvjy 类继承框架 
public jvjy() {
setLayout(new BorderLayout()); // 设置边界布局
DrawPanel display = new DrawPanel(); // 创建画图面板实例 display
add("Center", display); // 对中加入画图面板 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[]) {
jvjy jvjy = new jvjy();
jvjy.setTitle("Java 语言图形程序设计 矩形圆形 fsxss 2003.10.1.");
jvjy.setSize(800,600);
jvjy.show();
}
}

class DrawPanel extends Panel {
public void paint(Graphics g) {

g.setColor(new Color(255,0,255));     //设置画笔为紫色
g.drawRect(5,5,780,540);              // 画图纸外边框

g.setColor(new Color(0,155,0));       //设置画笔为绿色
g.drawRect(15,15,760,520);            // 画图纸内边框
g.drawRect(16,16,758,518);
g.drawRect(17,17,756,516);
g.drawRect(18,18,754,514);

g.setColor(new Color(255,0,0));       //设置画笔为红色
g.drawRect(240,70,60,30);             // 画矩形
g.fillRect(320,70,60,30);
g.drawRoundRect(400,70,50,30,20,20);  // 画圆角矩形
g.fillRoundRect(480,70,50,30,40,30);
g.drawRoundRect(560,70,50,30,50,30);

g.setColor(new Color(0,150,0));      //设置画笔为绿色
g.drawOval(230,150,60,60);           // 画椭圆
g.fillOval(330,150,80,60);
g.drawArc(410,150,100,60,35,-140);   // 画弧
g.fillArc(510,150,100,60,35,65);

g.setColor(new Color(0,0,255));      //设置画笔为蓝色
g.drawLine(30,250,750,250);          // 画水平轴线
g.drawLine(30,251,750,251);
g.drawLine(30,252,750,252);
g.drawLine(30,253,750,253);

g.setColor(new Color(0,150,0));      //设置画笔为绿色
g.drawLine(60,300,720,300);
g.drawLine(60,302,720,302);
g.drawLine(60,304,720,304);

g.setColor(new Color(255,0,255));    //设置画笔为紫色
g.drawLine(90,350,690,350);
g.drawLine(90,353,690,353); 

g.setColor(new Color(255,155,0));    //设置画笔为橙色
g.drawLine(120,400,660,400);

g.setColor(new Color(255,0,0));      //设置画笔为红色
g.drawLine(390,410,390,412);         // 画点
g.drawLine(390,420,390,422);
g.drawLine(390,430,390,432);
g.drawLine(390,440,390,442);
g.drawLine(390,450,390,452);
g.drawLine(390,460,390,462);
g.drawLine(390,470,390,472);
g.drawLine(390,480,390,482);
}
}