您的位置:首页 > 产品设计 > UI/UE

Java GUI 画点

2016-03-31 15:37 573 查看


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);
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: