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

📄 resourcecomponent.java

📁 P2P模拟器P2Psim的程序源码
💻 JAVA
字号:
/*
 * Created on 18-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.Gradient;

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

import javax.swing.JLabel;

import java.awt.Color;

import graph.Resource;
import javax.swing.JButton;


public class ResourceComponent extends PropertyComponent
{

	private JLabel[] color = new JLabel[10];
	private JLabel[] name = new JLabel[10];	
	private JButton nextButton, prevButton;

	public ResourceComponent()
	{	
		for (int i=0; i<10; i++)
		{
			color[i] = new JLabel("");
			color[i].setOpaque(true);
			color[i].setBounds(0, (1+i*16), 14, 14);
			//color[i].setBackground(Color.white);
			add(color[i]);
			
			
			name[i] = new JLabel("");
			name[i].setBounds(20, i*16, 150, 16);
			//toVertex[i].setBackground(Color.blue);
			add(name[i]);
		}
		
		nextButton = new JButton("next 10");
		nextButton.setBounds(90, 180, 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, 180, 80, 25);
		prevButton.addActionListener(new java.awt.event.ActionListener() {
						public void actionPerformed(java.awt.event.ActionEvent evt) 
						{
							decreaseBegin();
							updateInformation();
						}
					});
		add(prevButton);
		prevButton.hide();
		
		//System.out.println(color[0].toString());
	}


	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));
			name[i].setText("");
		}
		
		Resource tempResource;
		ListIterator li = p.getInformation("Resources");
		
		i = 0;
		while(li != null && li.hasNext() && i<10)
		{
			tempResource = (Resource)li.next();
			
			color[i].setBackground(Color.YELLOW);
			name[i].setText(tempResource.getName());
			
			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));
			name[i].setText("");
		}
	
		Resource tempResource;
		ListIterator li = copyOfProperties.getInformation("Resources");
	
		i = 0;
		int temp = 0;
		while(li != null && li.hasNext() && temp < (begin*10))
		{
			temp++;
			li.next();
		}
		while(li != null && li.hasNext() && i<10)
		{
			tempResource = (Resource)li.next();
		
			color[i].setBackground(Color.YELLOW);
			name[i].setText(tempResource.getName());
		
			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 + -