码迷,mamicode.com
首页 > 编程语言 > 详细

Java GUI 画点

时间:2016-03-31 16:53:51      阅读:202      评论:0      收藏:0      [点我收藏+]

标签:

技术分享

import java.awt.EventQueue;


public class Paint {

    private JFrame frame;

    /**
     * Launch the application.
     */
    public static void main(String[] args) {
        EventQueue.invokeLater(new Runnable() {
            public void run() {
                try {
                    Paint window = new Paint();
                    window.frame.setVisible(true);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        });
    }

    /**
     * Create the application.
     */
    public Paint() {
        initialize();
    }

    /**
     * Initialize the contents of the frame.
     */
    private void initialize() {
        frame = new JFrame();
        frame.getContentPane().addMouseMotionListener(new MouseMotionAdapter() {
            @Override
            public void mouseDragged(MouseEvent e) {
                
                Graphics g = frame.getGraphics();
//                g.drawLine(0,0, e.getX(), e.getY());
                g.fillRect(e.getX()+7, e.getY()+30, 3, 3);
            }
        });
        frame.setBounds(100, 100, 450, 300);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }
}

 

Java GUI 画点

标签:

原文地址:http://www.cnblogs.com/AndyHoo/p/5341406.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!