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

📄 multiselectframe.java

📁 简易聊天工具
💻 JAVA
字号:

import java.awt.*;
import java.awt.List;
import java.awt.event.*;
import javax.swing.*;
import java.util.*;
class MultiSelectFrame extends JFrame
{
	private JLabel msLabel;
	private JLabel clewLabel;
	private JScrollPane jsp;
	private JScrollPane jsp2;
	private List nameList;	
	private List selectedList;
	private JButton add;
	private JButton remove;
	private JButton removeAll;
	private JButton ok;
	private JButton cancel;
	private Vector friends;
	private ClientFrame CFparent = null;
	private CaptureDeviceFrame cdf = null;
	public MultiSelectFrame(ClientFrame parent, CaptureDeviceFrame cdf)
	{
		this.CFparent = parent;
		this.cdf = cdf;
		friends = CFparent.ChatFriends;
		msLabel = new JLabel("请选择参加会议的好友:");
		nameList = new List();
		for(int i = 0; i < friends.size(); i++)
		{
			People p = (People)friends.get(i);
			nameList.addItem(p.name);
		}
		jsp = new JScrollPane(nameList);
		selectedList = new List();
		jsp2 = new JScrollPane(selectedList);
		add = new JButton("添加");
		add.addActionListener(new ActionListener()
		{
			public void actionPerformed(ActionEvent e)
			{
				String[] sn = nameList.getSelectedItems();
				for(int i = 0; i < sn.length; i++)
				{
					if(selectedList.getItemCount() == 0) selectedList.addItem(sn[i]);
					else
					{	
						int k = 0;
						for(int j = 0; j < selectedList.getItemCount(); j++)
						{
							if(selectedList.getItem(j) != sn[i]) continue;
							k = 1;
							break;
						}
						if(k == 0) selectedList.addItem(sn[i]);
					}
				}		
			}	
		});
		remove = new JButton("删除");
		remove.addActionListener(new ActionListener()
		{
			public void actionPerformed(ActionEvent e)
			{
				String[] sn = selectedList.getSelectedItems();	
				for(int i = 0; i < sn.length; i++)
				{
					selectedList.remove(sn[i]);	
				}	
			}	
		});
		removeAll = new JButton("清空");
		removeAll.addActionListener(new ActionListener()
		{
			public void actionPerformed(ActionEvent e)
			{
				selectedList.removeAll();
			}	
		});
		clewLabel = new JLabel();
		ok = new JButton("确定");
		ok.addActionListener(new ActionListener()
		{
			public void actionPerformed(ActionEvent e)
			{
				ok_actionPerformed();                    
			}	
		});	
		cancel = new JButton("取消");
		cancel.addActionListener(new ActionListener()
		{
			public void actionPerformed(ActionEvent e)
			{
				setVisible(false);	                    
			}	
		});	
		msLabel.setBounds(new Rectangle(50, 20, 200, 20));
		jsp.setBounds(new Rectangle(20, 60, 150, 200));
		add.setBounds(new Rectangle(180, 100, 60, 20));
		remove.setBounds(new Rectangle(180, 150, 60, 20));
		removeAll.setBounds(new Rectangle(180, 200, 60, 20));
		jsp2.setBounds(new Rectangle(250, 60, 150, 200));
		clewLabel.setBounds(new Rectangle(50, 270, 200, 20));
		ok.setBounds(new Rectangle(100, 300, 60, 20));
		cancel.setBounds(new Rectangle(250, 300, 60, 20));
		Container cp = getContentPane();
		cp.setLayout(null);
		cp.add(msLabel, null);
		cp.add(add, null);
		cp.add(remove, null);
		cp.add(removeAll, null);
		cp.add(jsp, null);
		cp.add(jsp2, null);
		cp.add(clewLabel, null);
		cp.add(ok, null);
		cp.add(cancel, null);
		setTitle("网络会议");
		setSize(430, 380);
		this.setLocationRelativeTo(CFparent);
		setVisible(true);
	}
	private void ok_actionPerformed()
	{
		String ps = getSellectedPeopels();
		if(ps != null) 
		{
			CFparent.sendMsg("NETMEETING_CONNECT_REQUEST:" + ps);
			CFparent.audioFormat = cdf.getAudioFormat();
			CFparent.videoFormat = cdf.getVideoFormat();
			CFparent.audioDevice = cdf.getAudioDevice();
			CFparent.videoDevice = cdf.getVideoDevice();
			clewLabel.setText("正在连接,请等待...");
			try
			{
				synchronized (CFparent.netMeeting) 
				{ 	
					CFparent.netMeeting.wait();               
				}
			}catch (Exception e) {} 
			this.setVisible(false);
		}else
		{
			JOptionPane.showMessageDialog(this, "没有选中参加会议的人!", "系统消息", 
		    										JOptionPane.INFORMATION_MESSAGE);
		}
	}
	private String getSellectedPeopels()
	{
		String ps = null;
		String[] s = selectedList.getItems();
		if(s.length > 0)
		{
			ps = s[0];
			//System.out.println(ps);
			for(int i = 1; i < s.length; i++)
			{
				ps += "|" + s[i];	
			}
		}
		return ps;	
	}
	
}

⌨️ 快捷键说明

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