📄 pheromonecomponent.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.Pheromone;
// import javax.swing.JComponent;
import java.util.ListIterator;
import javax.swing.JLabel;
import javax.swing.JButton;
import java.awt.Color;
public class PheromoneComponent extends PropertyComponent
{
private JLabel[] color = new JLabel[10];
private JLabel[] number = new JLabel[10];
private JLabel[] resourceName = new JLabel[10];
private JLabel[] nextNode = new JLabel[10];
private JLabel[] pijl = new JLabel[10];
private JButton nextButton, prevButton;
public PheromoneComponent()
{
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, 16, 16);
//color[i].setBackground(Color.red);
add(number[i]);
resourceName[i] = new JLabel("");
resourceName[i].setBounds(42, i*32, 128, 16);
add(resourceName[i]);
pijl[i] = new JLabel("=>");
pijl[i].setBounds(25, 16+i*32, 20, 16);
add(pijl[i]);
nextNode[i] = new JLabel("");
nextNode[i].setBounds(45, 16+i*32, 125, 16);
add(nextNode[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();
//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));
number[i].setText("");
resourceName[i].setText("");
pijl[i].setText("");
nextNode[i].setText("");
}
Pheromone tempPheromone;
ListIterator li = p.getInformation("Pheromones");
i = 0;
while(li != null && li.hasNext() && i<10)
{
tempPheromone = (Pheromone)li.next();
color[i].setBackground(Color.magenta);
number[i].setText(String.valueOf(tempPheromone.getStrength()));
resourceName[i].setText(tempPheromone.getResource());
pijl[i].setText("=>");
nextNode[i].setText(tempPheromone.getDirection().toString());
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("");
resourceName[i].setText("");
pijl[i].setText("");
nextNode[i].setText("");
}
Pheromone tempPheromone;
ListIterator li = copyOfProperties.getInformation("Pheromones");
i = 0;
int temp = 0;
while(li != null && li.hasNext() && temp < (begin*10))
{
temp++;
li.next();
}
while(li != null && li.hasNext() && i<10)
{
tempPheromone = (Pheromone)li.next();
color[i].setBackground(Color.magenta);
number[i].setText(String.valueOf(tempPheromone.getStrength()));
resourceName[i].setText(tempPheromone.getResource());
pijl[i].setText("=>");
nextNode[i].setText(tempPheromone.getDirection().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 + -