﻿// MyGraph100.java                                              2003.05.19
//                                                              2003.05.04
//                                                      by M.Yanaka
//      正方形または円を描く（２個のButtonを用いて切り替える）

import  java.awt.*;
import  java.awt.event.*;

public class MyGraph100 extends Frame implements ActionListener {

        int sw;
        Button bt1, bt2;

        public MyGraph100(String title) {
                super(title);
                setSize(512,512);
                setBackground(Color.white);
                setLayout(new FlowLayout(FlowLayout.LEFT));

                sw = 0; // set rectangle

                bt1 = new Button("正方形");
                bt1.addActionListener(this);
                add(bt1);
                bt2 = new Button("円");
                bt2.addActionListener(this);
                add(bt2);

                addWindowListener(new MyWindowAdapter());
                setVisible(true);
        }

        public static void main(String argv[]) {
                MyGraph100 app = new MyGraph100("円と正方形(MyGraph100)");
        }

        public void paint(Graphics g) {
                super.paint(g);
                if (sw == 0)
                        g.drawRect(156, 156, 201, 201);
                else
                        g.drawOval(156, 156, 201, 201);
        }

        public void actionPerformed(ActionEvent evt) {
                if (evt.getSource() == bt1)
                        sw = 0;
                else 
                        sw = 1;
                repaint();
        }

        class MyWindowAdapter extends WindowAdapter {
                public void windowClosing(WindowEvent evt) {
                        dispose();
                }
                public void windowClosed(WindowEvent evt) {
                        System.exit(0);
                }
        }
}
