小男孩‘自慰网亚洲一区二区,亚洲一级在线播放毛片,亚洲中文字幕av每天更新,黄aⅴ永久免费无码,91成人午夜在线精品,色网站免费在线观看,亚洲欧洲wwwww在线观看

分享

swing組件的paint問題_技術(shù)專輯

 軟件團(tuán)隊(duì)頭目 2007-09-11
癥狀一:調(diào)用jframe的repaint()方法時(shí)為什么不會(huì)自動(dòng)引發(fā)paintcomponent()方法?(不過會(huì)引發(fā)paint()方法)  
   
  癥狀二:引發(fā)paint()方法后,我用drawstring()方法在jframe中畫字符串,不能顯示,不過改變jframe的大小時(shí)會(huì)正確顯示。    
 
  其實(shí)repaint()方法,好像是這樣的,如果有paint()方法則調(diào)用paint()方法,沒有paint()方法  
  而有paintcomponent()方法則調(diào)用paintcomponent()方法,下面代碼就是為了測(cè)試。你可以測(cè)試有paint()方法,和注釋掉  
  paint()方法兩種情況。  
   
   
  import   javax.swing.*;  
  import   java.awt.*;  
  import   java.awt.event.mouseadapter;  
  import   java.awt.event.mouseevent;  
  import   java.awt.graphics2d;  
  public   class   testpanel   extends   jframe   {  
      ttt   panel   =   new   ttt();  
      jpanel   pnlctl   =   new   jpanel();  
      jbutton   button   =   new   jbutton("draw   line");  
      jbutton   button2   =   new   jbutton("clear   all");  
      public   testpanel()   {  
          container   cp   =   this.getcontentpane();  
          cp.add(panel,borderlayout.center);  
          button.addmouselistener(new   mouseadapter(){  
              public   void   mouseclicked(mouseevent   me)  
              {  
                  graphics2d   g2   =   (graphics2d)   panel.getgraphics();  
                  g2.drawrect(20,20,100,300);  
                  panel.repaint();  
                   
              }  
          });  
          button2.addmouselistener(new   mouseadapter(){  
              public   void   mouseclicked(mouseevent   me)  
              {  
                  panel.getgraphics().clearrect(0,0,700,400);  
              }  
          });  
          pnlctl.add(button);  
          pnlctl.add(button2);  
          cp.add(pnlctl,borderlayout.north);  
          setsize(800,600);  
          this.setdefaultcloseoperation(jframe.exit_on_close);  
          this.show();  
      }  
      public   static   void   main(string[]   args)   {  
          testpanel   testpanel   =   new   testpanel();  
      }  
  }  
  class   ttt   extends   jpanel  
  {  
      public   ttt()  
      {  
          super();  
      }  
      public   void   paintcomponent(graphics   g)  
      {  
          joptionpane.showconfirmdialog(null,"paintcomponent()   called");  
          graphics2d   g2   =   (graphics2d)   g;  
          g2.drawline(10,10,300,300);  
      }  
  //如果要試驗(yàn)沒有paint()的情況注釋掉下面的方法  
      public   void   paint(graphics   g)  
      {  
          joptionpane.showconfirmdialog(null,"paint()   called");  
          graphics2d   g2   =   (graphics2d)   g;  
          g2.drawrect(20,20,300,300);  
      }  
  }

    本站是提供個(gè)人知識(shí)管理的網(wǎng)絡(luò)存儲(chǔ)空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點(diǎn)。請(qǐng)注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊一鍵舉報(bào)。
    轉(zhuǎn)藏 分享 獻(xiàn)花(0

    0條評(píng)論

    發(fā)表

    請(qǐng)遵守用戶 評(píng)論公約

    類似文章 更多