java不規則表單的構建

來源:互聯網
上載者:User
 

不規則表單的大體構建思路與以前沒有什麼不同,在這裡,我僅陳述在java中怎樣實現它。本次內容在eclipse平台下開發,需要swt 的外掛程式,可以到swt的官方網站www.swt-designer.com去下載。先說一下思路吧:先載入一幅圖片,這幅圖片具有不規則特性,然後將這幅圖片設定為表單的背景,這樣就算完蛋。 載入圖片靠以下代碼來完成 public Image getImage(Display display){       InputStream is = ImageLoad. class.getResourceAsStream( this.IMAGE_NAME);       Image result = null;        try {            if (is != null) {                ImageData imageData = new ImageData(is);                if ( imageData != null) {                   result = new Image(display, imageData);                }            }        } catch (Exception e) {            e.printStackTrace();        } finally {            try {                if(is != null)                    is.close();            } catch (IOException e1) {             e1.printStackTrace();            }        }        return result;    }其中,ImageLoad. class.getResourceAsStream( this.IMAGE_NAME)的ImageLoad為方法所屬的類, this.IMAGE_NAME為圖片的名稱。這樣就返回一個圖片。設定表單的背景圖片則靠以下代碼來實現://載入圖片       image = new ImageLoad().getImage(display);       //region代表地區,以下代碼要求構造地區       Region region = new Region();       imageData = image.getImageData();       //區分image是α還是β像素       if (imageData.alphaData != null) {           for ( int y = 0; y < imageData.height; y++) {              for ( int x = 0; x < imageData.width; x++) {                  if (imageData.getAlpha(x, y) ==255) {                     region.add(imageData.x + x,imageData.y + y,1,1);                  }              }           }       } else {           ImageData mask = imageData.getTransparencyMask();           for ( int y = 0; y < mask.height; y++) {              for ( int x = 0; x < mask.width; x++) {                  if (mask.getPixel(x, y) !=0 ) {                     region.add(imageData.x + x,imageData.y + y,1,1);                  }              }           }       }       shell.setRegion(region);       shell.setSize(imageData.x + imageData.width, imageData.y              + imageData.height);注釋中的詳解已經解釋得比較明白了,我就不多說了。不規則表單就這樣構建完畢。但是還需要給表單設定表單拖拽重繪製的功效,這樣才能實現一般表單的功能,這就需要你對shell表單添加一些監聽器,用於處理表單重繪、滑鼠拖拽、表單關閉的事件方法。原始碼可以到http://download.csdn.net/user/lejuo/下載

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.