⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 filesharingpanel.java

📁 基于P2P框架的使用CMS编写的文件共享系统
💻 JAVA
字号:
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;

import javax.swing.border.Border;

import net.jxta.peergroup.PeerGroup;
public class FilesharingPanel extends JPanel implements ActionListener 
{
	private static final long serialVersionUID = 6783365537817417664L;
	
	DownloadPanel downloadPanel=new DownloadPanel();
	SharePanel sharePanel=new SharePanel(StartService.getNetPeerGroup());
    ImageIcon img1 = new ImageIcon("download.png"); 
    ImageIcon img2 = new ImageIcon("share.png");
    JPanel jPanel1 = new JPanel();
    JButton download = new JButton();
    JButton share = new JButton();
    Border border = download.getBorder();
    
    public FilesharingPanel() 
    {
        try 
        {
        	this.setLayout(new BorderLayout());
            this.setBackground(Color.white);
            this.setBounds(3,50,560,400);
            jPanel1.setBorder(BorderFactory.createEtchedBorder());
            jPanel1.setPreferredSize(new Dimension(10, 38)); //如果 preferredSize 已设置为一个非 null 值,则返回该值
            jPanel1.setLayout(null);   //设置此容器的布局管理器
            jPanel1.add(share);
            jPanel1.add(download);
            
            download.setBounds(new Rectangle(45, 1, 36, 36));
            download.setBorder(null);
            download.setBorderPainted(true);
            download.setContentAreaFilled(false);
            download.setFocusPainted(false);
            download.setHorizontalTextPosition(SwingConstants.CENTER);
            download.setIcon(img1);
            download.setMargin(new Insets(2, 14, 2, 14));
            download.setText("");
            download.setVerticalTextPosition(SwingConstants.CENTER);
          
            share.setBounds(new Rectangle(5, 1, 36, 36));
            share.setBorder(null);
            share.setContentAreaFilled(false);
            share.setFocusPainted(false);
            share.setHorizontalTextPosition(SwingConstants.CENTER);
            share.setIcon(img2);
            share.setMargin(new Insets(2, 14, 2, 14));
            share.setText("");
            share.setVerticalTextPosition(SwingConstants.CENTER);
            
          
            this.add(jPanel1, java.awt.BorderLayout.NORTH);       
            download.addActionListener(this);
            share.addActionListener(this); 
            this.add(downloadPanel);
            
                
        } 
        catch (Exception exception) 
        {
            exception.printStackTrace();
        }
    }
    
    public void actionPerformed(ActionEvent e)
    {
    	
    	if(e.getSource()==download)
    	{      		
    		this.remove(sharePanel);  
    		this.add(downloadPanel);
    		this.updateUI();
    		this.validate(); 
    		/*使用 validate 方法会使容器再次布置其子组件。
    		 * 已经显示容器后,在修改此容器的子组件的时候
    		 * (在容器中添加或移除组件,或者更改与布局相关的信息)
    		 * ,应该调用上述方法。*/ 
    	}
    	else if(e.getSource()==share)
    	{                 
            //sharePanel=new SharePanel(StartService.getNetPeerGroup());
            this.remove(downloadPanel); 
            this.add(sharePanel);
            this.updateUI();
            this.validate(); 
    	}
    }

}






⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -