简单点的java_java实现简单画图功能(简单点的) 爱问知识人

import javax。swing。*;import t。*;import t。event。*;public class HuaTu extends JPanel implements MouseListener, MouseMotionListener, ActionListener{ private JFrame f; private int xBegin=0,yBegin=0,xEnd=0,yEnd=0;//开始和结束点坐标 private JButton butLine,butRect,butOval,butPen,butEraser;//线,方,圆,笔,橡皮 private JToolBar tb; public HuaTu() { f = new JFrame("画图板"); butLine = new JButton("\"); butRect = new JButton("□"); butOval = new JButton("○"); butPen = new JButton("Pen"); butEraser = new JButton("Eraser"); tb = new JToolBar(); d(butLine); d(butRect); d(butOval); d(butPen); d(butEraser); dActionListener(this); dActionListener(this); dActionListener(this); dActionListener(this); dActionListener(this); tLayout(new BorderLayout()); d(tb,BorderLayout。

NORTH); dMouseListener(this); dMouseMotionListener(this); d(this); tBounds(100,100,600,500); tVisible(true); } public void paintComponent(Graphics g) { //手工强制清空面板 intComponent(g); g。

drawLine(xBegin,yBegin,xEnd,yEnd); } public static void main(String args[]) { new HuaTu(); } public void mouseClicked(MouseEvent e) { } public void mousePressed(MouseEvent e) {//按下鼠标的时候,记录开始点的坐标 this。

xBegin = tX(); this。yBegin = tY(); } public void mouseReleased(MouseEvent e) { } public void mouseDragged(MouseEvent e) {//记录拖动的时候的结束点 this。

xEnd = tX(); this。yEnd = e。

getY(); //每次拖动,都需要重绘面板,显示最的图形 paint(); } public void mouseEntered(MouseEvent e) { } public void mouseExited(MouseEvent e) { } public void mouseMoved(MouseEvent e) { } /** * Method actionPerformed * * * @param e * */ public void actionPerformed(ActionEvent e) { // TODO: Add your code here }}。

全部

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值