• java_简易画图板


    下面我将分享用Java制作简易画图板的过程。

    version 1

    Draw.java

    Java代码 复制代码 收藏代码
    1. import javax.swing.JFrame;   
    2.   
    3. /**  
    4.  *   
    5.  * @author yangzhenlin  
    6.  *   
    7.  */  
    8. public class Draw extends JFrame {   
    9.   
    10.     public void initDraw() {   
    11.         this.setTitle("画图板");   
    12.         this.setSize(600500);   
    13.         this.setDefaultCloseOperation(3);   
    14.         this.setVisible(true);   
    15.   
    16.         /**  
    17.          * 从窗体上获取画布对象 获取窗体在屏幕上占据的区域,这块区域是允许改变颜色的。  
    18.          */  
    19.         java.awt.Graphics g = this.getGraphics();   
    20.   
    21.         DrawListener dlis = new DrawListener(g);   
    22.   
    23.         this.addMouseListener(dlis);   
    24.     }   
    25. }  

    DrawListener.java

    Java代码 复制代码 收藏代码
    1. import java.awt.event.MouseEvent;   
    2.   
    3. /**  
    4.  *   
    5.  * @author yangzhenlin   
    6.  *   
    7.  */  
    8.   
    9. /**  
    10.  * 画板监听器,实现鼠标监听器接口  
    11.  */  
    12. public class DrawListener implements java.awt.event.MouseListener {   
    13.     // private int x1, x2, y1, y2;   
    14.     private java.awt.Graphics g;   
    15.   
    16.     public DrawListener(java.awt.Graphics g) {   
    17.         this.g = g;   
    18.     }   
    19.   
    20.     public void mouseClicked(MouseEvent e) {   
    21.         System.out.println("mouseClicked");   
    22.     }   
    23.   
    24.     public void mousePressed(MouseEvent e) {   
    25.         System.out.println("mousePressed");   
    26.     }   
    27.   
    28.     public void mouseReleased(MouseEvent e) {   
    29.         System.out.println("mouseReleased");   
    30.     }   
    31.   
    32.     public void mouseEntered(MouseEvent e) {   
    33.         System.out.println("mouseEntered");   
    34.     }   
    35.   
    36.     public void mouseExited(MouseEvent e) {   
    37.         System.out.println("mouseExited");   
    38.     }   
    39.   
    40. }  
  • 相关阅读:
    leetcode------Palindrome Number
    leetcode------Minimum Depth of Binary Tree
    leetcode------Binary Tree Level Order Traversal II
    leetcode------Plus One
    leetcode------Plus One
    leetcode------Min Stack
    leetcode------Binary Tree Level Order Traversal
    递归树与非递归树的不同实现【转载,个人感觉写的比较好的一篇,值得去思考】
    leetcode------Compare Version Numbers
    leetcode------Majority Element
  • 原文地址:https://www.cnblogs.com/bjanzhuo/p/3576038.html
Copyright © 2020-2023  润新知