Andy 胡

导航

Java GUI 画点

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.setColor(Color.BLUE);

//                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);
    }
}

 

posted on 2016-03-31 15:37  talkwah  阅读(751)  评论(0编辑  收藏  举报