D2D网络数据存储器开发全过程(6)

 

第六章:

呵,现在应该给 NetworkPanel添加一些事件,来触发右边窗口的打开了。

那么RightPanel,又该添加些什么内容呢?右边显然也应该是一个JTabbedPane,所有我们建立一个NetViewPanelContainer类来实现。我们添加一个全局的

public static NetViewPanelContainer netviewPanelContainer;

修改RightPanel的构造函数:

 

public   class  RightPanel  extends  JPanel {
    
public RightPanel(){
        
this.setLayout(new GridLayout(1,1));
        
this.add(DTDCommObj.netviewPanelContainer);
    }

}

NetViewPanelContainer先简单的继承JTabbedPane,以后慢慢修饰

 

public   class  NetViewPanelContainer  extends  JTabbedPane {
    
public NetViewPanelContainer(){
        
    }

}

现在开始给NetworkPanel中,添加的网络节点,添加双击事件,在双击的时候,触发右边添加窗口。

每一个新窗口都将是一个会话,为了给每一个会话维持一个状态,我们建立一个类来实现:

 

public   class  UserConfig  implements  Serializable {
    
public String type;
    
public String user;
    
public String password;
    
public ArrayList dirList = new ArrayList();
}

 

class  TUserConfig {
    
public UserConfig userinfo;
    
public NetworkNode obj;
    
public TUserConfig(NetworkNode obj,UserConfig userinfo){
        
this.obj = obj;
        
this.userinfo = userinfo;
    }

}

用一个NetViewPanel来实现每一个被打开的新窗口,为了便于以后插件的开发。我们希望这个窗口能够实现动态的java类加载,所以构造函数中,添加类名为参数。

 

public   class  NetViewPanel  extends  JPanel {
    
public NetViewPanel(UserConfig userinfo,String className){
        
    }

}

现在给NetworkTree的构造函数,添加鼠标双击事件:

 

this .addMouseListener( new  MouseListener() {

            
public void mouseClicked(MouseEvent arg0) {
                
// TODO Auto-generated method stub
                
//多击事件
                if(arg0.getClickCount()==2){
                    
if(curSelectUser==null){
                        
return;
                    }

                    
//System.out.println(curSelectUser);
                    if(curSelectUser.userinfo.type.equals("qq")){
                        DTDCommObj.netviewPanelContainer.addTab(curSelectUser.userinfo.user, 
new NetViewPanel(curSelectUser.userinfo,"data.QQNetDisk"));
                    }

                    
else if(curSelectUser.userinfo.type.equals("google")){
                        DTDCommObj.netviewPanelContainer.addTab(curSelectUser.userinfo.user, 
new NetViewPanel(curSelectUser.userinfo,"data.GoogleNetDisk"));
                    }

                    
else if(curSelectUser.userinfo.type.equals("163")){
                        DTDCommObj.netviewPanelContainer.addTab(curSelectUser.userinfo.user, 
new NetViewPanel(curSelectUser.userinfo,"data.M163NetDisk"));
                    }

                }

            }


            
public void mouseEntered(MouseEvent arg0) {
                
// TODO Auto-generated method stub
                
            }


            
public void mouseExited(MouseEvent arg0) {
                
// TODO Auto-generated method stub
                
            }


            
public void mousePressed(MouseEvent arg0) {
                
// TODO Auto-generated method stub
                
            }


            
public void mouseReleased(MouseEvent arg0) {
                
// TODO Auto-generated method stu
            }

            
        }
);

这时的界面:

接着该具体实现NetViewPanel了。

我们需要添加一个网络文件目录选择区,显示区,已经操作过程中的信息区。实现的代码为:

public   class  NetViewPanel  extends  JPanel {
    
private String title = "";
    
private JTextArea infoText = new JTextArea();
    
private JList fileList = new JList();
    
private JComboBox dirList = new JComboBox();
    
public NetViewPanel(UserConfig userinfo,String className){
        
this.title = userinfo.user;
        JPanel topPanel 
= new JPanel();
        topPanel.setBorder(
null);
        topPanel.setLayout(
new BorderLayout());
        dirList.setEditable(
false);
        dirList.addActionListener(
new ActionListener(){
            
public void actionPerformed(ActionEvent arg0) {
                JComboBox box 
= (JComboBox)arg0.getSource();
                box.setPreferredSize(
new Dimension(0,0));
            }

        }
);
        topPanel.add(dirList,BorderLayout.CENTER);
        
        JButton button1 
= new JButton(DTDInfo.getNetViewPanel_Refresh());
        JPanel buttonPanel 
= new JPanel();
        buttonPanel.add(button1);
        topPanel.add(buttonPanel,BorderLayout.EAST);
        
        JScrollPane tp 
= new JScrollPane(topPanel);
        tp.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
        tp.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_NEVER);
        tp.setBorder(
null);
        
this.setLayout(new BorderLayout());
        
this.add(tp,BorderLayout.NORTH);
        
        
        JPanel infoPanel 
= new JPanel();
        infoPanel.setLayout(
new GridLayout(1,1));
        infoText.setEditable(
false);
        infoPanel.add(infoText);
        JSplitPane splitPanel 
= new JSplitPane(JSplitPane.VERTICAL_SPLIT,new JScrollPane(fileList),new JScrollPane(infoPanel));
        splitPanel.setDividerSize(
2);
        splitPanel.setDividerLocation(
200);
        
this.add(splitPanel,BorderLayout.CENTER);
    }

    
}

此时的界面:

呵,再打包一个:

http://www.018008.com/v/D2D1.0_5.rar

 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值