L
laxcompute
Hello-
I've been using Java for quite a while, but I'm fairly new to applets.
I wrote my main program, as a panel and several other classes. Then I
made a driver to run it. It works fine that way, but I'm trying to
eventually get my program onto a webpage. So, I made an applet to call
the Panel, instead of the driver.
When I run the Applet, I get the following message:
However, it works just fine when I run the driver. All of my files are
in the same folder.
Here is the code for the applet:
import javax.swing.JApplet;
public class AppletPotter extends JApplet
{
public void init()
{
try{
setContentPane(new PanelPotter(6,5,6,12));
}
catch(Exception e){
return;
}
}
}
Here is the code for the driver:
import javax.swing.JFrame;
public class DriverPotter
{
public static void main(String[] args) throws Exception
{
JFrame frame = new JFrame("The Game");
frame.setSize(600,440);
frame.setLocation(100,100);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setContentPane(new PanelPotter(6,5,6,12));
frame.setVisible(true);
}
}
And, here is the initialization and construction of the Panel:
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
import javax.xml.parsers.*;
public class PanelPotter extends JPanel
{
private static TextField input;
private static TextArea output;
private static Button go;
private static JScrollPane scroller;
private static int xCenter, yCenter, xPos, yPos, xStart, yStart;
private static Location[][] locations;
public PanelPotter(int xC, int yC, int xS, int yS) throws
Exception
{
locations = LocationReader.toArray("locations.xml");
xCenter = xC;
yCenter = yC;
xStart = xPos = xS;
yStart = yPos = yS;
this.setLayout(new BorderLayout());
try{
output = new TextArea(">>"+locations[xStart]
[yStart].getReply("look around")+"\n",
50,20,TextArea.SCROLLBARS_VERTICAL_ONLY);
}
catch(Exception e){
System.out.println("caught");
return;
}
output.setSize(490,340);
output.setVisible(true);
output.setEditable(false);
input = new TextField();
input.setVisible(true);
input.addKeyListener(new Texter());
add(input, BorderLayout.SOUTH);
add(output, BorderLayout.CENTER);
}
As you can see, my problem happens on this line: output = new
TextArea(">>"+locations[xStart][yStart].getReply("look around")+"\n",
50,20,TextArea.SCROLLBARS_VERTICAL_ONLY);
locations is an array which I read from an XML file, using several
other bits of code. If you need to see them to help with this problem,
just let me know what you need.
Does anyone know how to fix this problem?
Thank you very much!
I've been using Java for quite a while, but I'm fairly new to applets.
I wrote my main program, as a panel and several other classes. Then I
made a driver to run it. It works fine that way, but I'm trying to
eventually get my program onto a webpage. So, I made an applet to call
the Panel, instead of the driver.
When I run the Applet, I get the following message:
However, it works just fine when I run the driver. All of my files are
in the same folder.
Here is the code for the applet:
import javax.swing.JApplet;
public class AppletPotter extends JApplet
{
public void init()
{
try{
setContentPane(new PanelPotter(6,5,6,12));
}
catch(Exception e){
return;
}
}
}
Here is the code for the driver:
import javax.swing.JFrame;
public class DriverPotter
{
public static void main(String[] args) throws Exception
{
JFrame frame = new JFrame("The Game");
frame.setSize(600,440);
frame.setLocation(100,100);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setContentPane(new PanelPotter(6,5,6,12));
frame.setVisible(true);
}
}
And, here is the initialization and construction of the Panel:
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
import javax.xml.parsers.*;
public class PanelPotter extends JPanel
{
private static TextField input;
private static TextArea output;
private static Button go;
private static JScrollPane scroller;
private static int xCenter, yCenter, xPos, yPos, xStart, yStart;
private static Location[][] locations;
public PanelPotter(int xC, int yC, int xS, int yS) throws
Exception
{
locations = LocationReader.toArray("locations.xml");
xCenter = xC;
yCenter = yC;
xStart = xPos = xS;
yStart = yPos = yS;
this.setLayout(new BorderLayout());
try{
output = new TextArea(">>"+locations[xStart]
[yStart].getReply("look around")+"\n",
50,20,TextArea.SCROLLBARS_VERTICAL_ONLY);
}
catch(Exception e){
System.out.println("caught");
return;
}
output.setSize(490,340);
output.setVisible(true);
output.setEditable(false);
input = new TextField();
input.setVisible(true);
input.addKeyListener(new Texter());
add(input, BorderLayout.SOUTH);
add(output, BorderLayout.CENTER);
}
As you can see, my problem happens on this line: output = new
TextArea(">>"+locations[xStart][yStart].getReply("look around")+"\n",
50,20,TextArea.SCROLLBARS_VERTICAL_ONLY);
locations is an array which I read from an XML file, using several
other bits of code. If you need to see them to help with this problem,
just let me know what you need.
Does anyone know how to fix this problem?
Thank you very much!