java.awt.component.repaint()

repaint

public void repaint()Repaints this component.

If this component is a lightweight component, this method causes a call to this component's paint method as soon as possible. Otherwise, this method causes a call to this component's update method as soon as possible.

Note: For more information on the paint mechanisms utilitized by AWT and Swing, including information on how to write the most efficient painting code, see Painting in AWT and Swing.


Since:
JDK1.0
See Also:
update(Graphics)
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
设计一个简单的画图程序,即使用鼠标绘图。该应用程序窗体标题为“Drag to draw”。 (1)本题源程序: import java.awt.*; import java.awt.event.*; import javax.swing.*; public class Dragtodraw extends JPanel implements MouseMotionListener { ​int xval = 0, yval = 0; ​JFrame frame; ​public static void main(String args[]) { ​​Dragtodraw A = new Dragtodraw(); ​​A.go(); ​} ​public void go() { ​​frame = new JFrame(); ​​frame.setSize(300, 200); ​​【代码11】 // 设置窗体标题为"Drag to draw" ​​frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); ​​frame.setContentPane(this); // 把当前JPanel对象设置成为frame的内容面板 ​​【代码22】 // 将当前对象注册为它的鼠标运动监听器(MotionListener) ​​frame.setLocationRelativeTo(null); ​​frame.setVisible(true); ​} ​public void paintComponent(Graphics g) { ​​if (xval == 0 && yval == 0) { ​​​super.paintComponent(g);// 清空画布并准备绘制新的内容 ​​} else { ​​​【代码3】// 设置画笔颜色为蓝色 ​​​【代码4】 // 绘制圆点,原点半径为4像素 ​​} ​} ​@Override ​public void mouseDragged(MouseEvent e) { ​​【代码55】 // 获取鼠标的X坐标 ​​【代码66】 // 获取鼠标的Y坐标 ​​/* ​​ * repaint()是重绘component的方法 component中已有的图形发生变化后不会立刻显示,须使用repaint方法 ​​ */ ​​repaint(); ​} ​@Override ​public void mouseMoved(MouseEvent e) {} }
05-29

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值