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

📄 agentcomponent.java

📁 P2P模拟器P2Psim的程序源码
💻 JAVA
字号:
/*
 * Created on 20-dec-2003
 *
 * To change the template for this generated file go to
 * Window>Preferences>Java>Code Generation>Code and Comments
 */
package gui;

import graph.Properties;
import graph.Agent;

//import javax.swing.JComponent;
import java.util.ListIterator;

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

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

//import graph.Properties;


public class AgentComponent 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[] origin = new JLabel[10];	
	private JButton nextButton, prevButton;
	
	public AgentComponent()
	{		
		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]);

			origin[i] = new JLabel("");
			origin[i].setBounds(70, 16+i*32, 100, 16);
			add(origin[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);
		//System.out.println("Paint");
	}

	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("");
			origin[i].setText("");
		}
		
		Agent tempAgent;
		ListIterator li = p.getInformation("Agents");
		
		i = 0;
		while(li != null && li.hasNext() && i<10)
		{
			tempAgent = (Agent)li.next();
			
			color[i].setBackground(Color.orange);
			number[i].setText(String.valueOf(tempAgent.getAge()));
			searchFor[i].setText(tempAgent.getSearchFor());
			
			action[i].setText(tempAgent.getStatus());
			if (tempAgent.getOrigin() != null)
			{
				origin[i].setText("origin: " + tempAgent.getOrigin().toString());
			}
			else
			{
				origin[i].setText("no origin");
			}
			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("");
			origin[i].setText("");
		}
	
		Agent tempAgent;
		ListIterator li = copyOfProperties.getInformation("Agents");
		
		i = 0;
		int temp = 0;
		while(li != null && li.hasNext() && temp < (begin*10))
		{
			temp++;
			li.next();
		}
		while(li != null && li.hasNext() && i<10)
		{
			tempAgent = (Agent)li.next();
		
			color[i].setBackground(Color.orange);
			number[i].setText(String.valueOf(tempAgent.getAge()));
			searchFor[i].setText(tempAgent.getSearchFor());
		
			action[i].setText(tempAgent.getStatus());
			origin[i].setText("origin: " + tempAgent.getOrigin().toString());
		
			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 + -