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

📄 querycomponent.java

📁 P2P模拟器P2Psim的程序源码
💻 JAVA
字号:
package gui;

import graph.Properties;
import graph.ResourceQuery;

import java.util.ListIterator;

import javax.swing.JLabel;
import javax.swing.JButton;

import java.awt.Color;
import java.awt.Graphics;


public class QueryComponent extends PropertyComponent
{

	private JLabel[] color = new JLabel[10];
	private JLabel[] number = new JLabel[10];
	private JLabel[] searchFor = new JLabel[10];	
	private JLabel[] action = new JLabel[10];
	private JLabel[] numberOfAgents = new JLabel[10];
	private JButton nextButton, prevButton;
	
	public QueryComponent()
	{		
		for (int i=0; i<10; i++)
		{
			color[i] = new JLabel("");
			color[i].setOpaque(true);
			color[i].setBounds(0, (1+i*32), 14, 14);
			//color[i].setBackground(Color.white);
			add(color[i]);
			
			number[i] = new JLabel("");
			number[i].setBounds(20, i*32, 25, 16);
			//color[i].setBackground(Color.red);
			add(number[i]);
			
			searchFor[i] = new JLabel("");
			searchFor[i].setBounds(48, i*32, 122, 16);
			//destination[i].setBackground(Color.blue);
			add(searchFor[i]);
			
			action[i] = new JLabel("");
			action[i].setBounds(10, 16+i*32, 60, 16);
			add(action[i]);

			numberOfAgents[i] = new JLabel("");
			numberOfAgents[i].setBounds(70, 16+i*32, 100, 16);
			add(numberOfAgents[i]);
		
		}
		
		
		nextButton = new JButton("next 10");
		nextButton.setBounds(90, 340, 80, 25);
		nextButton.addActionListener(new java.awt.event.ActionListener() {
						public void actionPerformed(java.awt.event.ActionEvent evt) 
						{
							increaseBegin();
							updateInformation();
						}
					});
		add(nextButton);
		nextButton.hide();

		prevButton = new JButton("prev 10");
		prevButton.setBounds(5, 340, 80, 25);
		prevButton.addActionListener(new java.awt.event.ActionListener() {
						public void actionPerformed(java.awt.event.ActionEvent evt) 
						{
							decreaseBegin();
							updateInformation();
						}
					});
		add(prevButton);
		prevButton.hide();
		
	}

	public void paint(Graphics g)
	{
		super.paint(g);
	}

	public void updateInformation(Properties p)
	{
		begin = 0;
		int i = 0;
		
		copyOfProperties = p;
		
		for (i=0; i<10; i++)
		{
			color[i].setBackground(new Color(204,204,204));
			number[i].setText("");
			searchFor[i].setText("");
			action[i].setText("");
			numberOfAgents[i].setText("");
		}
		
		ResourceQuery tempQuery;
		ListIterator li = p.getInformation("Query");
		
		i = 0;
		while(li != null && li.hasNext() && i<10)
		{
			tempQuery = (ResourceQuery)li.next();
			
			color[i].setBackground(new Color(140,200,116));
			number[i].setText(String.valueOf(tempQuery.getWaitingTime()));
			searchFor[i].setText(tempQuery.getSearchFor());
			
			action[i].setText(tempQuery.getStatus());
			numberOfAgents[i].setText("# agents : " + tempQuery.getNumberOfAgents());
			
			i++;
		}
		
		if (i == 10)
		{
			nextButton.show();
			//add(nextButton);
		}
		else
		{
			nextButton.hide();
			//remove(nextButton);
		}

		repaint();
	}

	public void updateInformation()
	{
		int i = 0;
	
		for (i=0; i<10; i++)
		{
			color[i].setBackground(new Color(204,204,204));
			number[i].setText("");
			searchFor[i].setText("");
			action[i].setText("");
			numberOfAgents[i].setText("");
		}
	
		ResourceQuery tempQuery;
		ListIterator li = copyOfProperties.getInformation("Query");
	
		i = 0;
		int temp = 0;
		while(li != null && li.hasNext() && temp < (begin*10))
		{
			temp++;
			li.next();
		}
		while(li != null && li.hasNext() && i<10)
		{
			tempQuery = (ResourceQuery)li.next();
		
			color[i].setBackground(new Color(140,200,116));
			number[i].setText(String.valueOf(tempQuery.getWaitingTime()));
			searchFor[i].setText(tempQuery.getSearchFor());
		
			action[i].setText(tempQuery.getStatus());
			numberOfAgents[i].setText("# agents : " + tempQuery.getNumberOfAgents());
		
			i++;
		}
	
		if (i == 10 && li.hasNext())
		{
			nextButton.show();
			//add(nextButton);
		}
		else
		{
			nextButton.hide();
			//remove(nextButton);
		}
		if (begin == 0)
		{
			prevButton.hide();
			//remove(prevButton);
		}
		else
		{
			prevButton.show();
			//add(prevButton);
		}

		repaint();
	}

}

⌨️ 快捷键说明

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