`

paint()与paintComponent()的区别

阅读更多

paint :由 Swing 调用,以绘制组件。此方法实际上将绘制工作委托给三个受保护的方法:paintComponent、paintBorder 和 paintChildren。按列出的顺序调用这些方法,以确保子组件出现在组件本身的顶部。子类可以始终重写此方法。只想特殊化 UI(外观)委托的 paint 方法的子类只需重写 paintComponent。

paintComponent :如果 UI 委托为非 null,则调用该 UI 委托的 paint 方法。向该委托传递 Graphics 对象的副本,以保护其余的 paint 代码免遭不可取消的更改

分享到:
评论

相关推荐

    java paintComponent 拖拽操作

    java 实现的纯paint流界面 实现了拖拽操作

    PintandoAndo:实用的paintComponent

    PintandoAndo:实用的paintComponent

    带图片背景的面板

    import javax.swing.*;... } public void paintComponent(Graphics g) { g.drawImage(myimage,0,0,myimage.getWidth(this),myimage.getHeight(this),Color.red,this); super.paintComponent(g); } }

    java开发爱心代码示例,开发代码的步骤解析

    public void paintComponent(Graphics g) { super.paintComponent(g); Graphics2D g2d = (Graphics2D) g; g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2d....

    java中透明窗口 再也不用局限于矩形窗口了

    //空布局 任意摆放 与下面的b1.setBounds(280,80,60,25);呼应 JButton b1=new JButton("exit",imagebutton); b1.addActionListener(new ActionListener(){ public void actionPerformed (ActionEvent e){ ...

    自定义Button

    自定义Button,利用paintComponent方法。

    JAVA实现贪吃蛇游戏毕业设计(源代码+论文)

    三种不同的食物在被毒液吃...在该类中通过方法paintComponent(Graphics g)来调用该类中的所有paint方法,进行绘图。 在该类中通过方法keyPressed(KeyEvent e)来调用该类中的所有Response方法,进行对键盘的监听和响应。

    基于Java Swing的推箱子游戏

    这是一个基于Java Swing的推箱子游戏。游戏界面由一个名为PushBoxGame的类实现,其中包含了游戏的迷宫布局信息以及方块的移动...游戏的绘制通过重写paintComponent方法实现。运行程序后,即可显示出推箱子游戏的界面。

    java项目-俄罗斯方块

    * paint方法实际上把绘图的主要工作委派给paintComponent方法等方法 */ public void paintComponent(Graphics g) { super.paintComponent(g); g.setColor(frontColor); for (int i = 0; i ; i++) { ...

    通讯录管理系统 Java设计 源程序

    * 重写paintComponent方法 */ public class DAO { private static DAO dao=new DAO(); // 创建DAO对象 public DAO(){ try { Class.forName("com.mysql.jdbc.Driver"); // 加载数据库驱动类 } catch ...

    Java开发的五子棋系统

    3、 DrawPanel中覆盖paintComponent方法来进行绘制。 绘制15*15网格的棋盘, 绘制前先定义边距、行数、列数、网格宽度等常量 4、 定义Chess类,包括x,y索引, 颜色。 定义构造函数和相应的get方法。 5、 在DrawPanel...

    五子棋代码

    public void paintComponent Graphics g { super paintComponent g ; Font f new Font "宋体" Font BOLD 22 ; g setFont f ; g drawString "五子棋)" 10 30 ; f new Font "楷体 ...

    draws 10 random filled shapes in random positions.

    Method paintComponent should contain a loop that iterates 10 times. In each iteration, the loop should determine whether to draw a rectangle or an oval, and choose coordinates and dimensions at ...

    Java 语言基础 —— 非常符合中国人习惯的Java基础教程手册

    定义一个类与定义一个数据类型是有区别的。在程序设计语言中,把定义数据类型的能 力作为一种很重要的能力来对待。在面向对象的语言中,类的功能更强大,这是因为类不仅 含有定义数据类型的功能,而且还包含了对方法...

    Java在窗口上加载显示GIF动画图像.rar

     public void paintComponent(Graphics g) { //重载组件绘制方法   super.paintComponent(g); //调用父类函数   images[currentImage].paintIcon(this,g,70,0); //绘制图标   currentImage=(currentImage 1)%...

    仿QQ登录窗体,拉伸展开!

    public void paintComponent(Graphics g) { g.drawImage(new ImageIcon("image\\logintop1.jpg").getImage(), 0, 0,500,48, null); super.paintComponent(g); } };//标题栏panel topPanel....

    五子棋java编写的,有点残,如果有意可以改改

    public void paintComponent(Graphics g){ super.paintComponent(g); drawGrids(g); for(int i=0;i;i++) for(int j=0;j;j++) if(chesses[i][j]!=0) drawChess(g,i,j,chesses[i][j]); } } ...

    Relogio-JAVA:具有图形界面的JAVA时钟

    看JAVA 使用PaintComponent API的JAVA时钟,用其指针绘制时钟以显示当前时间。

    模拟时钟StillClock类

    protected void paintComponent(Graphics g) { super.paintComponent(g); // Initialize clock parameters int clockRadius = (int) (Math.min(getWidth(), getHeight()) * 0.8 * 0.5); int xCenter = ...

    Java图形填充实例.rar

     super.paintComponent(g); //调用父类的绘制组件方法  Graphics2D g2D = (Graphics2D)g;  setBackground(Color.white);  setForeground(Color.black);  int charH = 16; //最大字符高度  int gridW = ...

Global site tag (gtag.js) - Google Analytics