Advertisement
Guest User

Untitled

a guest
Apr 29th, 2017
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.70 KB | None | 0 0
  1. import command.*;
  2. import drawer.*;
  3.  
  4. import java.awt.*;
  5. import java.awt.event.*;
  6. import javax.swing.*;
  7.  
  8. public class Main extends JFrame implements ActionListener, MouseMotionListener, WindowListener {
  9.  
  10. private MacroCommand history = new MacroCommand();
  11.  
  12. private DrawCanvas canvas = new DrawCanvas(600, 400, history);
  13.  
  14. private JButton clearButton = new JButton("クリア");
  15.  
  16.  
  17. public Main(String title) {
  18. super(title);
  19.  
  20. this.addWindowListener(this);
  21. canvas.addMouseMotionListener(this);
  22. clearButton.addActionListener(this);
  23.  
  24. Box buttonBox = new Box(BoxLayout.X_AXIS);
  25. buttonBox.add(clearButton);
  26. Box mainBox = new Box(BoxLayout.Y_AXIS);
  27. mainBox.add(buttonBox);
  28. mainBox.add(canvas);
  29. getContentPane().add(mainBox);
  30.  
  31. pack();
  32. setVisible(true);
  33. }
  34.  
  35.  
  36. public void actionPerformed(ActionEvent e) {
  37. if (e.getSource() == clearButton) {
  38. history.clear();
  39. canvas.repaint();
  40. }
  41. }
  42.  
  43.  
  44. public void mouseMoved(MouseEvent e) {
  45. }
  46. public void mouseDragged(MouseEvent e) {
  47. Command cmd = new DrawCommand(canvas, e.getPoint());
  48. history.append(cmd);
  49. cmd.execute();
  50. }
  51.  
  52.  
  53. public void windowClosing(WindowEvent e) {
  54. System.exit(0);
  55. }
  56. public void windowActivated(WindowEvent e) {}
  57. public void windowClosed(WindowEvent e) {}
  58. public void windowDeactivated(WindowEvent e) {}
  59. public void windowDeiconified(WindowEvent e) {}
  60. public void windowIconified(WindowEvent e) {}
  61. public void windowOpened(WindowEvent e) {}
  62.  
  63. public static void main(String[] args) {
  64. new Main("お絵かきサンプル");
  65. }
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement