vj++6.0环境下java程序调试问题,急!!!(100分)

M

mirrors

Unregistered / Unconfirmed
GUEST, unregistred user!
在下初学java,用java作毕业设计,有3个问题想请教:
1. 在Vj++6.0环境下,build java程序后出现以下提示:
Class 'RA'do
es not have a method of the form'static public void main(String[])'
若此时执行程序,会弹出一个窗口说:“Solution update failed.Some files
may not be updated.
是什么意思,该如何解决。
2.为什么我的计算机每次运行java程序时,总会出现这种情况:
当鼠标第一次点击了运行后的java程序的屏幕后,再次点击时,
不管鼠标点击该程序有效范围的任何地方,都会变成点击第一次
点击过的地方(如某个按钮)只有按ALT+TAB切换出去并再切换
回来后,才可以点击该程序的其他地方,但是,同样地,这时想
要再点击其他地方的话,就只有再切换一次了。
3.为什么我的java程序运行后编辑框(Edit栏)中总无法输入?
请问上面这些问题是为什么?有何解决办法?(我的机器上装的
操作系统是Windows2000 Advance Server和windowsXP beta 2465)
 
建议您不要再使用 VJ 了,微软都放弃它了。
还是使用 JBuilder 4。
 
用JB太耗系统资源了,
很慢啊,我的频率才200,
内存才96,都快死了一样的
 
多谢孙老师的建议,我的程序不管在jbuiler还是在Vj上调试都没成功,
可否麻烦孙老师帮忙调试我的程序?帮忙看看问题出在哪里。
Thanks in advance!
以下是源代码(是关于路由算法的程序):
import java.awt.*;
import java.applet.*;
import java.net.*;
import java.util.*;
public class RA extends Applet {

final int noden=28;
//No. of network nodes
int gx[]={27,130,221,284,12,76,171,266,39,103,267,316,348,421,389,501,524,595,574,608,461,456,568,586,325,437,556,550};
int gy[]={45,59,55,68,131,136,135,119,181,240,257,168,50,100,172,104,45,14,64,112,168,226,212,163,294,293,272,334};
int graph[][]={{0,1,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{1,0,1,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,1,0,0,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0,640,0,0,0,0,0,0,0,0,0,1120,0,0,360,0,0,0},
{0,0,0,0,0,0,0,440,0,0,640,0,0,0,400,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,360,0,0,0,0,0,0,0,0,0,520,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,920,0,0,0,0,520,0,440,400,0,0,0,0,440,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,400,0,440,0,0,0,0,0,0,400,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0,0,400,0,0,400,0,440,600,400,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,400,0,360,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,360,0,320,640,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,440,0,320,0,360,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,600,0,640,360,0,0,0,0,320,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0,0,440,400,400,0,0,0,0,0,320,640,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,1120,0,0,0,0,0,0,0,0,0,320,0,600,0,0,400,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,640,600,0,280,0,0,360,0},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,320,0,0,280,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,360,0,0,0,0,0,0,0,0,0,0,0,0,0,0,600,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,400,0,0,600,0,640,640},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,360,0,0,640,0,400},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,640,400,0}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4,8,9,0,0,0,0,0},{4,0,4,5,8,9,0,0,0,0},{4,0,4,5,6,9,0,0,0,0},{5,0,1,6,5,8,9,0,0,0},{5,0,4,8,5,6,9,0,0,0},{6,0,1,2,3,7,6,9,0,0},{6,0,1,6,7,11,10,9,0,0},{6,0,1,6,5,4,8,9,0,0},{-1,0,0,0,0,0,0,0,0,0},
{0,10,9,0,0,0,0,0,0,0},{4,0,1,6,9,10,0,0,0,0},{4,0,4,8,9,10,0,0,0,0},{5,0,1,6,7,11,10,0,0,0},{5,0,4,5,6,9,10,0,0,0},{5,0,4,5,8,9,10,0,0,0},{6,0,1,2,3,7,11,10,0,0},{6,0,4,5,6,7,11,10,0,0},{6,0,1,6,5,8,9,10,0,0},{6,0,4,8,5,6,9,10,0,0},{-1,0,0,0,0,0,0,0,0,0},
{0,11,10,0,0,0,0,0,0,0},{4,0,1,6,7,11,0,0,0,0},{5,0,4,5,6,7,11,0,0,0},{5,0,1,2,3,7,11,0,0,0},{5,0,4,8,9,10,11,0,0,0},{5,0,1,6,9,10,11,0,0,0},{6,0,4,5,8,9,10,11,0,0},{6,0,4,5,6,9,10,11,0,0},{6,0,4,8,5,6,7,11,0,0},{6,0,1,6,7,13,14,11,0,0},{6,0,4,8,9,6,7,11,0,0},{-1,0,0,0,0,0,0,0,0,0},
{0,12,12,0,0,0,0,0,0,0},{4,0,1,2,3,12,0,0,0,0},{5,0,1,6,7,3,12,0,0,0},{5,0,1,6,7,13,12,0,0,0},{6,0,4,5,6,7,3,12,0,0},{6,0,4,5,6,7,13,12,0,0},{6,0,1,2,3,7,13,12,0,0},{7,0,4,5,6,1,2,3,12,0},{7,0,1,6,7,11,14,13,12,0},{7,0,4,8,5,6,7,13,12,0},{7,0,4,8,5,6,7,3,12,0},{7,0,4,8,9,6,7,13,12,0},{7,0,4,8,9,6,7,3,12,0},{-1,0,0,0,0,0,0,0,0,0},
{0,13,8,0,0,0,0,0,0,0},{4,0,1,6,7,13,0,0,0,0},{5,0,4,5,6,7,13,0,0,0},{5,0,1,2,3,7,13,0,0,0},{5,0,1,2,3,12,13,0,0,0},{6,0,4,8,5,6,7,13,0,0},{6,0,4,8,9,6,7,13,0,0},{6,0,1,6,7,3,12,13,0,0},{6,0,1,6,7,11,14,13,0,0},{-1,0,0,0,0,0,0,0,0,0},
{0,14,10,0,0,0,0,0,0,0},{5,0,1,6,7,11,14,0,0,0},{5,0,1,6,7,13,14,0,0,0},{6,0,4,5,6,7,11,14,0,0},{6,0,1,2,3,7,11,14,0,0},{6,0,4,8,9,10,11,14,0,0},{6,0,1,2,3,7,13,14,0,0},{6,0,4,5,6,7,13,14,0,0},{6,0,1,2,3,12,13,14,0,0},{6,0,1,6,7,13,20,14,0,0},{6,0,1,6,9,10,11,14,0,0},{-1,0,0,0,0,0,0,0,0,0},
{0,15,15,0,0,0,0,0,0,0},{5,0,1,6,7,13,15,0,0,0},{6,0,4,5,6,7,13,15,0,0},{6,0,1,2,3,7,13,15,0,0},{6,0,1,2,3,12,13,15,0,0},{6,0,1,6,7,13,20,15,0,0},{7,0,4,8,9,10,21,20,15,0},{7,0,1,2,3,12,13,20,15,0},{7,0,1,2,3,7,13,20,15,0},{7,0,4,5,6,7,13,20,15,0},{7,0,4,8,5,6,7,13,15,0},{7,0,4,8,9,6,7,13,15,0},{7,0,1,6,7,3,12,13,15,0},{7,0,1,6,7,11,14,20,15,0},{7,0,1,6,9,10,21,20,15,0},{7,0,1,6,7,11,14,13,15,0},{-1,0,0,0,0,0,0,0,0,0},
{0,16,16,0,0,0,0,0,0,0},{6,0,1,6,7,13,15,16,0,0},{7,0,4,5,6,7,13,15,16,0},{7,0,1,2,3,7,13,15,16,0},{7,0,1,2,3,12,13,15,16,0},{7,0,1,6,7,13,20,15,16,0},{8,0,4,8,9,10,21,20,15,16},{8,0,1,2,3,12,13,20,15,16},{8,0,1,2,3,7,13,20,15,16},{8,0,4,5,6,7,13,20,15,16},{8,0,1,6,7,13,15,18,17,16},{8,0,4,8,5,6,7,13,15,16},{8,0,4,8,9,6,7,13,15,16},{8,0,1,6,7,3,12,13,15,16},{8,0,1,6,7,11,14,20,15,16},{8,0,1,6,9,10,21,20,15,16},{8,0,1,6,7,11,14,13,15,16},{-1,0,0,0,0,0,0,0,0,0},
{0,17,17,0,0,0,0,0,0,0},{7,0,1,6,7,13,15,16,17,0},{7,0,1,6,7,13,15,18,17,0},{7,0,1,6,7,13,15,19,17,0},{8,0,4,5,6,7,13,15,16,17},{8,0,1,2,3,7,13,15,16,17},{8,0,1,2,3,12,13,15,16,17},{8,0,1,6,7,13,20,15,16,17},{8,0,1,6,7,13,20,15,18,17},{8,0,1,2,3,12,13,15,18,17},{8,0,1,2,3,7,13,15,18,17},{8,0,4,5,6,7,13,15,18,17},{8,0,1,6,7,13,20,15,19,17},{8,0,1,2,3,12,13,15,19,17},{8,0,1,2,3,7,13,15,19,17},{8,0,4,5,6,7,13,15,19,17},{8,0,1,6,7,13,15,18,19,17},{8,0,1,6,7,13,15,19,18,17},{-1,0,0,0,0,0,0,0,0,0},
{0,18,21,0,0,0,0,0,0,0},{6,0,1,6,7,13,15,18,0,0},{7,0,4,5,6,7,13,15,18,0},{7,0,1,2,3,7,13,15,18,0},{7,0,1,2,3,12,13,15,18,0},{7,0,1,6,7,13,20,15,18,0},{7,0,1,6,7,13,15,19,18,0},{8,0,4,8,9,10,21,20,15,18},{8,0,1,2,3,12,13,20,15,18},{8,0,1,2,3,7,13,20,15,18},{8,0,4,5,6,7,13,20,15,18},{8,0,1,6,7,13,20,15,19,18},{8,0,1,2,3,12,13,15,19,18},{8,0,1,2,3,7,13,15,19,18},{8,0,4,5,6,7,13,15,19,18},{8,0,4,8,5,6,7,13,15,18},{8,0,4,8,9,6,7,13,15,18},{8,0,1,6,7,3,12,13,15,18},{8,0,1,6,7,11,14,20,15,18},{8,0,1,6,9,10,21,20,15,18},{8,0,1,6,7,11,14,13,15,18},{8,0,1,6,7,13,15,16,17,18},{-1,0,0,0,0,0,0,0,0,0},
{0,19,24,0,0,0,0,0,0,0},{6,0,1,6,7,13,15,19,0,0},{7,0,4,5,6,7,13,15,19,0},{7,0,1,2,3,7,13,15,19,0},{7,0,1,2,3,12,13,15,19,0},{7,0,1,6,7,13,20,15,19,0},{7,0,1,6,7,13,15,18,19,0},{8,0,4,8,9,10,21,20,15,19},{8,0,1,2,3,12,13,20,15,19},{8,0,1,2,3,7,13,20,15,19},{8,0,4,5,6,7,13,20,15,19},{8,0,1,6,7,13,20,15,18,19},{8,0,1,2,3,12,13,15,18,19},{8,0,1,6,9,10,21,22,23,19},{8,0,1,2,3,7,13,15,18,19},{8,0,4,8,9,10,21,22,23,19},{8,0,4,5,6,7,13,15,18,19},{8,0,4,8,5,6,7,13,15,19},{8,0,4,8,9,6,7,13,15,19},{8,0,1,6,7,3,12,13,15,19},{8,0,1,6,7,11,14,20,15,19},{8,0,1,6,9,10,21,20,15,19},{8,0,1,6,7,11,14,13,15,19},{8,0,1,6,7,13,20,22,23,19},{8,0,1,6,7,13,15,16,17,19},{-1,0,0,0,0,0,0,0,0,0},
{0,20,9,0,0,0,0,0,0,0},{5,0,1,6,7,13,20,0,0,0},{6,0,4,5,6,7,13,20,0,0},{6,0,1,2,3,7,13,20,0,0},{6,0,4,8,9,10,21,20,0,0},{6,0,1,2,3,12,13,20,0,0},{6,0,1,6,7,11,14,20,0,0},{6,0,1,6,9,10,21,20,0,0},{6,0,1,6,7,13,14,20,0,0},{6,0,1,6,7,13,15,20,0,0},{-1,0,0,0,0,0,0,0,0,0},
{0,21,18,0,0,0,0,0,0,0},{5,0,1,6,9,10,21,0,0,0},{5,0,4,8,9,10,21,0,0,0},{6,0,1,6,7,11,10,21,0,0},{6,0,1,6,7,13,20,21,0,0},{6,0,4,5,6,9,10,21,0,0},{6,0,4,5,8,9,10,21,0,0},{7,0,1,2,3,7,11,10,21,0},{7,0,4,5,6,7,11,10,21,0},{7,0,1,2,3,7,13,20,21,0},{7,0,4,5,6,7,13,20,21,0},{7,0,4,8,9,10,24,25,21,0},{7,0,1,2,3,12,13,20,21,0},{7,0,1,6,7,11,14,20,21,0},{7,0,1,6,7,13,14,20,21,0},{7,0,1,6,9,10,24,25,21,0},{7,0,1,6,5,8,9,10,21,0},{7,0,1,6,7,13,20,22,21,0},{7,0,4,8,5,6,9,10,21,0},{-1,0,0,0,0,0,0,0,0,0},
{0,22,13,0,0,0,0,0,0,0},{6,0,1,6,7,13,20,22,0,0},{6,0,4,8,9,10,21,22,0,0},{6,0,1,6,9,10,21,22,0,0},{7,0,1,2,3,7,13,20,22,0},{7,0,1,2,3,12,13,20,22,0},{7,0,4,5,6,9,10,21,22,0},{7,0,4,5,6,7,13,20,22,0},{7,0,1,6,7,11,10,21,22,0},{7,0,1,6,7,13,20,21,22,0},{7,0,1,6,7,11,14,20,22,0},{7,0,1,6,9,10,21,20,22,0},{7,0,4,8,9,10,21,20,22,0},{7,0,4,5,8,9,10,21,22,0},{-1,0,0,0,0,0,0,0,0,0},
{0,23,19,0,0,0,0,0,0,0},{7,0,1,6,7,13,15,19,23,0},{7,0,4,8,9,10,21,22,23,0},{7,0,1,6,9,10,21,22,23,0},{7,0,1,6,7,13,20,22,23,0},{8,0,1,2,3,7,13,15,19,23},{8,0,1,2,3,7,13,20,22,23},{8,0,1,2,3,12,13,15,19,23},{8,0,1,2,3,12,13,20,22,23},{8,0,4,5,6,7,13,15,19,23},{8,0,4,5,6,7,13,20,22,23},{8,0,4,5,6,9,10,21,22,23},{8,0,4,8,9,10,21,20,22,23},{8,0,1,6,7,13,15,18,19,23},{8,0,1,6,7,13,20,15,19,23},{8,0,4,5,8,9,10,21,22,23},{8,0,1,6,7,11,14,20,22,23},{8,0,1,6,7,11,10,21,22,23},{8,0,1,6,9,10,21,20,22,23},{8,0,1,6,7,13,20,21,22,23},{-1,0,0,0,0,0,0,0,0,0},
{0,24,11,0,0,0,0,0,0,0},{5,0,1,6,9,10,24,0,0,0},{5,0,4,8,9,10,24,0,0,0},{6,0,1,6,7,11,10,24,0,0},{6,0,4,5,6,9,10,24,0,0},{6,0,4,5,8,9,10,24,0,0},{7,0,1,2,3,7,11,10,24,0},{7,0,4,5,6,7,11,10,24,0},{7,0,1,6,9,10,21,25,24,0},{7,0,4,8,9,10,21,25,24,0},{7,0,1,6,5,8,9,10,24,0},{7,0,4,8,5,6,9,10,24,0},{-1,0,0,0,0,0,0,0,0,0},
{0,25,11,0,0,0,0,0,0,0},{6,0,1,6,9,10,21,25,0,0},{6,0,4,8,9,10,21,25,0,0},{6,0,1,6,9,10,24,25,0,0},{6,0,4,8,9,10,24,25,0,0},{7,0,1,6,7,11,10,21,25,0},{7,0,1,6,7,11,10,24,25,0},{7,0,4,5,6,9,10,21,25,0},{7,0,4,5,6,9,10,24,25,0},{7,0,4,5,8,9,10,21,25,0},{7,0,4,5,8,9,10,24,25,0},{7,0,1,6,7,13,20,21,25,0},{-1,0,0,0,0,0,0,0,0,0},
{0,26,28,0,0,0,0,0,0,0},{7,0,1,6,7,13,20,22,26,0},{7,0,4,8,9,10,21,22,26,0},{7,0,1,6,9,10,21,22,26,0},{7,0,1,6,9,10,21,25,26,0},{7,0,4,8,9,10,21,25,26,0},{7,0,1,6,9,10,24,25,26,0},{7,0,4,8,9,10,24,25,26,0},{8,0,1,2,3,7,13,20,22,26},{8,0,1,2,3,12,13,20,22,26},{8,0,4,5,6,9,10,21,25,26},{8,0,4,5,6,9,10,21,22,26},{8,0,4,5,6,7,13,20,22,26},{8,0,1,6,7,11,10,21,25,26},{8,0,1,6,7,11,10,21,22,26},{8,0,1,6,7,11,10,24,25,26},{8,0,4,5,6,9,10,24,25,26},{8,0,4,5,8,9,10,21,25,26},{8,0,4,5,8,9,10,24,25,26},{8,0,4,5,8,9,10,21,22,26},{8,0,1,6,9,10,21,25,27,26},{8,0,1,6,9,10,24,25,27,26},{8,0,4,8,9,10,21,25,27,26},{8,0,4,8,9,10,24,25,27,26},{8,0,1,6,7,13,20,21,22,26},{8,0,1,6,7,11,14,20,22,26},{8,0,1,6,9,10,21,20,22,26},{8,0,4,8,9,10,21,20,22,26},{8,0,1,6,7,13,20,21,25,26},{-1,0,0,0,0,0,0,0,0,0},
{0,27,18,0,0,0,0,0,0,0},{7,0,1,6,9,10,21,25,27,0},{7,0,4,8,9,10,21,25,27,0},{7,0,1,6,9,10,24,25,27,0},{7,0,4,8,9,10,24,25,27,0},{8,0,1,6,7,11,10,21,25,27},{8,0,1,6,7,11,10,24,25,27},{8,0,1,6,7,13,20,22,26,27},{8,0,4,8,9,10,21,22,26,27},{8,0,4,8,9,10,24,25,26,27},{8,0,4,5,6,9,10,21,25,27},{8,0,4,5,6,9,10,24,25,27},{8,0,4,5,8,9,10,21,25,27},{8,0,4,5,8,9,10,24,25,27},{8,0,1,6,7,13,20,21,25,27},{8,0,1,6,9,10,21,22,26,27},{8,0,1,6,9,10,24,25,26,27},{8,0,1,6,9,10,21,25,26,27},{8,0,4,8,9,10,21,25,26,27}};

final int mdown=14;
final int mright=95;
int bandwidth[][]=new int [noden][noden];
int delay[][]=new int [noden][noden];
double wband[][]=newdo
uble [noden][noden];
final int radius=10;
final int ncfont=12;
int metricd=1;
Choice disp;
List falgo;
String nometrics="不显示link metrics";
String onlyband="显示带宽";
String onlyprop="显示广播时间";
String allmetrics="显示所有的link metrics";
String randoml="随机产生新带宽";
String chlink="改变一个链接的metrics";
final int maxband=155;
final int maxdelay=250;
String wsp="widest-shortest";
String swp="shortest-widest";
String lcp="最小代价least-cost";
String lhop="最少跳数least hop-count";
Random rand=new Random();
Label lmetric,sourcei,desti,qosb,qosd,algo,title;
Button help,start,linkband,clink;
TextField fsnod,fdnod,fband,fdelay;
public TextArea msg;
String ialgo=lcp;
// algorithm
int isrc,ides; // source and destination
int iband,idel; // bandwidth and delay
double ngraph[][]=newdo
uble [noden][noden];
//the real network
int result[]=new int [noden+1];
//computation result
int dsprlt;
int rltpath[][]=new int [noden][noden];
final int step=6;
int newx,newy;
public void init() {
int i,j;
//resize(700,200);
setBackground(Color.white);
setFont(new Font("TimesRoman",Font.BOLD,ncfont));
/* move graphdo
wn and right */
for (i=0;i<noden;i++) {
gy=gy+mdown;
gx=gx+mright;
}
/* link bandwidth initialization */
for (i=0;i<noden;i++)
for (j=0;j<noden;j++)
if (graph[j]==1) {graph[j]=1;
bandwidth[j]=155;}
else
{graph[j]=0;
bandwidth[j]=0;}
/* link delay &amp;
distance initialization */
for (i=0;i<noden;i++)
for (j=0;j<noden;j++) {
if (graph[j]==0) distan[j]=Double.MAX_VALUE;
if ((j<i)&amp;&amp;(graph[j]==1)) {
delay[j]=(int) Math.round(distan[j]/20.0);
delay[j]=delay[j];
delay=0;
distan[j]=distan[j];
distan=Double.MAX_VALUE;
}
}
/* display the main menu */
//setLayout(new GridLayout(3,7,5,5));
sourcei=new Label("源节点:");
desti=new Label("目标节点:");
qosb=new Label("带宽(Mbps):");
qosd=new Label("延迟 bound (ms):");
algo=new Label("算法:");
help=new Button("帮助");
start=new Button("开始计算:");
linkband= new Button(randoml);
clink=new Button(chlink);
title=new Label(" ============== 基于QoS的路由算法演示 =============");
/* display link metrics */
disp=new Choice();
disp.addItem(onlyband);
disp.addItem(onlyprop);
disp.addItem(nometrics);
disp.addItem(allmetrics);
/* display source and destination */
fsnod=new TextField(4);
fsnod.setEditable(true);
fdnod=new TextField(4);
fdnod.setEditable(true);
/* display bandwidth and delay bound */
fband=new TextField(4);
fband.setEditable(true);
fdelay=new TextField(4);
fdelay.setEditable(true);
/* display algorithms */
falgo=new List(4,false);
falgo.addItem(lcp);
falgo.addItem(lhop);
falgo.addItem(swp);
falgo.addItem(wsp);
falgo.select(0);
/* display message */
msg=new TextArea(8,80);
msg.setEditable(false);
GridBagConstraints gbc;
setLayout(new GridBagLayout());
gbc=new GridBagConstraints();

gbc.gridheight=1;
gbc.weightx=1;
gbc.weighty=1;
gbc.fill=GridBagConstraints.NONE;
gbc.anchor=GridBagConstraints.NORTHWEST;
gbc.gridwidth=15;
gbc.gridx=1;
gbc.gridy=1;
((GridBagLayout) getLayout()).setConstraints(title,gbc);
add(title);
gbc.gridx=1;
gbc.gridy=4;
gbc.gridwidth=1;
((GridBagLayout) getLayout()).setConstraints(help,gbc);
add(help);
gbc.gridx=1;
gbc.gridy=5;
((GridBagLayout) getLayout()).setConstraints(sourcei,gbc);
add(sourcei);
gbc.gridwidth=1;
gbc.gridx=1;
gbc.gridy=6;
((GridBagLayout) getLayout()).setConstraints(fsnod,gbc);
add(fsnod);
gbc.gridx=1;
gbc.gridy=7;
((GridBagLayout) getLayout()).setConstraints(desti,gbc);
add(desti);
gbc.gridx=1;
gbc.gridy=8;
((GridBagLayout) getLayout()).setConstraints(fdnod,gbc);
add(fdnod);
gbc.gridx=1;
gbc.gridy=9;
((GridBagLayout) getLayout()).setConstraints(qosb,gbc);
add(qosb);
gbc.gridx=1;
gbc.gridy=10;
((GridBagLayout) getLayout()).setConstraints(fband,gbc);
add(fband);
gbc.gridx=1;
gbc.gridy=11;
((GridBagLayout) getLayout()).setConstraints(qosd,gbc);
add(qosd);
gbc.gridx=1;
gbc.gridy=12;
((GridBagLayout) getLayout()).setConstraints(fdelay,gbc);
add(fdelay);
gbc.gridwidth=1;
gbc.gridx=1;
gbc.gridy=13;
((GridBagLayout) getLayout()).setConstraints(linkband,gbc);
add(linkband);
gbc.gridx=1;
gbc.gridy=14;
((GridBagLayout) getLayout()).setConstraints(clink,gbc);
add(clink);
gbc.gridheight=1;
gbc.anchor=GridBagConstraints.NORTHWEST;
gbc.gridx=2;
gbc.gridy=18;
gbc.gridwidth=3;
((GridBagLayout) getLayout()).setConstraints(disp,gbc);
add(disp);
/*
gbc.anchor=GridBagConstraints.NORTHWEST;
gbc.gridx=2;
gbc.gridy=18;
gbc.gridwidth=3;
((GridBagLayout) getLayout()).setConstraints(algo,gbc);
add(algo);
*/
gbc.anchor=GridBagConstraints.WEST;
gbc.gridx=2;
gbc.gridy=18;
gbc.gridwidth=4;
((GridBagLayout) getLayout()).setConstraints(falgo,gbc);
add(falgo);
gbc.anchor=GridBagConstraints.WEST;
gbc.gridx=1;
gbc.gridy=18;
gbc.gridwidth=1;
gbc.gridheight=2;
((GridBagLayout) getLayout()).setConstraints(msg,gbc);
add(msg);
gbc.anchor=GridBagConstraints.SOUTHWEST;
gbc.gridx=2;
gbc.gridy=18;
gbc.gridwidth=1;
gbc.gridheight=1;
((GridBagLayout) getLayout()).setConstraints(start,gbc);
add(start);
}

public Insets Insets() {
return new Insets(10,10,10,10);
}
public boolean HandleEvent (Event evt) {
int i,j,aband,success=0;
int ppsrc,ppdes,ppband,ppdel;
Dijkstra shortpath;
Wang shortwide;
Gurin wideshort;
String rlt;
if (evt.id==evt.ACTION_EVENT) {
dsprlt=0;
if (evt.target==disp) {
if ((String) evt.arg==nometrics) metricd=0;
else
if ((String) evt.arg==onlyband) metricd=1;
else
if ((String) evt.arg==onlyprop) metricd=2;
else
if ((String) evt.arg==allmetrics) metricd=3;
repaint();
}
else
if (evt.target==help) {
msg.append("/n=== Help ====");
msg.append("/nSteps needed to compute a path:");
msg.append("/n* choose a source node");
msg.append("/n* choose a destination node");
msg.append("/n* give a bandwidth constraint (not larger than 155 Mbps)");
msg.append("/n* give a delay bound (not larger than 250 ms)");
msg.append("/n* choose an algorithm");
msg.append("/n* click the button `Start computing′");
msg.append("/nYou can randomly change the available bandwidths of all links, or change the metrics");
msg.append("/nof a single link. You can also control the way of link metrics displaying./n");
}
else
if (evt.target==linkband) {
for (i=0;i<noden;i++)
for (j=0;j<noden;j++)
if ((j<i)&amp;&amp;(graph[j]==1)) {
bandwidth[j]=(int) (rand.nextFloat()*maxband);
bandwidth[j]=bandwidth[j];
bandwidth=0;
}
repaint();
}
else
if (evt.target==clink) {
ppsrc=0;
ppdes=0;
ppband=0;
ppdel=0;
try {
isrc=Integer.valueOf(fsnod.getText()).intValue();
} catch (NumberFormatException e) {
ppsrc=1;
}
if (isrc>=noden) ppsrc=1;
try {
ides=Integer.valueOf(fdnod.getText()).intValue();
} catch (NumberFormatException e) {
ppdes=1;
}
if (ides>=noden) ppdes=1;
try {
iband=Integer.valueOf(fband.getText()).intValue();
} catch (NumberFormatException e) {
ppband=1;
}
if (iband>maxband) ppband=1;
try {
idel=Integer.valueOf(fdelay.getText()).intValue();
} catch (NumberFormatException e) {
ppdel=1;
}
if (idel>maxdelay) ppdel=1;
if ((ppsrc==1)||(ppdes==1)||(ppband==1)||(ppdel==1)) {
if (ppsrc==1) {
msg.selectAll();
msg.append("The given linkdo
es not exist!/n");
}
if (ppdes==1) {
msg.selectAll();
msg.append("The given linkdo
es not exist!/n");
}
if (ppband==1) {
msg.selectAll();
msg.append("Input error for the new link available bandwidth! (must be <= 155 Mbps)/n");
}
if (ppdel==1) {
msg.selectAll();
msg.append("Input error for the new link propagation delay! (must be <=250 ms)/n");
}

}
else
if (graph[isrc][ides]==0) msg.append("/nlink ("+isrc+","+ides+")do
es not exist!/n");
else
{
delay[isrc][ides]=idel;
delay[ides][isrc]=idel;
bandwidth[isrc][ides]=iband;
bandwidth[ides][isrc]=iband;
msg.append("/nThe available bandwidth of link ("+isrc+","+ides+") is changed to "+iband+" Mbps.");
msg.append("/nThe propagation delay of link ("+isrc+","+ides+") is changed to "+idel+" ms./n");
repaint();
}
}
else
if (evt.target==start) {
ialgo=falgo.getSelectedItem();
ppsrc=0;
ppdes=0;
ppband=0;
ppdel=0;
/*
msg.append("/nisrc="+fsnod.getText());
msg.append("/nides="+fdnod.getText());
msg.append("/niband="+fband.getText());
msg.append("/nidel="+fdelay.getText()+"/n/n");
*/
try {
isrc=Integer.valueOf(fsnod.getText()).intValue();
} catch (NumberFormatException e) {
ppsrc=1;
}
if (isrc>=noden) ppsrc=1;
try {
ides=Integer.valueOf(fdnod.getText()).intValue();
} catch (NumberFormatException e) {
ppdes=1;
}
if (ides>=noden) ppdes=1;
try {
iband=Integer.valueOf(fband.getText()).intValue();
} catch (NumberFormatException e) {
ppband=1;
}
if (iband>maxband) ppband=1;
try {
idel=Integer.valueOf(fdelay.getText()).intValue();
} catch (NumberFormatException e) {
ppdel=1;
}
if (idel>maxdelay) ppdel=1;
if ((ppsrc==1)||(ppdes==1)||(ppband==1)||(ppdel==1)) {
if (ppsrc==1) {
msg.selectAll();
msg.append("Input error for source node!/n");
}
if (ppdes==1) {
msg.selectAll();
msg.append("Input error for destination node!/n");
}
if (ppband==1) {
msg.selectAll();
msg.append("Input error for bandwidth requirement!/n");
}
if (ppdel==1) {
msg.selectAll();
msg.append("Input error for delay bound!/n");
}
msg.append("--- Please click `Help′ button for help ---/n/n");
}
else
{
//msg.append("You have chosen:/n");
msg.append("/nsource node="+new Integer(isrc).toString()+", ");
msg.append("destination="+new Integer(ides).toString()+", ");
msg.append("required bandwidth="+new Integer(iband).toString()+" Mbps, ");
msg.append("delay bound="+new Integer(idel).toString()+" ms");
msg.append("/nusing "+ialgo+" path algorithm ...");

if ((ialgo==lcp)||(ialgo==lhop)) {
for (i=0;i<noden;i++)
for (j=0;j<noden;j++)
if (j<i) {
if (bandwidth[j]<iband) ngraph[j]=Double.MAX_VALUE;
else
{
if (ialgo==lhop) ngraph[j]=1;
else
ngraph[j]=1.0/bandwidth[j];
}
ngraph[j]=ngraph[j];
ngraph=Double.MAX_VALUE;
}
shortpath=new Dijkstra();
success=shortpath.shortest(this,noden,ngraph,isrc,ides);
}
else
if (ialgo==swp) {
for (i=0;i<noden;i++)
for (j=0;j<noden;j++)
if (j<i) {
/*
if (bandwidth[j]<iband) {
wband[j]=0;
ngraph[j]=Double.MAX_VALUE;
}
else
{
*/
wband[j]=bandwidth[j];
ngraph[j]=distan[j];
// }
wband[j]=wband[j];
wband=0;
ngraph[j]=ngraph[j];
ngraph=Double.MAX_VALUE;
}
shortwide=new Wang();
success=shortwide.swide(this,noden,wband,isrc,ides,ngraph);
}
else
if (ialgo==wsp) {
wideshort=new Gurin();
i=Math.min(isrc,ides);
if (i==0) success=wideshort.wshort(this,noden,bandwidth,isrc,ides,iband,spath0);
//else
if (i<=3) success=wideshort.wshort(this,noden,bandwidth,isrc,ides,iband,spath1);
else
{
msg.append(" Sorry,to speed the computation for this algorithm,/nthe source node or the destination node must be 0./n");
success=2;
}
}
if (success==1) {
dsprlt=1;
for (i=0;i<noden;i++)
for (j=0;j<noden;j++) rltpath[j]=0;
msg.append("/nThe computed path is:");
rlt=" ";
j=0;
aband=Integer.MAX_VALUE;
for (i=1;i<=result[0]+1;i++) {
rlt=rlt+result+" ";
if (i<=result[0]) {
rltpath[result][result[i+1]]=1;
rltpath[result[i+1]][result]=1;
j=j+delay[result][result[i+1]];
aband=Math.min(aband,bandwidth[result][result[i+1]]);
}
}
repaint();
msg.append(rlt+", no. of hops="+result[0]+"/n");
msg.append("The delay of the computed path is "+j+" ms.");
if (j>idel) msg.append(" The given delay bound is not satisfied!");
msg.append("/nThe available bandwidth of the computed path (width) is "+aband+" Mbps.");
if (aband<iband) msg.append("/nThe bandwidth requirement is not satisfied!");
msg.append("/n");
} else
if (success==0) msg.append("/nThe pathdo
es not exist!/n");
msg.append("/n");
}

}
}
return false;
}
public void pathrlt(int paths[]) {
int i;
for (i=0;i<=paths[0]+1;i++)
result=paths;
}

public void newxy(int x1,int y1,int x2,int y2) {
double zz=step/Math.sqrt((double) ((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1)));
newx=(int) (zz*(x2-x1)+x1);
if (y1==y2) newy=y1;
else
if (y1<y2) newy=(int) (zz*(y2-y1)+y1);
else
newy=y1-(int) (zz*(y1-y2));
}
public void drawL(Graphics g,int mark,int x1,int y1,int x2,int y2) {
int nx,ny;
if (mark==0) g.drawLine(x1,y1,x2,y2);
else
{
newxy(x1,y1,x2,y2);
if (newx<x2) g.drawLine(x1,y1,newx,newy);
else
g.drawLine(x1,y1,x2,y2);
while (newx<x2) {
newxy(newx,newy,x2,y2);
nx=newx;
ny=newy;
if (nx<x2) {
newxy(newx,newy,x2,y2);
if (newx<x2) g.drawLine(nx,ny,newx,newy);
else
g.drawLine(nx,ny,x2,y2);
}
}
}
}
public void paint(Graphics g) {
int i,j,sx1,y1,lx2,y2,bl,mk;
String bstring,dstring;
for (i=0;i<noden;i++) {
g.drawOval((gx-radius),(gy-radius),(2*radius),(2*radius));
if (i<10) g.drawString(new Integer(i).toString(),gx-ncfont/5,gy+ncfont/3);
else
g.drawString(new Integer(i).toString(),gx-ncfont/2,gy+ncfont/3);
}
for (i=0;i<noden;i++)
for (j=0;j<noden;j++)
if ((j<i)&amp;&amp;(graph[j]==1)) {
if ((dsprlt==1)&amp;&amp;(rltpath[j]==1)) {mk=1;
g.setColor(Color.red);}
else
{mk=0;
g.setColor(Color.black);}
if (gx<=gx[j]) {sx1=gx;y1=gy;lx2=gx[j];y2=gy[j];}
else
{sx1=gx[j];y1=gy[j];lx2=gx;y2=gy;}
if ((lx2-sx1)>Math.abs(y2-y1)) drawL(g,mk,sx1+radius,y1,lx2-radius,y2);
else
if (y1<y2) drawL(g,mk,sx1,y1+radius,lx2,y2-radius);
else
drawL(g,mk,sx1,y1-radius,lx2,y2+radius);
g.setColor(Color.black);
dstring=new Integer(delay[j]).toString();
if (metricd==2) g.drawString(dstring,(sx1+lx2)/2,(y1+y2)/2+4);
else
if (metricd==3) g.drawString(","+dstring,(sx1+lx2)/2,(y1+y2)/2+4);
if ((metricd==1)||(metricd==3)) {
g.setColor(Color.blue);
bstring=new Integer(bandwidth[j]).toString();
bl=bstring.length();
g.drawString(bstring,(sx1+lx2)/2-bl*4-4,(y1+y2)/2+4);
}
}
}
}
class Dijkstra {
//Dijkstra's shortest path algorithm
//return 1, if a path can be computed;
otherweise return 0
public int shortest(RA parent,int nodem,double graph[][],int s,int q) {
do
uble sumv,label;
int i,j,mark=1,mark1=0,ii,jj,vpii=0,vpjj=0;
int p_T[]=new int [nodem];
int p_P[]=new int [nodem];
int p_W[]=new int [nodem];
int result[]=new int [nodem];
double p_PL[]=newdo
uble [nodem];
int rlt[]=new int [nodem+1];
i=0;
p_T=s;
p_PL=0;
p_P=0;
for (j=0;j<nodem;j++) p_W[j]=j;
p_W=-1;
while (mark==1) {
label=Double.MAX_VALUE;
for (ii=0;ii<=i;ii++)
for (jj=0;jj<nodem;jj++)
if (p_W[jj]>=0) {
if (graph[p_T[ii]][p_W[jj]]<Double.MAX_VALUE-1) {
sumv=p_PL[ii]+graph[p_T[ii]][p_W[jj]];
if (sumv<label) {
label=sumv;
vpii=ii;vpjj=jj;
}
}
}
if (label>=Double.MAX_VALUE-1) mark=0;
else
{
i++;
p_T=p_W[vpjj];
p_W[vpjj]=-1;
p_P=p_T[vpii];
p_PL=label;
if (p_T==q) {mark1=1;
mark=0;}
}
}
if (mark1==0) return(0);
ii=0;jj=i;
result[ii]=p_T;
while (result[ii]!=s) {
ii++;
result[ii]=p_P;
i--;
while (p_T!=result[ii]) i--;
}
rlt[0]=ii;
i=1;
while (ii>=0) {
rlt=result[ii];
ii--;
i++;
}
parent.pathrlt(rlt);
return(1);
}
}

class Wang {
//shortest-widest path routing algorithm
//return 1, if a path can be computed;
otherweise return 0
int swide(RA parent,int nodem,double b[][],int s,int q,double graph[][])
{
int p_T[]=new int [nodem];
int p_P[]=new int [nodem];
int p_W[]=new int [nodem];
int rlt[]=new int [nodem+1];
int result[]=new int [nodem];
do
uble p_PL[]=newdo
uble [nodem];
double p_PH[]=newdo
uble [nodem];
double label,bv,mbv;
int i,j,mark=1,mark1=0,ii,jj,vpii=0,vpjj=0,mbvj=0;
do
uble dsum,bandl,width,sumv;
int zz;
//parent.msg.append("/ns = "+s+", q = "+q);
//first compute width
i=0;
p_T=s;
p_PL=Double.MAX_VALUE;
p_P=0;
p_PH=0;
for (j=0;j<nodem;j++) p_W[j]=j;
p_W=-1;

while (mark==1) {
label=0;
for (ii=0;ii<nodem;ii++)
if (p_W[ii]>=0) {
mbv=0;
for (jj=0;(jj<=i);jj++)
if (b[p_T[jj]][p_W[ii]]>0) {
bv=b[p_T[jj]][p_W[ii]];
if (p_PL[jj]<bv) bv=p_PL[jj];
if (mbv<bv) {mbv=bv;
mbvj=p_T[jj];}
else
if (mbv==bv)
if (p_PH[mbvj]>p_PH[p_T[jj]]) mbvj=p_T[jj];
}

if (mbv>label) {label=mbv;
vpii=ii;
vpjj=mbvj;}
else
if ((mbv==label)&amp;&amp;(mbv>0)&amp;&amp;(p_PH[vpjj]>p_PH[mbvj])) {
vpii=ii;
vpjj=mbvj;
}
}

if (label==0) mark=0;
else
{
i++;
p_T=vpii;
p_W[vpii]=-1;
p_P=vpjj;
p_PL=label;
p_PH[vpii]=p_PH[vpjj]+1;
if (p_T==q) {mark1=1;
mark=0;}
}
}
if (mark1==0) return(0);
ii=0;jj=i;
result[ii]=p_T;
while (result[ii]!=s) {
ii++;
result[ii]=p_P;
i--;
while (p_T!=result[ii]) i--;
}
width = p_PL[jj];
if (width <= 0) return(0);
//compute the shortest path from s to q
for (i=0;
i<nodem;
i++)
for (j=0;
j<nodem;
j++)
if (b[j]<width) graph[j]=Double.MAX_VALUE;
i=0;
mark=1;
mark1=0;
p_T=s;
p_PL=0;
p_P=0;
for (j=0;j<nodem;j++) p_W[j]=j;
p_W=-1;
while (mark==1) {
label=Double.MAX_VALUE;
for (ii=0;ii<=i;ii++)
for (jj=0;jj<nodem;jj++)
if (p_W[jj]>=0)
if (graph[p_T[ii]][p_W[jj]]<Double.MAX_VALUE-1) {
sumv=p_PL[ii]+graph[p_T[ii]][p_W[jj]];
if (sumv<label) {
label=sumv;
vpii=ii;vpjj=jj;}
}
if (label>=Double.MAX_VALUE-1) mark=0;
else
{
i++;
p_T=p_W[vpjj];
p_W[vpjj]=-1;
p_P=p_T[vpii];
p_PL=label;
if (p_T==q) {mark1=1;
mark=0;}
}
}
if (mark1==0) return(0);
ii=0;jj=i;
result[ii]=p_T;
while (result[ii]!=s) {
ii++;
result[ii]=p_P;
i--;
while (p_T!=result[ii]) i--;
}
rlt[0]=ii;
i=1;
while (ii>=0) {
rlt=result[ii];
ii--;
i++;
}
parent.pathrlt(rlt);
return(1);
}
}
class Gurin {
//widest-shortest path routing algorithm
//return 1, if a path can be computed;
otherweise return 0
int wshort(RA parent,int nodem,int band[][],int src,int des,int rband,int spath[][]) {
int s,q,pos,mark,totalp,hops;
int i,j,k;
int rlt[]=new int [nodem+1];

if (src>des) {s=des;
q=src;}
else
{s=src;
q=des;}
//parent.msg.append("/ns="+s+", q="+q+", rband="+rband);

//find the position of the shortest path for (s,q) in spath[][]
mark=0;
pos=0;
while (mark==0) {
if (spath[pos][0]==-1) pos++;
else
{
parent.msg.append("/nInternal Error with shortest paths/n");
return(0);
}
if ((spath[pos][0]==s)&amp;&amp;(spath[pos][1]==q)) mark=1;
else
pos=pos+spath[pos][2]+1;
}
//parent.msg.append("pos="+pos);
totalp=spath[pos][2];
//parent.msg.append("totalp="+totalp);
for (k=1;k<=totalp;k++) {
pos++;
hops=spath[pos][0];
j=1;
mark=0;
while ((mark==0)&amp;&amp;(j<=hops))
if (band[spath[pos][j]][spath[pos][j+1]]<rband) mark=1;
else
j++;
if (mark==0) {
//the path has been found
rlt[0]=spath[pos][0];
if (s==src)
for (j=1;j<=hops+1;j++) rlt[j]=spath[pos][j];
else
{
i=1;
for (j=hops+1;j>=1;j--) {rlt=spath[pos][j];
i++;}
}
parent.pathrlt(rlt);
return(1);
}
}
return(0);
}
}

 
补充,我的mail: hqli2000@21cn.com
Many Thx!
 
mirrors,要继续讨论你的问题,请定时将问题提前!
 
[^]提个小建议,下次贴代码是否能将注释也带上,否则读起来就不太顺利,呵呵
 
你没有'static public void main(String[])'方法,程序当然无法运行了!
 
講到布局,我現在也碰到這樣的問題了:
JCreator:
簡單代碼如下:import java.awt.*;
import java.applet.*;
import java.awt.Container;
import java.awt.GridBagConstraints;
public class GridBagLayout extends Applet {
protected void addGridBagButton(String buttonName,GridBagLayout gb,
GridBagConstraints gbc)
{
Button button=new Button(buttonName);
gb.setConstraints(button,gbc);
add(button);
}
public void init() {
resize(400,300);
GridBagLayout gridbag=new GridBagLayout();
GridBagConstraints c=new GridBagConstraints();
setLayout(gridbag);
c.fill=GridBagConstraints.BOTH;
c.weightx=1.0;
addGridBagButton("Button1",gridbag,c);
c.gridwidth=GridBagConstraints.REMAINDER;
addGridBagButton("Button2",gridbag,c);
addGridBagButton("Button3",gridbag,c);
c.weighty=1.0;
addGridBagButton("Button4",gridbag,c);
c.gridwidth=1;
c.weighty=0.0;
addGridBagButton("Button5",gridbag,c);
c.weightx=0.0;
addGridBagButton("Button6",gridbag,c);
c.gridwidth=GridBagConstraints.REMAINDER;
addGridBagButton("Button7",gridbag,c);
c.gridwidth=1;
c.gridheight=2;
c.weighty=1.5;
addGridBagButton("Button8",gridbag,c);
c.weighty=0.0;
c.gridwidth=GridBagConstraints.REMAINDER;
c.gridheight=1;
addGridBagButton("Button9",gridbag,c);
addGridBagButton("Button10",gridbag,c);
c.weighty=0.0;
addGridBagButton("Button11",gridbag,c);
c.weighty=0.0;
addGridBagButton("Button12",gridbag,c);
}
public void paint(Graphics g) {
g.drawString("Welcome to Java!!", 50, 60 );
}
}
出錯提示如下:
--------------------Configuration: GridBagLayout - JDK version 1.3.1_04 <Default>--------------------
C:/Program Files/Xinox Software/JCreator Pro/MyProjects/Helloworld3/variableclass/customer/cathcdemo/labeldemo/labeldemo/uselistenerdemo/hello/GridBagLayout/GridBagLayout.java:23: cannot resolve symbol
symbol : method setConstraints (java.awt.Button,java.awt.GridBagConstraints)
location: class GridBagLayout
gb.setConstraints(button,gbc);
^
C:/Program Files/Xinox Software/JCreator Pro/MyProjects/Helloworld3/variableclass/customer/cathcdemo/labeldemo/labeldemo/uselistenerdemo/hello/GridBagLayout/GridBagLayout.java:30: setLayout(java.awt.LayoutManager) in java.awt.Container cannot be applied to (GridBagLayout)
setLayout(gridbag);
^
2 errors
Process completed.
請各位一并幫我的問題解決一下!不好意思啊,樓主,借你貼子用一下
 
顶部