如何在Jlabel中设置文字:
PsoMath1.java类包含方法(print soliution)
int printSolution()
{
// Find solution particle.
int i = 0;
for(; i < particles.size(); i++)
{
if(testProblem(i) == TARGET){
break;
}
}
// Print it.
**System.out.println("Particle " + i + " has achieved target.");**
for(int j = 0; j < MAX_INPUTS; j++)
{
if(j < MAX_INPUTS - 1){
System.out.print(particles.get(i).data(j) + " + ");
}else{
System.out.print(particles.get(i).data(j) + " = " + TARGET);
}
} // j
System.out.print("\n");
return 0;
}
Pso.java包含Jbutton:在这里,我想设置另一个类的文本。
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt){
psomath1 ob =new psomath1();
String n1 = TARGETS.getText();
TARGETT= Integer.parseInt(n1);
ob.TARGET=TARGETT;
String n2 = MAXINPUTS.getText();
final int MAX_INPUTST = Integer.parseInt(n2);
ob.MAX_INPUTS=MAX_INPUTST;
String n3 = MAXPARTICLES.getText();
final int MAX_PARTICLEST = Integer.parseInt(n3);
ob.MAX_PARTICLES=MAX_PARTICLEST;
String n4 = VMAX.getText();
final int V_MAXT = Integer.parseInt(n4);
ob.V_MAX =V_MAXT;
String n5 = MAXEPOCHS.getText();
final int MAX_EPOCHST = Integer.parseInt(n5);
ob.MAX_EPOCHS =MAX_EPOCHST;
String n6 = STARTRANGEMIN .getText();
final int START_RANGE_MINT = Integer.parseInt(n6);
ob.START_RANGE_MIN =START_RANGE_MINT;
String n7 = STARTRANGEMAX.getText();
final int START_RANGE_MAXT = Integer.parseInt(n7);
ob.START_RANGE_MIN =START_RANGE_MINT;
ob.PSOAlgorithm();
**PRINTIT.setText(Integer.toString(ob.printSolution()));**
return;
}
但输出打印:0。
如何打印最后一次迭代值?
答案 0 :(得分:1)
那是因为你的方法printSolution在最后返回0,那就是你设置标签的那个。
PRINTIT.setText(Integer.toString(ob.printSolution()));