import java.awt.*;import javax.swing.*;public class ht extends JFrame{Wdmb mb=null;public static void main(String[] args){ht lx=new ht();System.out.println("123");}public ht(){mb=new Wdmb();this.add(mb);this.setSize(400,300);this.setLocation(300,280);this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);this.setVisible(true);for(int i=0;i<20;i++){this.repaint();System.out.println("11111111111");}}}class Wdmb extends JPanel{public void paint(Graphics g){int b = 0;System.out.println(b);b++;}}
2 回答
波斯汪
TA贡献1811条经验 获得超4个赞
你的这个repaint 方法不刷新子view 的 视图;
我给你贴出来 方法的内部实现 ;
只刷新你的ht类 的view
/** * Repaints this component. * <p> * If this component is a lightweight component, this method * causes a call to this component's <code>paint</code> * method as soon as possible. Otherwise, this method causes * a call to this component's <code>update</code> method as soon * as possible. * <p> * <b>Note</b>: For more information on the paint mechanisms utilitized * by AWT and Swing, including information on how to write the most * efficient painting code, see * <a href="http://www.oracle.com/technetwork/java/painting-140037.html">Painting in AWT and Swing</a>. * * @see #update(Graphics) * @since JDK1.0 */ public void repaint() { repaint( 0 , 0 , 0 , width, height); } |
添加回答
举报
0/150
提交
取消