File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Applets and the fly likes Passing arguments to an applet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Applets
Bookmark "Passing arguments to an applet" Watch "Passing arguments to an applet" New topic
Author

Passing arguments to an applet

Amey Rane
Greenhorn

Joined: Mar 21, 2007
Posts: 15
I am passing two string arguments to the applet SurfCore.class through a cgi script. Please check wheter this is the right way to do it. All HTML code is in the proper tag . I could not keep it this way as its not allowed on the forum due to a security issue
--------------------------------------------------------------------------
print <<ENDF6;

applet code="SurfCore.class" width=900 height=900
param name=bgImage value="IMAGES/PurdueDataNetwork1.6_core.jpg"
param name=bgImage2 value="IMAGES/Router.jpg"
param name=bgImage3 value="IMAGES/CRouter.jpg"
param name=vlan_num value="
param name=vlan_num2 value="
ENDF6
print "$arv2";
print "$arv2_b";

print <<END9;
">/applet
/body
/html
END9
---------------------------------------------------------------------------
I am getting an error which looks like this

java.lang.NullPointerException
at SurfCore.init(SurfCore.java:106)
at sun.applet.AppletPanel.run(AppletPanel.java:380)
at java.lang.Thread.run(Thread.java:595)
---------------------------------------------------------------------------
Finally this is the Java File. The error is originating at line 106 which I have commented in the code as //LINE 106: Error
It just shows that second argument is not getting passed properly...

import java.awt.*;
import java.applet.*;
import java.awt.event.*;
public class SurfCore extends Applet {

Image purdue;
Image router1;
Image router2;
Font bigFont;

String foo;
String foo2;


int size; // counting the no. of vlan#
int size2; // counting the no. of vlan#
int bsize;
int bsize2;

int i = 0; // for iteration
int p = 0;
int w = 0;
int n = 0;
int s = 0;
int m = 0;
int m2= 0;
int k = 0;
int l = 0;
int j = 0;
int h = 0;
int v = 0;
int q = 0;



String[] test2=new String[4];
String[] test3=new String[4];
String[] test_des=new String[4]; // split for designated router
String[] test_des2=new String[4]; // split for designated router
String[] test_des3=new String[4]; // split for designated router
String[] test_des4=new String[4]; // split for designated router
String[] test=new String[500];
String[] V_Array=new String[500];
String[] V_cord =new String[5];


String[] Temp_2 =new String[3];
String[] Temp_3 =new String[3];


int[] test_des_cord=new int[3]; // integer forms
int[] test_des_cord2=new int[3]; // integer forms

String[] btest2=new String[4];
String[] btest3=new String[4];
String[] btest_des=new String[4]; // split for designated router
String[] btest_des2=new String[4]; // split for designated router
String[] btest_des3=new String[4]; // split for designated router
String[] btest_des4=new String[4]; // split for designated router
String[] btest=new String[500];
String[] bV_Array=new String[500];
String[] bV_cord =new String[5];


String[] bTemp_2 =new String[3];
String[] bTemp_3 =new String[3];

int match_flag=0;
int bmatch_flag=0;


int[] btest_des_cord=new int[3]; // integer forms
int[] btest_des_cord2=new int[3]; // integer forms


// The colors you will use
Color redColor;
Color greenColor;
Color blackColor;
Color orangeColor;
Color blueColor;


public void init()

{
bigFont = new Font("Arial",Font.BOLD,13);

// Standard colors can be named like this
redColor = Color.red;
blackColor = Color.black;
orangeColor = Color.orange;
blueColor = Color.blue;
greenColor = Color.green;
// The following 2 lines get the Purdue topology & router image

purdue = getImage(getCodeBase(), getParameter("bgImage"));
router1 = getImage(getCodeBase(), getParameter("bgImage2"));
router2 = getImage(getCodeBase(), getParameter("bgImage3"));


foo = getParameter("vlan_num");
foo2= getParameter("vlan_num2");

test = foo.split(";");
btest = foo2.split(";"); //LINE 106 Error

size = Integer.parseInt(test[(test.length - 4)]);
bsize = Integer.parseInt(btest[(btest.length - 4)]);

size2 = Integer.parseInt(test[(test.length - 5)]);
bsize2 = Integer.parseInt(btest[(btest.length - 5)]);

test_des = test[1].split(":");
test_des2 = test[(test.length - 3)].split(",");
test_des3 = test_des2[0].split("--");
test_des4 = test_des3[0].split("=");

btest_des = btest[1].split(":");
btest_des2 = btest[(btest.length - 3)].split(",");
btest_des3 = btest_des2[0].split("--");
btest_des4 = btest_des3[0].split("=");


Temp_2 = test[1].split(":");
Temp_3 = Temp_2[0].split("--");

bTemp_2 = btest[1].split(":");
bTemp_3 = bTemp_2[0].split("--");



//System.out.println("Value1 = " + test_des_cord[0] + " Value2 = " + test_des_cord[1]);
if (Temp_3[1].equals("lamb")) {
test_des_cord[0] = 212;
test_des_cord[1] = 30;
}else if (Temp_3[1].equals("lynn")) {
test_des_cord[0] = 430;
test_des_cord[1] = 199;
}else if (Temp_3[1].equals("tel")) {
test_des_cord[0] = 293;
test_des_cord[1] = 427;
}else if (Temp_3[1].equals("erht")) {
test_des_cord[0] = 48;
test_des_cord[1] = 210 ;
}

if (test_des4[0].equals("lamb-20-c6509-01")) {
match_flag = 1;
test_des_cord2[0] = 261;
test_des_cord2[1] = 132;
}else if (test_des4[0].equals("lynn-b168-c6509-01")) {
match_flag = 1;
test_des_cord2[0] = 383;
test_des_cord2[1] = 257;
}else if (test_des4[0].equals("tel-210-c6509-01")) {
match_flag = 1;
test_des_cord2[0] = 250;
test_des_cord2[1] = 375;
}else if (test_des4[0].equals("erht-5b-c6509-01")) {
match_flag = 1;
test_des_cord2[0] = 143;
test_des_cord2[1] = 266;
}
if (match_flag != 1) {
if (test_des4[1].equals("lamb")) {
test_des_cord2[0] = 307;
test_des_cord2[1] = 45;
} else if (test_des4[1].equals("lynn")) {
test_des_cord2[0] = 462;
test_des_cord2[1] = 184;
} else if (test_des4[1].equals("tel")) {
test_des_cord2[0] = 214;
test_des_cord2[1] = 476;
} else if (test_des4[1].equals("erht")) {
test_des_cord2[0] = 63;
test_des_cord2[1] = 181;
}
}

if (bTemp_3[1].equals("lamb")) {
btest_des_cord[0] = 212;
btest_des_cord[1] = 30;
}else if (bTemp_3[1].equals("lynn")) {
btest_des_cord[0] = 430;
btest_des_cord[1] = 199;
}else if (bTemp_3[1].equals("tel")) {
btest_des_cord[0] = 293;
btest_des_cord[1] = 427;
}else if (bTemp_3[1].equals("erht")) {
btest_des_cord[0] = 48;
btest_des_cord[1] = 210 ;
}

if (btest_des4[0].equals("lamb-20-c6509-01")) {
bmatch_flag = 1;
btest_des_cord2[0] = 261;
btest_des_cord2[1] = 132;
}else if (btest_des4[0].equals("lynn-b168-c6509-01")) {
bmatch_flag = 1;
btest_des_cord2[0] = 383;
btest_des_cord2[1] = 257;
}else if (btest_des4[0].equals("tel-210-c6509-01")) {
bmatch_flag = 1;
btest_des_cord2[0] = 250;
btest_des_cord2[1] = 375;
}else if (btest_des4[0].equals("erht-5b-c6509-01")) {
bmatch_flag = 1;
btest_des_cord2[0] = 143;
btest_des_cord2[1] = 266;
}
if (bmatch_flag != 1) {
if (btest_des4[1].equals("lamb")) {
btest_des_cord2[0] = 307;
btest_des_cord2[1] = 45;
} else if (btest_des4[1].equals("lynn")) {
btest_des_cord2[0] = 462;
btest_des_cord2[1] = 184;
} else if (btest_des4[1].equals("tel")) {
btest_des_cord2[0] = 214;
btest_des_cord2[1] = 476;
} else if (btest_des4[1].equals("erht")) {
btest_des_cord2[0] = 63;
btest_des_cord2[1] = 181;
}
}


//System.out.println("Value = " + size);
for (i = 0; i < size; i++) {
v = 0;
test2 = test[i+2+size2].split(":");
for (v = 0; v < 3; v++)
{
V_Array[m++] = test2[v];
}
}

for (i = 0; i < bsize; i++) {
v = 0;
btest2 = test[i+2+bsize2].split(":");
for (v = 0; v < 3; v++)
{
bV_Array[m2++] = btest2[v];
}
}

}
//System.out.println("M value = " + m);

// end init()

public void paint(Graphics g) {
//System.out.println(" MATH = " + test[(test.length - 1)]);
g.setFont(bigFont);
g.drawImage(purdue,0,0,this);
g.setColor(blackColor.brighter());
g.drawLine(585,5,585,145);
g.drawLine(586,6,586,146);
g.drawLine(585,5,875,5);
g.drawLine(585,6,875,6);
g.drawLine(585,145,875,145);
g.drawLine(585,146,875,146);
g.drawLine(875,5,875,145);
g.drawLine(876,6,876,146);
g.setColor(orangeColor.darker());
g.drawString("LEGEND",706,25);
g.setColor(blackColor.brighter());
g.drawImage(router1,593,38,null);
g.drawString("CURRENT FIRST-HOP ROUTER",665,70);
g.drawImage(router2,600,90,null);
g.drawString("IDEAL FIRST-HOP ROUTER",665,116);
if (test[(test.length - 1)].equals("YES_MATCH")) {
if (test_des_cord[0] != 0) {
g.drawImage(router1,test_des_cord[0],test_des_cord[1],null);
}
for (q = 1; q < m; q = q + 3) {
V_cord = V_Array[q+1].split(",");
g.drawString(V_Array[q], Integer.parseInt(V_cord[0])+55, Integer.parseInt(V_cord[1])+70);
}
} else {
if (test_des_cord[0] != 0) {
g.drawImage(router1,test_des_cord[0],test_des_cord[1],null);
}
for (q = 1; q < m; q = q + 3) {
V_cord = V_Array[q+1].split(",");
g.drawString(V_Array[q], Integer.parseInt(V_cord[0])+55, Integer.parseInt(V_cord[1])+70);
}
if (test_des_cord2[0] != 0) {
g.drawImage(router2,test_des_cord2[0],test_des_cord2[1],null);
}
}

if (btest[(btest.length - 1)].equals("YES_MATCH")) {
if (btest_des_cord[0] != 0) {
g.drawImage(router1,btest_des_cord[0],btest_des_cord[1],null);
}
for (q = 1; q < m2; q = q + 3) {
bV_cord = bV_Array[q+1].split(",");
g.drawString(bV_Array[q], Integer.parseInt(bV_cord[0])+55, Integer.parseInt(bV_cord[1])+70);
}
} else {
if (btest_des_cord[0] != 0) {
g.drawImage(router1,btest_des_cord[0],btest_des_cord[1],null);
}
for (q = 1; q < m2; q = q + 3) {
bV_cord = bV_Array[q+1].split(",");
g.drawString(bV_Array[q], Integer.parseInt(bV_cord[0])+55, Integer.parseInt(bV_cord[1])+70);
}
if (btest_des_cord2[0] != 0) {
g.drawImage(router2,btest_des_cord2[0],btest_des_cord2[1],null);
}
}
}
} // end class PurdueTopology
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41108
    
  45
It sure looks as if neither vlan_num nor vlan_num2 could possibly be passed correctly. More interesting is what the HTML looks like that gets generated - do a "view source" in the browser, and post the full applet tag.


Ping & DNS - my free Android networking tools app
Norm Radder
Ranch Hand

Joined: Aug 10, 2005
Posts: 685
getParameter() returns null if it can't find the parameter. Check your HTML to see that the requested name is valid.
 
Don't get me started about those stupid light bulbs.
 
subject: Passing arguments to an applet
 
Similar Threads
Help on java graph applet
Applet Problems
Applet not initialized error
Applet Not initialized error
Scrollbar not working