日韩无码专区无码一级三级片|91人人爱网站中日韩无码电影|厨房大战丰满熟妇|AV高清无码在线免费观看|另类AV日韩少妇熟女|中文日本大黄一级黄色片|色情在线视频免费|亚洲成人特黄a片|黄片wwwav色图欧美|欧亚乱色一区二区三区

RELATEED CONSULTING
相關咨詢
選擇下列產品馬上在線溝通
服務時間:8:30-17:00
你可能遇到了下面的問題
關閉右側工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
控件位置可以配置的Swing桌面

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

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

首先我們定義一個位置接口,實現(xiàn)該接口的類就標示它的位置

 
 
 
 
  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  

上面的接口標示的位置見下圖:

第三:我們寫一個面板,實現(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.     }  

第四:在配置文件中配置這個類

打開配置文件按zlconfig.xml

編寫

第五:加載配置文件

我們利用Spring將配置文件中實現(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.         }  

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


標題名稱:控件位置可以配置的Swing桌面
URL網(wǎng)址:http://www.5511xx.com/article/dhdgose.html