Advertisement
hasecraft

>>Creative Commons<< programing3-8

May 28th, 2015
309
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.77 KB | None | 0 0
  1. /*
  2. Auther : Kohei Hasegawa
  3. Licence : Creative Commons
  4. */
  5.   import java.awt.*;
  6.   import java.awt.event.*;
  7.   import javax.swing.*;
  8.  
  9.   public class filename extends JPanel {
  10.     static int[][] xp = new int[20][700];
  11.     static int[][] yp = new int[20][700];
  12.     static int[] kazu = new int[20];
  13.     static int st = 0;
  14.     static int stMax = 0;
  15.     static String msg[]={"Pressed", " ", "Relesed\n"};
  16.     static int  cnt= 0;
  17.  
  18.     public filename() {
  19.       setOpaque(false);
  20.       addMouseMotionListener(new MouseMotionAdapter() {
  21.         public void mouseDragged(MouseEvent event) {
  22.           kiroku(event, 1);
  23.           repaint();
  24.         }
  25.       });
  26.  
  27.       addMouseListener(new MouseAdapter() {
  28.         public void mouseReleased(MouseEvent event) {
  29.           kiroku(event, 2);
  30.           st++;
  31.           cnt = 0;
  32.           repaint();
  33.         }
  34.  
  35.         public void mousePressed(MouseEvent event) {
  36.           kiroku(event, 0);
  37.           repaint();
  38.         }
  39.       });
  40.     }
  41.  
  42.     public void kiroku(MouseEvent event, int id) {
  43.       System.out.printf(" %5d: x=%5d, ", cnt, event.getX());
  44.       System.out.printf("y=%5d %s\n", event.getY(), msg[id]);
  45.  
  46.       xp[st][cnt] = event.getX();
  47.       yp[st][cnt] = event.getY();
  48.      
  49.       cnt++;
  50.       if(cnt >= 700){ cnt = 0; }
  51.       kazu[st] = cnt;
  52.     }
  53.    
  54.     public void paintComponent(Graphics g) {
  55.       for(int k=0; k<st; k++) {
  56.           System.out.println(" kazu["+k+"] > "+kazu[k]);
  57.           g.drawPolyline(xp[k], yp[k], kazu[k]);
  58.       }
  59.     }
  60.     public static void main(String[] args) {
  61.       JFrame app = new JFrame("Display Name");
  62.       app.add(new filename());
  63.       app.setSize(300, 300);
  64.       app.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  65.       app.setVisible(true);
  66.     }
  67.   }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement