Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import command.*;
- import drawer.*;
- import java.awt.*;
- import java.awt.event.*;
- import javax.swing.*;
- public class Main extends JFrame implements ActionListener, MouseMotionListener, WindowListener {
- private MacroCommand history = new MacroCommand();
- private DrawCanvas canvas = new DrawCanvas(600, 400, history);
- private JButton clearButton = new JButton("クリア");
- public Main(String title) {
- super(title);
- this.addWindowListener(this);
- canvas.addMouseMotionListener(this);
- clearButton.addActionListener(this);
- Box buttonBox = new Box(BoxLayout.X_AXIS);
- buttonBox.add(clearButton);
- Box mainBox = new Box(BoxLayout.Y_AXIS);
- mainBox.add(buttonBox);
- mainBox.add(canvas);
- getContentPane().add(mainBox);
- pack();
- setVisible(true);
- }
- public void actionPerformed(ActionEvent e) {
- if (e.getSource() == clearButton) {
- history.clear();
- canvas.repaint();
- }
- }
- public void mouseMoved(MouseEvent e) {
- }
- public void mouseDragged(MouseEvent e) {
- Command cmd = new DrawCommand(canvas, e.getPoint());
- history.append(cmd);
- cmd.execute();
- }
- public void windowClosing(WindowEvent e) {
- System.exit(0);
- }
- public void windowActivated(WindowEvent e) {}
- public void windowClosed(WindowEvent e) {}
- public void windowDeactivated(WindowEvent e) {}
- public void windowDeiconified(WindowEvent e) {}
- public void windowIconified(WindowEvent e) {}
- public void windowOpened(WindowEvent e) {}
- public static void main(String[] args) {
- new Main("お絵かきサンプル");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement