import java.awt.Frame;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
//============================================================================== 主函数
public class EditorTh {
public static void main(String args[]) {
Myframe mf = new Myframe(); // Myframe是自己设计的继承 Frame 的类
mf.setSize(new Dimension(800, 600)); // 设定显示的范围
mf.setVisible(true); // 设定 自定义的 Myframe为可视
}
}
// ============================================================================
class Myframe extends JFrame implements ActionListener, MouseListener,
MouseMotionListener // 继承 几个屏幕响应的接口
{
private Label label1 = new Label(" "); // 屏幕的元素
private Label label2 = new Label("选择图形");
private Choice choice1 = new Choice();
private Checkbox checkbox1 = new Checkbox();
private Button button1 = new Button("选择颜色");
private Button button2 = new Button("清除");
Image img; // 构造一个 image类用来引入图形
Graphics g; // 构造一个 Graphics类对象 g用来画图
Point p = new Point(40, 100);// 点类,用来定位坐标
Myframe() // Myframe的构造函数
{
super("图形编辑器"); // 标题
setLayout(new FlowLayout()); // 定义默认的 flowlayout
choice1.setForeground(Color.blue); // 选择画点的框中的前景色为蓝
checkbox1.setLabel("填充");
// --------------------------------------------------------------------------=
setBackground(Color.white); // myframe的默认的 背景色
choice1.add("点");
choice1.add("直线");
choice1.add("曲线");
choice1.add("矩形");
choice1.add("圆");
button1.addActionListener(this); // 注册监听
button2.addActionListener(this);
addMouseListener(this);
addMouseMotionListener(this);
addWindowListener(new closeWin());// 注意,这是关闭窗口的函数
label1.setSize(100, 50);