<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

      1 ////////////////////////////////////////////////////////////////////////////////////
      2 //
      3 // 文件名: nButton.java
      4 //
      5 // 功  能: 自定義按鈕
      6 //
      7 // 備  注: 按鈕設(shè)置大小時,應(yīng)比實際圖片大小寬1、高1象素。
      8 //
      9 /////////////////////////////////////////////////////////////////////////////////////
     10 import java.awt.*;
     11 import java.awt.geom.*;
     12 import javax.swing.*;
     13 import java.io.*;
     14 
     15 public class nButton extends JButton
     16 {
     17     
     18     Image img;
     19     public Color back;
     20     ImageIcon icon = new ImageIcon ();
     21     public nButton()
     22     {
     23         super ();
     24         Dimension size = getPreferredSize ();
     25         size.width = size.height = Math.max (size.width, size.height);
     26         setPreferredSize (size);
     27         //這個調(diào)用使JButton不畫背景,而允許畫一個圓的背景。
     28         setContentAreaFilled (false);
     29     }
     30     
     31     
     32     public nButton(String label)
     33     {
     34         super (label);
     35         // 這些聲明把按鈕擴(kuò)展為一個圓而不是一個橢圓。
     36         Dimension size = getPreferredSize ();
     37         size.width = size.height = Math.max (size.width, size.height);
     38         setPreferredSize (size);
     39         
     40         //這個調(diào)用使JButton不畫背景,而允許我們畫一個圓的背景。
     41         setContentAreaFilled (false);
     42     }
     43     
     44     // 畫圓的背景和標(biāo)簽
     45     protected void paintComponent (Graphics g)
     46     {
     47         if (getModel ().isArmed ())
     48         {
     49             
     50             // 可以選一個高亮的顏色作為圓形按鈕類的屬性
     51             g.setColor (back);
     52         }
     53         else
     54         {
     55             g.setColor (back);
     56         }
     57         g.fillRect (00, getSize ().width, getSize ().height);
     58         
     59         //這個調(diào)用會畫一個標(biāo)簽和焦點矩形。
     60         super.paintComponent (g);
     61     }
     62     
     63     
     64     public void setImageIcon (Image img)
     65     {
     66         this.img = img;
     67     }
     68     
     69     // 用簡單的弧畫按鈕的邊界。
     70     protected void paintBorder (Graphics g)
     71     {
     72         //g.setColor(back);
     73         //g.drawRect(-1, -1, getSize().width + 1 , getSize().height + 1);
     74     }
     75     
     76     
     77     // 偵測點擊事件
     78     Shape shape;
     79     public boolean contains (int x, int y)
     80     {
     81         // 如果按鈕改變大小,產(chǎn)生一個新的形狀對象。
     82         if (shape == null ||
     83                 !shape.getBounds ().equals (getBounds ()))
     84         {
     85             shape = new Ellipse2D.Float (00, getWidth (), getHeight ());
     86         }
     87         return shape.contains (x, y);
     88     }
     89     ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
     90     //下面都是測試代碼
     91     public void init ()
     92     {
     93        icon = new ImageIcon (getClass ().getResource ("clear1.jpg"));
     94        this.setIcon((Icon) icon) ;
     95        icon = new ImageIcon (getClass ().getResource ("clear2.jpg"));
     96        this.setRolloverIcon((Icon) icon);
     97        this.setPressedIcon ((Icon) icon);
     98         //return icon;
     99     }
    100     public static void main (String args[])
    101     {
    102         JFrame frame = new JFrame ("test");
    103         frame.setLayout(null);
    104         nButton btn = new nButton();
    105         btn.init();
    106        btn.back = frame.getContentPane ().getBackground () ;
    107         btn.setToolTipText ("test");
    108         btn.setBounds (100,100 ,62,21) ;
    109         frame.add (btn);
    110         frame.setSize (300,300);
    111         frame.setVisible (true);
    112         frame.setDefaultCloseOperation (3);
    113     }
    114     
    115 }
    116 
    117 
    posted on 2007-02-06 16:58 -274°C 閱讀(389) 評論(0)  編輯  收藏 所屬分類: JAVA

    常用鏈接

    留言簿(21)

    隨筆分類(265)

    隨筆檔案(242)

    相冊

    JAVA網(wǎng)站

    關(guān)注的Blog

    搜索

    •  

    積分與排名

    • 積分 - 914507
    • 排名 - 40

    最新評論

    主站蜘蛛池模板: 亚洲不卡1卡2卡三卡2021麻豆| 久久精品国产精品亚洲蜜月| 狠狠色伊人亚洲综合网站色 | 亚洲人妖女同在线播放| 中文字幕免费高清视频| 亚洲成电影在线观看青青| 114级毛片免费观看| 67194在线午夜亚洲| 免费视频中文字幕| 免费一级特黄特色大片| 中文字幕亚洲电影| 99精品视频在线免费观看| 亚洲欧洲精品久久| 在线观看免费为成年视频| 国产亚洲男人的天堂在线观看| 亚洲人妻av伦理| 久久国产精品免费专区| 亚洲乱码中文字幕小综合| 免费观看一级毛片| 久久www免费人成精品香蕉| 亚洲精品成人av在线| 91免费精品国自产拍在线不卡| 亚洲无码一区二区三区| 亚洲精品综合久久| 免费精品无码AV片在线观看| 亚洲色欲色欲www在线播放| 亚洲成a人一区二区三区| 99精品视频免费观看| 亚洲国产成人久久一区二区三区| 亚洲av无码天堂一区二区三区| 免费一级不卡毛片| 精品久久久久久亚洲中文字幕| 亚洲熟妇无码八AV在线播放| 久草视频免费在线观看| 一进一出60分钟免费视频| 亚洲精品国产第1页| 国产免费爽爽视频免费可以看| 免费成人高清在线视频| 国内精品久久久久影院亚洲| 亚洲日韩av无码| 日韩伦理片电影在线免费观看|