av激情亚洲男人的天堂国语,日韩欧美精品一中文字幕,无码av一区二区三区无码,国产又色又爽又刺激的a片,国产又色又爽又刺激的a片

控件位置可以配置的Swing桌面

用過Wordpress或者Joomla的朋友一定對(duì)他們的靈活的頁面布局印象深刻。在Joomla中,你可以將一個(gè)控件,放在頁面的任何一個(gè)位置,例如:左邊,右邊,菜單,底部等等。

所以我也嘗試著在Swing桌面上實(shí)現(xiàn)類似的功能,思考以后發(fā)現(xiàn)其實(shí)swing實(shí)現(xiàn)這種功能比利用html頁面實(shí)現(xiàn)該功能還簡單。

首先我們定義一個(gè)位置接口,實(shí)現(xiàn)該接口的類就標(biāo)示它的位置

 
 
 
 
  1. public interface Arrange {  
  2.       
  3.     public String getComponentName();  
  4.  

第二:繼承Arrange 接口,定義不用的位置接口,分別有

 
 
 
 
  1. public interface ArrangeBottom extends Arrange  
  2. public interface ArrangeLeft extends Arrange  
  3. public interface ArrangeLogo extends Arrange  
  4. public interface ArrangeMainBottom extends Arrange  
  5. public interface ArrangeMenuBar extends Arrange  
  6. public interface ArrangeRight extends Arrange  
  7. public interface ArrangeToolBar extends Arrange  

上面的接口標(biāo)示的位置見下圖:

第三:我們寫一個(gè)面板,實(shí)現(xiàn)位置接口

例如:public class ZPanel extends JPanel implements ArrangeRight

 
 
 
 
  1. protected void paintComponent(Graphics g) {  
  2.         if (null != wallpaper) {  
  3.             processBackground(g);  
  4.         }  
  5.         System.out.println("f:paintComponent(Graphics g)");  
  6.     }  
  7.  
  8.     public void setBackground() {  
  9.         wallpaper = new javax.swing.ImageIcon(getClass()  
  10.                 .getResource("/com/peraglobal/workspace/initcompt/picpanel/kutoku.jpg"));  
  11.         this.repaint();  
  12.     }  

第四:在配置文件中配置這個(gè)類

打開配置文件按zlconfig.xml

編寫

第五:加載配置文件

我們利用Spring將配置文件中實(shí)現(xiàn)了某一接口的類全部拿出,并且加載到指定的位置:

 
 
 
 
  1. Map lefts = context.getBeansOfType(ArrangeLeft.class);  
  2.         ArrangeLeft agLeft;  
  3.  
  4.         leftPanel.setLayout(new BorderLayout());  
  5.         JTabbedPane tabLeft = new JTabbedPane();  
  6.  
  7.         leftPanel.add(tabLeft);  
  8.  
  9.         Iterator it = lefts.entrySet().iterator();  
  10.         while (it.hasNext()) {  
  11.             Map.Entry entry = (Map.Entry) it.next();  
  12.             Object key = entry.getKey();  
  13.  
  14.             Class newClass = Class.forName((String) key);  
  15.             agLeft = (ArrangeLeft) newClass.newInstance();  
  16.             tabLeft.add((Component) agLeft, agLeft.getComponentName());  
  17.         }  

第六:我們看到我們剛才寫的一個(gè)Panel已經(jīng)加載到了右邊的面板中


網(wǎng)頁標(biāo)題:控件位置可以配置的Swing桌面
當(dāng)前URL:http://uogjgqi.cn/article/dhdgose.html
掃二維碼與項(xiàng)目經(jīng)理溝通

我們在微信上24小時(shí)期待你的聲音

解答本文疑問/技術(shù)咨詢/運(yùn)營咨詢/技術(shù)建議/互聯(lián)網(wǎng)交流