Things Visible in Two Classes
I'm developing a program using two classes: "Analysis.class" and "AnalysisCalc.class", each in separate files. I don't desire to import either class via package design. I'm trying to call a method from "AnalysisCalc.class" using variables visible to both classes. The intent of the program is to decrement a variable using a while loop. The intent of using "AnalysisCalc.class" is to manage my code better rather than consolidate all the code in "Analysis.class". How do I modify the following source code for these classes?
(NOTE: Don't worry about other aspects of program such as I/O since I know how to handle that )
// Analysis Program: Analysis.java
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
publicclass Analysisextends JAppletimplements ActionListener{
double variableX;
boolean variableA, variableB;
publicvoid init()
{
variableX = 0;
variableA =true;
variableB =true;
}// end method init
publicvoid strt()
{
while(variableB){
rundata();
if( variableX < 10 )
variableB =false;
}
}// end method strt
strt();
}//end class Analysis
// AnalysisCalc.java
publicclass AnalysisCalc{
// AnalysisCalc constructor
public AnalysisCalc()
{
rundata( );
}
publicvoid rundata( )
{
if( variableA ==true)
{
variableX = 100;
variableA =false;
}
variableX--;
}
}// end class AnalysisCalc
If you want to access member variables of other classes directly (this is a bad practice), you first need to have an instance of that class.Analysic a = new Analysis();a.variableX = true;Is this homework?
> I'm trying to call a method from
> "AnalysisCalc.class" using variables visible to both
> classes.
but in your code example the variables are not visible to each class
You need to learn about object references. Please see the java tutorials (link in left column). For AnalysisCalc to modify an instance variable of Analysis it would need a REFERENCE to an instance of Analysis.
> The intent of the program is to decrement a
> variable using a while loop.
Why not just assign the value after you're done counting down?
> The intent of using
> "AnalysisCalc.class" is to manage my code better
> rather than consolidate all the code in
> "Analysis.class".
In your example, I'd say there's no point in splitting the code into 2 classes. In fact, it violates encapsulation - why is AnalysisCalc modifying internal state of another class? Why not have analysis calc hold onto the values and have Analysis look at them when appropriate (if ever).
> How do I modify the following source
> code for these classes?
>
(Again, see my comments above about analysis calc 'owning' the data its modifying)
Pass a reference to AnalysisCalc like:
public class AnalysisCalc {
private Analysis analysis;
// AnalysisCalc constructor
public AnalysisCalc(Analysis analysis)
{
this.analysis = analysis;
rundata( );
}
public void rundata( )
{
if( analysis.variableA == true)
{
analysis.variableX = 100;
analysis.variableA = false;
}
analysis.variableX--;
}
}
> (NOTE: Don't worry about other aspects of program such
> as I/O since I know how to handle that )
I'm not worried; but I don't really believe you either... :\
BacMan:No, this is not homework. I tried to make my problem simple. Now, Ill replace the problem with a more complex problem.
OK, forget the code I posted previously.
The following code in files Trajectory.java and Calculate.java have a similar problem. I'm trying to get my method set up simple with a decrement logic because later the logic for the method will become more complex. I want to keep all this complex code out of the Trajectory.java file and manage it from the Calculate.java file. I would set up package and import design, but my ISP will not accept package design in building website since fully qualified names must be used to avoid naming conflicts.
key code segments in file trajectory.java, being analogous to Analysis.java, include>
Calculate Z = new Calculate();
while(sentinel){
Z.rundata();
if( altitude < 10 )
sentinel = false;
}
The file analogous to AnalysisCalc.java is Calculate.java
// Trajectory Analysis Program: Trajectory.java
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Trajectory extends JApplet implements ActionListener {
final double MAX = 90.0;
final double MIN = -90.0;
final double MAX_ALTITUDE = 2000000.0;
final double MIN_ALTITUDE = 0.0;
private JTextArea introductionArea, resultsArea;
private JLabel spanLabel, chordLabel,
thicknessLabel, massLabel, altitudeLabel, velocityLabel,
trajectory_angleLabel, time_incrementLabel, rotation_factorLabel,
calculationLabel, resultsLabel;
private JTextField spanField, chordField, thicknessField,
massField, altitudeField, velocityField, trajectory_angleField,
time_incrementField, rotation_factorField;
private JButton startButton, resetButton, contButton, abortButton;
String introduction_string, span_string, chord_string, thickness_string, mass_string,
altitude_string, velocity_string, trajectory_angle_string,
time_increment_string, rotation_factor_string, results_string;
public double span, chord, thickness, mass, altitude, velocity, trajectory_angle, time_increment,
rotation_factor, distance, velocity_fps, elapsed_time;
boolean value, sentinel;
// create objects
public void init()
{
Calculate Z = new Calculate();
span = 0;
chord = 0;
thickness = 0;
mass = 0;
altitude = 0;
velocity = 0;
trajectory_angle = 0;
time_increment = 0;
rotation_factor = 0;
distance = 0;
velocity_fps = 0;
elapsed_time = 0;
velocity_fps = 0;
elapsed_time = 0;
value = true;
sentinel = true;
introduction_string =
"DEBRIS TRAJECTORY PROGRAM\n"
+ "designed by Weldon K. Chafin, Jr.\n\n"
+ "Inspired by the brave heroes of the Columbia Accident "
+ "of February 1, 2003.\n\n"
+ "This program determines trajectory for an object modeled "
+ "as a rectangular prism having given mass falling through "
+ "the atmosphere. The object is assumed to oscillate with same "
+ "frequency about all six possible permutations for axis "
+ "angular velocity vectors as the means to simulate "
+ "equally likely random events.\n\n"
+ "NOTE: This program is still under construction. "
+ "I predict this program will be fully functional by October 4, 2003. "
+ "Then it should have calculation capability comparable to the C++ program version I created "
+ "for the Columbia Accident Investigation Board (CAIB) to predict locations of Columbia debris. "
+ "In fact, the CAIB forwarded my program as an analytical tool to NASA "
+ "JSE Early Sightings Assessment Team tasked with finding high interest "
+ "Columbia debris items via radar imaging.";
span_string = "";
chord_string = "";
thickness_string = "";
mass_string = "";
altitude_string = "";
velocity_string = "";
trajectory_angle_string = "";
time_increment_string = "";
rotation_factor_string = "";
results_string = "";
// create container & panel
Container container = getContentPane();
Panel panel = new Panel( new FlowLayout( FlowLayout.LEFT));
container.add( panel );
// set up vertical boxlayout
Box box = Box.createVerticalBox();
Box inputbox1 = Box.createHorizontalBox();
Box inputbox2 = Box.createHorizontalBox();
Box inputbox2a = Box.createHorizontalBox();
Box inputbox2b = Box.createHorizontalBox();
Box inputbox2c = Box.createHorizontalBox();
Box inputbox2d = Box.createHorizontalBox();
Box inputbox3 = Box.createHorizontalBox();
Box buttonbox = Box.createHorizontalBox();
// set up introduction
introductionArea = new JTextArea( introduction_string, 10, 50 );
introductionArea.setEditable( false );
box.add( new JScrollPane( introductionArea ) );
box.add( Box.createVerticalStrut (10) );
box.add( inputbox1);
box.add(inputbox2a);
Dimension minSize = new Dimension(5, 15);
Dimension prefSize = new Dimension(5, 15);
Dimension maxSize = new Dimension(Short.MAX_VALUE, 15);
inputbox2a.add(new Box.Filler(minSize, prefSize, maxSize));
// set up span
spanLabel = new JLabel( "span (feet)" );
spanField = new JTextField(5 );
inputbox2a.add( spanLabel );
inputbox2a.add( spanField );
inputbox2a.add(new Box.Filler(minSize, prefSize, maxSize));
// set up chord
chordLabel = new JLabel( "chord (feet)" );
chordField = new JTextField(5 );
inputbox2a.add( chordLabel );
inputbox2a.add( chordField );
inputbox2a.add(new Box.Filler(minSize, prefSize, maxSize));
// set up thickness
thicknessLabel = new JLabel( "thickness (feet)" );
thicknessField = new JTextField(5 );
inputbox2a.add( thicknessLabel );
inputbox2a.add( thicknessField );
inputbox2a.add(new Box.Filler(minSize, prefSize, maxSize));
box.add( Box.createVerticalStrut (10) );
box.add(inputbox2b);
inputbox2b.add(new Box.Filler(minSize, prefSize, maxSize));
// set up mass
massLabel = new JLabel( "mass (slugs)" );
massField = new JTextField(5);
inputbox2b.add( massLabel );
inputbox2b.add( massField );
inputbox2b.add(new Box.Filler(minSize, prefSize, maxSize));
// set up altitude
altitudeLabel = new JLabel( "altitude (feet)");
altitudeField = new JTextField(5 );
inputbox2b.add( altitudeLabel );
inputbox2b.add( altitudeField );
inputbox2b.add(new Box.Filler(minSize, prefSize, maxSize));
// set up velocity
velocityLabel = new JLabel( "velocity (Mach Number)");
velocityField = new JTextField(5);
inputbox2b.add( velocityLabel );
inputbox2b.add( velocityField );
inputbox2b.add(new Box.Filler(minSize, prefSize, maxSize));
box.add( Box.createVerticalStrut (10) );
Dimension minSize2c = new Dimension(160, 15);
Dimension prefSize2c = new Dimension(160, 15);
Dimension maxSize2c = new Dimension(Short.MAX_VALUE, 15);
box.add(inputbox2c);
inputbox2c.add(new Box.Filler(minSize2c, prefSize2c, maxSize2c));
// set up trajectory_angle
trajectory_angleLabel = new JLabel( "trajectory angle (degrees)");
trajectory_angleField = new JTextField(5);
inputbox2c.add( trajectory_angleLabel );
inputbox2c.add( trajectory_angleField );
inputbox2c.add(new Box.Filler(minSize2c, prefSize2c, maxSize2c));
box.add( Box.createVerticalStrut (10) );
Dimension minSize2d = new Dimension(50, 15);
Dimension prefSize2d = new Dimension(50, 15);
Dimension maxSize2d = new Dimension(Short.MAX_VALUE, 15);
box.add(inputbox2d);
inputbox2d.add(new Box.Filler(minSize2d, prefSize2d, maxSize2d));
// set up time_increment
time_incrementLabel = new JLabel( "time increment (seconds)" );
time_incrementField = new JTextField(5);
inputbox2d.add( time_incrementLabel );
inputbox2d.add( time_incrementField );
inputbox2d.add(new Box.Filler(minSize2d, prefSize2d, maxSize2d));
// set up rotation_factor
rotation_factorLabel = new JLabel( "rotation factor (number)" );
rotation_factorField = new JTextField(5);
inputbox2d.add( rotation_factorLabel );
inputbox2d.add( rotation_factorField );
inputbox2d.add(new Box.Filler(minSize2d, prefSize2d, maxSize2d));
box.add( Box.createVerticalStrut (10) );
box.add( buttonbox);
Dimension minSizeB = new Dimension(10, 30);
Dimension prefSizeB = new Dimension(10, 30);
Dimension maxSizeB = new Dimension(Short.MAX_VALUE, 30);
buttonbox.add(new Box.Filler(minSizeB, prefSizeB, maxSizeB));
// set up start
startButton = new JButton( "START" );
buttonbox.add( startButton );
buttonbox.add(new Box.Filler(minSizeB, prefSizeB, maxSizeB));
// set up reset
resetButton = new JButton( "RESET" );
buttonbox.add( resetButton );
buttonbox.add(new Box.Filler(minSizeB, prefSizeB, maxSizeB));
// set up cont
contButton = new JButton( "CONTINUE" );
buttonbox.add( contButton );
buttonbox.add(new Box.Filler(minSizeB, prefSizeB, maxSizeB));
// set up abort
abortButton = new JButton( "ABORT" );
buttonbox.add( abortButton );
buttonbox.add(new Box.Filler(minSizeB, prefSizeB, maxSizeB));
box.add( Box.createVerticalStrut (10) );
// set up results
resultsArea = new JTextArea( results_string, 6, 50 );
resultsArea.setEditable( false );
box.add( new JScrollPane( resultsArea ) );
// add box to panel
panel.add( box );
// register event handlers
spanField.addActionListener( this );
chordField.addActionListener( this );
thicknessField.addActionListener( this );
massField.addActionListener( this );
altitudeField.addActionListener( this );
velocityField.addActionListener( this );
trajectory_angleField.addActionListener( this );
time_incrementField.addActionListener( this );
rotation_factorField.addActionListener( this );
startButton.addActionListener( this );
resetButton.addActionListener( this );
contButton.addActionListener( this );
abortButton.addActionListener( this );
reset();
} // end method init
public void t_r_a_test (double trajectory_angle) throws Tare {
if (trajectory_angle > MAX || trajectory_angle < MIN)
throw new Tare("\ntrajectory_angle "
+ trajectory_angle + " is outside of allowable range\n\n"
+ "Try another value for the trajectory angle\n"
+ "( " + MIN + " <= trajectory angle <= " + MAX + " )" );
} // end method t_r_a_test
public void a_r_e_test (double altitude) throws Are {
if ( altitude > MAX_ALTITUDE )
throw new Are("\naltitude "
+ altitude + " is outside of allowable range\n\n"
+ "Try value for altitude\n"
+ "( " + MIN_ALTITUDE + " <= altitude <= "
+ MAX_ALTITUDE + " )" );
} // end method a_r_e_test
public void n_v_test (boolean value) throws Nve {
if ( value == false ){
if( span < 0 ){
span = 0;
throw new Nve("\nValue for "
+ " span must not be negative\n\n"
+ "Try another value ");
}
if( chord < 0 ){
chord = 0;
throw new Nve("\nValue for "
+ " chord must not be negative\n\n"
+ "Try another value ");
}
if( thickness < 0 ){
thickness = 0;
throw new Nve("\nValue for "
+ " thickness must not be negative\n\n"
+ "Try another value ");
}
if( mass < 0 ){
mass = 0;
throw new Nve("\nValue for "
+ " mass must not be negative\n\n"
+ "Try another value ");
}
if( altitude < 0 ){
altitude = 0;
throw new Nve("\nValue for "
+ " altitude must not be negative\n\n"
+ "Try another value ");
}
if( velocity < 0 ){
velocity = 0;
throw new Nve("\nValue for "
+ " velocity must not be negative\n\n"
+ "Try another value ");
}
if( time_increment < 0 ){
time_increment = 0;
throw new Nve("\nValue for "
+ " time increment must not be negative\n\n"
+ "Try another value ");
}
if( rotation_factor < 0 ){
rotation_factor = 0;
throw new Nve("\nValue for "
+ " rotation factor must not be negative\n\n"
+ "Try another value ");
}
} //end if( value == false )
} // end method n_v_test
// process events
public void actionPerformed( ActionEvent event )
{
// process spanField
if( event.getSource() == spanField ) {
span_string = spanField.getText();
span = Double.parseDouble( span_string);
}
// process chordField
if( event.getSource() == chordField ) {
chord_string = chordField.getText();
chord = Double.parseDouble( chord_string);
}
// process thicknessField
if( event.getSource() == thicknessField ) {
thickness_string = thicknessField.getText();
thickness = Double.parseDouble( thickness_string);
}
// process massField
if( event.getSource() == massField ) {
mass_string = massField.getText();
mass = Double.parseDouble( mass_string);
}
// process altitudeField
if( event.getSource() == altitudeField ){
altitude_string = altitudeField.getText();
altitude = Double.parseDouble( altitude_string);
}
// process velocityField
if( event.getSource() == velocityField ){
velocity_string = velocityField.getText();
velocity = Double.parseDouble( velocity_string);
}
// process trajectory_angleField
if( event.getSource() == trajectory_angleField ){
trajectory_angle_string = trajectory_angleField.getText();
trajectory_angle = Double.parseDouble( trajectory_angle_string);
}
// process time_incrementField
if( event.getSource() == time_incrementField ){
time_increment_string = time_incrementField.getText();
time_increment = Double.parseDouble( time_increment_string);
}
// process rotation_factorField
if( event.getSource() == rotation_factorField ){
rotation_factor_string = rotation_factorField.getText();
rotation_factor = Double.parseDouble( rotation_factor_string);
}
// process startButton event
if ( event.getSource() == startButton )
strtb();
// process resetButton event
if ( event.getSource() == resetButton )
reset();
// process contButton event
if ( event.getSource() == contButton )
cont();
// process abortButton event
if ( event.getSource() == abortButton )
abort();
} // end method actionPerformed
public void strtb()
{
try{
span = Double.parseDouble( spanField.getText() );
chord = Double.parseDouble( chordField.getText() );
thickness = Double.parseDouble( thicknessField.getText() );
mass = Double.parseDouble( massField.getText() );
altitude = Double.parseDouble( altitudeField.getText());
velocity = Double.parseDouble( velocityField.getText());
trajectory_angle = Double.parseDouble( trajectory_angleField.getText());
time_increment = Double.parseDouble( time_incrementField.getText() );
rotation_factor = Double.parseDouble( rotation_factorField.getText() );
if( span < 0 || chord < 0 || thickness < 0 || mass < 0
|| altitude < 0 || velocity < 0
|| time_increment < 0 || rotation_factor < 0 )
value = false;
t_r_a_test( trajectory_angle );
n_v_test( value );
a_r_e_test( altitude );
while(sentinel){
Z.rundata();
if( altitude < 10 )
sentinel = false;
}
results();
resultsArea.setText( results() );
}//end try
// process improperly formatted input
catch ( NumberFormatException numberFormatException ) {
JOptionPane.showMessageDialog( this,
"You must enter numbers in decimal format or integers",
"Invalid Number Format" ,
JOptionPane.ERROR_MESSAGE );
} // end catch NumberFormatException
catch ( ArithmeticException arithmeticException ) {
JOptionPane.showMessageDialog( this,
arithmeticException.toString(), "Arithmetic Exception" ,
JOptionPane.ERROR_MESSAGE );
} // end catch ArithmeticException
catch ( Tare tare ) {
JOptionPane.showMessageDialog( this,
tare.toString(), "-90 <= range <= 90 " ,
JOptionPane.ERROR_MESSAGE );
} // end catch Tare
catch ( Nve nve ) {
JOptionPane.showMessageDialog( this,
nve.toString(), " value less than zero" ,
JOptionPane.ERROR_MESSAGE );
} // end catch Nve
catch ( Are are ) {
JOptionPane.showMessageDialog( this,
are.toString(), " value greater than maximum" ,
JOptionPane.ERROR_MESSAGE );
} // end catch Are
} // end method strtb
public void reset()
{
span_string = "";
chord_string = "";
thickness_string = "";
mass_string = "";
altitude_string = "";
velocity_string = "";
trajectory_angle_string = "";
time_increment_string = "";
rotation_factor_string = "";
results_string = "";
spanField.setText( span_string );
chordField.setText( chord_string );
thicknessField.setText( thickness_string );
massField.setText( mass_string );
altitudeField.setText( altitude_string );
velocityField.setText( velocity_string );
trajectory_angleField.setText( trajectory_angle_string );
time_incrementField.setText( time_increment_string );
rotation_factorField.setText( rotation_factor_string );
resultsArea.setEditable( true );
resultsArea.setText( results_string );
resultsArea.setEditable( false );
span = 0;
chord = 0;
thickness = 0;
mass = 0;
altitude = 0;
velocity = 0;
trajectory_angle = 0;
time_increment = 0;
rotation_factor = 0;
distance = 0;
velocity_fps = 0;
elapsed_time = 0;
value = true;
}// end method reset
public void cont()
{
//later
}
public void abort()
{
//later
}
public String results()
{
results_string =
"Distance =\t\t" + distance + " miles\n"
+ "Altitude =\t\t" + altitude + " feet\n"
+ "Trajectory Angle =\t" + trajectory_angle + " degrees\n"
+ "Velocity =\t\t" + velocity_fps + " feet per second\n"
+ "Elapsed Time =\t\t" + elapsed_time + " seconds\n";
return results_string;
}
} //end class Trajectory
[code]
// Trajectory Analysis Program: Calculate.java
public class Calculate {
Trajectory T = new Trajectory();
// Calculate constructor
public Calculate()
{
rundata( );
}
public void rundata( )
{
T.altitude--;
}
} // end class Calculate
[/code]
Get rid of the creation of a new Trajectory object in the Calculate class and pass the instance of the current one to the rundata() method instead.
In the Trajectory class:
Calculate Z = new Calculate();
Z.rundata(this);
In the Calculate class:
public void rundata(Trajcectory T)
{
T.altitude--;
}
As was said before, it isn't good practice to access fields of an object directly. You should use accessor methods (setters and getters).
eriklindquist:
I tried your suggestion, but it doesn't work.
This is what I did in trajectory.java:
"Calculate Z = new Calculate();" was retained in the init method definition as before.
The while statement in strtb method definition was changed to:
while(sentinel){
Z.rundata(this);
if( altitude < 10 )
sentinel = false;
}
The following is Calculate.java file:
// Trajectory Analysis Program: Calculate.java
public class Calculate {
// Calculate constructor
public Calculate()
{
rundata( );
}
public void rundata( Trajectory T)
{
T.altitude--;
}
} // end class Calculate
These are the compile errors
C:\JAVATEMP>calculate.java
C:\JAVATEMP>javac trajectory.java
trajectory.java:12: class Trajectory is public, should be declared in a file na
ed Trajectory.java
public class Trajectory extends JApplet implements ActionListener {
^
trajectory.java:49: cannot resolve symbol
symbol : class Calculate
location: class Trajectory
Calculate Z = new Calculate();
^
trajectory.java:49: cannot resolve symbol
symbol : class Calculate
location: class Trajectory
Calculate Z = new Calculate();
^
trajectory.java:539: cannot resolve symbol
symbol : variable Z
location: class Trajectory
Z.rundata(this);
^
4 errors
C:\JAVATEMP>javac calculate.java
calculate.java:3: class Calculate is public, should be declared in a file named
Calculate.java
public class Calculate {
^
calculate.java:14: cannot resolve symbol
symbol : class Trajectory
location: class Calculate
public void rundata( Trajectory T)
^
calculate.java:10: rundata(Trajectory) in Calculate cannot be applied to ()
rundata( );
^
3 errors
Java is case sensitive. If your class is called Trajectory then it needs
to be in a file called Trajectory.java. Currently your file is called
trajectory.java. The same is true for the Calculate class.
That accounts for all of the errors you posted. Others may appear when
you resolve this issue though :)
matfud
OK, corrected file name... the new compile error messages are as follows:
C:\JAVATEMP>javac Trajectory.java
Trajectory.java:49: cannot resolve symbol
symbol : class Calculate
location: class Trajectory
Calculate Z = new Calculate();
^
Trajectory.java:49: cannot resolve symbol
symbol : class Calculate
location: class Trajectory
Calculate Z = new Calculate();
^
Trajectory.java:539: cannot resolve symbol
symbol : variable Z
location: class Trajectory
Z.rundata(this);
^
3 errors
C:\JAVATEMP>javac Calculate.java
Calculate.java:14: cannot resolve symbol
symbol : class Trajectory
location: class Calculate
public void rundata( Trajectory T)
^
Calculate.java:10: rundata(Trajectory) in Calculate cannot be applied to ()
rundata( );
^
2 errors
OK, my computer does strange things when coping and saving files. It apparently is having trouble changing case even when I rename a file. However, I think I found a work around by copying and saving as totally different characters in name string, deleting old files and then saving new name as correct name.
Now, I get the following sets of compile errors:
C:\JAVATEMP>javac Trajectory.java
Trajectory.java:539: cannot resolve symbol
symbol : variable Z
location: class Trajectory
Z.rundata(this);
^
.\Calculate.java:10: rundata(Trajectory) in Calculate cannot be applied to ()
rundata( );
^
2 errors
C:\JAVATEMP>javac Calculate.java
Calculate.java:10: rundata(Trajectory) in Calculate cannot be applied to ()
rundata( );
^
.\Trajectory.java:539: cannot resolve symbol
symbol : variable Z
location: class Trajectory
Z.rundata(this);
^
2 errors
OK, Maybe it's a problem with HTML as well. I attempted the following( note that it still refers to lowercase name even though I deleted it!):
C:\JAVATEMP>javac -d Trajectory.java
C:\JAVATEMP>javac -d Calculate.java
C:\JAVATEMP>appletviewer Trajectory.html
java.lang.NoClassDefFoundError: Trajectory (wrong name: trajectory)
at java.lang.ClassLoader.defineClass0(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:502)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:12
3)
at sun.applet.AppletClassLoader.findClass(AppletClassLoader.java:148)
at java.lang.ClassLoader.loadClass(ClassLoader.java:299)
at sun.applet.AppletClassLoader.loadClass(AppletClassLoader.java:114)
at java.lang.ClassLoader.loadClass(ClassLoader.java:255)
at sun.applet.AppletClassLoader.loadCode(AppletClassLoader.java:501)
at sun.applet.AppletPanel.createApplet(AppletPanel.java:566)
at sun.applet.AppletPanel.runLoader(AppletPanel.java:495)
at sun.applet.AppletPanel.run(AppletPanel.java:292)
at java.lang.Thread.run(Thread.java:536)
The appletviewer states "Start: applet not initialized"
This is the HTML for file Trajectory.html:
<html>
<Head>
</Head>
<Body>
<applet code = "Trajectory.class"
width = "600" height = "480"
>
Your browser is completely ignoring the <APPLET> tag!
</APPLET>
</Body>
</html>
To compile your two classes you should probably do
javac *.java
as java requires you to specify all files that may be used which need
compilation at the same time. This is so that java can resolve the
dependencies between the .java files.
The error you are getting from appletviewer
java.lang.NoClassDefFoundError: Trajectory (wrong name: trajectory)
suggests that you still have a problem with capitalisation.
(note that Trajectory has a capital T inthe first case and small t in
the second)
Your html file looks OK.
matfud
You also should not need the -d option to javac (You seem to be usingit incorrectly anyway as you are not specifying the output directorymatfud
I tried appletviewer again and now message is:
C:\JAVATEMP>appletviewer Trajectory.html
load: class Trajectory.class not found.
java.lang.ClassNotFoundException: Trajectory.class
at sun.applet.AppletClassLoader.findClass(AppletClassLoader.java:153)
at java.lang.ClassLoader.loadClass(ClassLoader.java:299)
at sun.applet.AppletClassLoader.loadClass(AppletClassLoader.java:114)
at java.lang.ClassLoader.loadClass(ClassLoader.java:255)
at sun.applet.AppletClassLoader.loadCode(AppletClassLoader.java:506)
at sun.applet.AppletPanel.createApplet(AppletPanel.java:566)
at sun.applet.AppletPanel.runLoader(AppletPanel.java:495)
at sun.applet.AppletPanel.run(AppletPanel.java:292)
at java.lang.Thread.run(Thread.java:536)
Caused by: java.io.FileNotFoundException: C:\JAVATEMP\Trajectory\class.class (Th
e system cannot find the path specified)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(FileInputStream.java:103)
at java.io.FileInputStream.<init>(FileInputStream.java:66)
at sun.net.www.protocol.file.FileURLConnection.connect(FileURLConnection
.java:69)
at sun.net.www.protocol.file.FileURLConnection.getInputStream(FileURLCon
nection.java:156)
Im not sure why this is appearing in your stack trace
Caused by: java.io.FileNotFoundException: C:\JAVATEMP\Trajectory\class.class (Th
e system cannot find the path specified)
This says that the appletviewer is looking for a directory called
Trajectory.
Does this exist in JAVATEMP? it may have been created by your use of the
However the problem is most likely cause by some mis-spelling somewhere
run del *.class
in your JAVATEMP directory then check the spelling of class names
and their corresponding directorys. Then recompile using javac *.java
(I'm assuming you only have the .java files for this project in this
directory.
Thats all the advice I can give for the moment. Its late and I need to
sleep. If you still have problems, I'll look at this thread again
tomorrow. (If you are lucky someone else may help before then though)
matfud
I did something else instead. I created a new directory "JTEMP" and put the relevant files there and then compiled. Thanks for advice. Sweet dreams. Maybe you can revisit my problem.
The following is result:
Directory of C:\JTEMP
09/30/2003 08:56 PM<DIR> .
09/30/2003 08:56 PM<DIR> ..
09/30/2003 08:58 PM221 Nve.java
09/30/2003 08:59 PM218 Tare.java
09/30/2003 08:59 PM234 Are.java
09/30/2003 09:00 PM17,480 Trajectory.java
09/30/2003 09:00 PM257 Calculate.java
09/30/2003 09:02 PM200 Trajectory.html
6 File(s) 18,610 bytes
2 Dir(s) 28,743,237,632 bytes free
C:\JTEMP>javac *.java
Calculate.java:10: rundata(Trajectory) in Calculate cannot be applied to ()
rundata( );
^
Trajectory.java:539: cannot resolve symbol
symbol : variable Z
location: class Trajectory
Z.rundata(this);
^
2 errors
Two ways of doing this
Use "static" i.e Instead of
boolean variableA, variableB
do as:
public static boolean variableA, variableB
By default if you don't put private or public in start, the
default is private which means "no other class" can use these
variables. We put static to "share the values" among more than one class
To access from AnalysisCalc, simply do:
Analysis.variableA;
Analysis.variableB;
Another way of doing this, is use "inner classes" which is a class
inside another class. The inner class can access the variables on the
outside class without using static: Example below:
public class Analysis extends JApplet implements ActionListener {
double variableX;
boolean variableA, variableB;
public class AnalysisCalc {
public AnalysisCalc(){
rundata( );
}
public void rundata( ) {
if (variableA == true) {
variableX = 100;
variableA = false;
}
variableX--;
}
}
}
akhalil100:
I really received word that the "static" option doesn't work since I don't declare packages which is something I want to avoid. Also, my current problem is with a different set of code other than the simpler set you advised. Nevertheless, I tried using "public static" and the problem persists. My next post will reflect all the code set. The following shows what happens when I compile.
Directory of C:\j2sdk1.4.2_01\bin\JTEMP
09/30/2003 08:56 PM<DIR> .
09/30/2003 08:56 PM<DIR> ..
09/30/2003 08:58 PM221 Nve.java
09/30/2003 08:59 PM218 Tare.java
09/30/2003 08:59 PM234 Are.java
10/01/2003 07:15 AM17,501 Trajectory.java
09/30/2003 09:00 PM257 Calculate.java
09/30/2003 09:02 PM200 Trajectory.html
6 File(s) 18,631 bytes
2 Dir(s) 28,741,271,552 bytes free
C:\j2sdk1.4.2_01\bin\JTEMP>javac *.java
Calculate.java:10: rundata(Trajectory) in Calculate cannot be applied to ()
rundata( );
^
Trajectory.java:539: cannot resolve symbol
symbol : variable Z
location: class Trajectory
Z.rundata(this);
^
2 errors
C:\j2sdk1.4.2_01\bin\JTEMP>dir
Volume in drive C is WIN_ME
Volume Serial Number is 2721-07F1
Directory of C:\j2sdk1.4.2_01\bin\JTEMP
09/30/2003 08:56 PM<DIR> .
09/30/2003 08:56 PM<DIR> ..
09/30/2003 08:58 PM221 Nve.java
09/30/2003 08:59 PM218 Tare.java
09/30/2003 08:59 PM234 Are.java
10/01/2003 07:15 AM17,501 Trajectory.java
09/30/2003 09:00 PM257 Calculate.java
09/30/2003 09:02 PM200 Trajectory.html
10/01/2003 07:17 AM261 Are.class
7 File(s) 18,892 bytes
2 Dir(s) 28,741,238,784 bytes free
C:\j2sdk1.4.2_01\bin\JTEMP>
The current status of my code as of Oct. 1 7:30 AM Central Time is as following:
Trajectory.html>
<html>
<Head>
</Head>
<Body>
<applet code = "Trajectory.class"
width = "600" height = "480"
>
Your browser is completely ignoring the <APPLET> tag!
</APPLET>
</Body>
</html>
Trajectory.java >
// Trajectory Analysis Program: Trajectory.java
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Trajectory extends JApplet implements ActionListener {
final double MAX = 90.0;
final double MIN = -90.0;
final double MAX_ALTITUDE = 2000000.0;
final double MIN_ALTITUDE = 0.0;
private JTextArea introductionArea, resultsArea;
private JLabel spanLabel, chordLabel,
thicknessLabel, massLabel, altitudeLabel, velocityLabel,
trajectory_angleLabel, time_incrementLabel, rotation_factorLabel,
calculationLabel, resultsLabel;
private JTextField spanField, chordField, thicknessField,
massField, altitudeField, velocityField, trajectory_angleField,
time_incrementField, rotation_factorField;
private JButton startButton, resetButton, contButton, abortButton;
String introduction_string, span_string, chord_string, thickness_string, mass_string,
altitude_string, velocity_string, trajectory_angle_string,
time_increment_string, rotation_factor_string, results_string;
public static double span, chord, thickness, mass, altitude, velocity, trajectory_angle, time_increment,
rotation_factor, distance, velocity_fps, elapsed_time;
public static boolean value, sentinel;
// create objects
public void init()
{
Calculate Z = new Calculate();
span = 0;
chord = 0;
thickness = 0;
mass = 0;
altitude = 0;
velocity = 0;
trajectory_angle = 0;
time_increment = 0;
rotation_factor = 0;
distance = 0;
velocity_fps = 0;
elapsed_time = 0;
velocity_fps = 0;
elapsed_time = 0;
value = true;
sentinel = true;
introduction_string =
"DEBRIS TRAJECTORY PROGRAM\n"
+ "designed by Weldon K. Chafin, Jr.\n\n"
+ "Inspired by the brave heroes of the Columbia Accident "
+ "of February 1, 2003.\n\n"
+ "This program determines trajectory for an object modeled "
+ "as a rectangular prism having given mass falling through "
+ "the atmosphere. The object is assumed to oscillate with same "
+ "frequency about all six possible permutations for axis "
+ "angular velocity vectors as the means to simulate "
+ "equally likely random events.\n\n"
+ "NOTE: This program is still under construction. "
+ "I predict this program will be fully functional by October 4, 2003. "
+ "Then it should have calculation capability comparable to the C++ program version I created "
+ "for the Columbia Accident Investigation Board (CAIB) to predict locations of Columbia debris. "
+ "In fact, the CAIB forwarded my program as an analytical tool to NASA "
+ "JSE Early Sightings Assessment Team tasked with finding high interest "
+ "Columbia debris items via radar imaging.";
span_string = "";
chord_string = "";
thickness_string = "";
mass_string = "";
altitude_string = "";
velocity_string = "";
trajectory_angle_string = "";
time_increment_string = "";
rotation_factor_string = "";
results_string = "";
// create container & panel
Container container = getContentPane();
Panel panel = new Panel( new FlowLayout( FlowLayout.LEFT));
container.add( panel );
// set up vertical boxlayout
Box box = Box.createVerticalBox();
Box inputbox1 = Box.createHorizontalBox();
Box inputbox2 = Box.createHorizontalBox();
Box inputbox2a = Box.createHorizontalBox();
Box inputbox2b = Box.createHorizontalBox();
Box inputbox2c = Box.createHorizontalBox();
Box inputbox2d = Box.createHorizontalBox();
Box inputbox3 = Box.createHorizontalBox();
Box buttonbox = Box.createHorizontalBox();
// set up introduction
introductionArea = new JTextArea( introduction_string, 10, 50 );
introductionArea.setEditable( false );
box.add( new JScrollPane( introductionArea ) );
box.add( Box.createVerticalStrut (10) );
box.add( inputbox1);
box.add(inputbox2a);
Dimension minSize = new Dimension(5, 15);
Dimension prefSize = new Dimension(5, 15);
Dimension maxSize = new Dimension(Short.MAX_VALUE, 15);
inputbox2a.add(new Box.Filler(minSize, prefSize, maxSize));
// set up span
spanLabel = new JLabel( "span (feet)" );
spanField = new JTextField(5 );
inputbox2a.add( spanLabel );
inputbox2a.add( spanField );
inputbox2a.add(new Box.Filler(minSize, prefSize, maxSize));
// set up chord
chordLabel = new JLabel( "chord (feet)" );
chordField = new JTextField(5 );
inputbox2a.add( chordLabel );
inputbox2a.add( chordField );
inputbox2a.add(new Box.Filler(minSize, prefSize, maxSize));
// set up thickness
thicknessLabel = new JLabel( "thickness (feet)" );
thicknessField = new JTextField(5 );
inputbox2a.add( thicknessLabel );
inputbox2a.add( thicknessField );
inputbox2a.add(new Box.Filler(minSize, prefSize, maxSize));
box.add( Box.createVerticalStrut (10) );
box.add(inputbox2b);
inputbox2b.add(new Box.Filler(minSize, prefSize, maxSize));
// set up mass
massLabel = new JLabel( "mass (slugs)" );
massField = new JTextField(5);
inputbox2b.add( massLabel );
inputbox2b.add( massField );
inputbox2b.add(new Box.Filler(minSize, prefSize, maxSize));
// set up altitude
altitudeLabel = new JLabel( "altitude (feet)");
altitudeField = new JTextField(5 );
inputbox2b.add( altitudeLabel );
inputbox2b.add( altitudeField );
inputbox2b.add(new Box.Filler(minSize, prefSize, maxSize));
// set up velocity
velocityLabel = new JLabel( "velocity (Mach Number)");
velocityField = new JTextField(5);
inputbox2b.add( velocityLabel );
inputbox2b.add( velocityField );
inputbox2b.add(new Box.Filler(minSize, prefSize, maxSize));
box.add( Box.createVerticalStrut (10) );
Dimension minSize2c = new Dimension(160, 15);
Dimension prefSize2c = new Dimension(160, 15);
Dimension maxSize2c = new Dimension(Short.MAX_VALUE, 15);
box.add(inputbox2c);
inputbox2c.add(new Box.Filler(minSize2c, prefSize2c, maxSize2c));
// set up trajectory_angle
trajectory_angleLabel = new JLabel( "trajectory angle (degrees)");
trajectory_angleField = new JTextField(5);
inputbox2c.add( trajectory_angleLabel );
inputbox2c.add( trajectory_angleField );
inputbox2c.add(new Box.Filler(minSize2c, prefSize2c, maxSize2c));
box.add( Box.createVerticalStrut (10) );
Dimension minSize2d = new Dimension(50, 15);
Dimension prefSize2d = new Dimension(50, 15);
Dimension maxSize2d = new Dimension(Short.MAX_VALUE, 15);
box.add(inputbox2d);
inputbox2d.add(new Box.Filler(minSize2d, prefSize2d, maxSize2d));
// set up time_increment
time_incrementLabel = new JLabel( "time increment (seconds)" );
time_incrementField = new JTextField(5);
inputbox2d.add( time_incrementLabel );
inputbox2d.add( time_incrementField );
inputbox2d.add(new Box.Filler(minSize2d, prefSize2d, maxSize2d));
// set up rotation_factor
rotation_factorLabel = new JLabel( "rotation factor (number)" );
rotation_factorField = new JTextField(5);
inputbox2d.add( rotation_factorLabel );
inputbox2d.add( rotation_factorField );
inputbox2d.add(new Box.Filler(minSize2d, prefSize2d, maxSize2d));
box.add( Box.createVerticalStrut (10) );
box.add( buttonbox);
Dimension minSizeB = new Dimension(10, 30);
Dimension prefSizeB = new Dimension(10, 30);
Dimension maxSizeB = new Dimension(Short.MAX_VALUE, 30);
buttonbox.add(new Box.Filler(minSizeB, prefSizeB, maxSizeB));
// set up start
startButton = new JButton( "START" );
buttonbox.add( startButton );
buttonbox.add(new Box.Filler(minSizeB, prefSizeB, maxSizeB));
// set up reset
resetButton = new JButton( "RESET" );
buttonbox.add( resetButton );
buttonbox.add(new Box.Filler(minSizeB, prefSizeB, maxSizeB));
// set up cont
contButton = new JButton( "CONTINUE" );
buttonbox.add( contButton );
buttonbox.add(new Box.Filler(minSizeB, prefSizeB, maxSizeB));
// set up abort
abortButton = new JButton( "ABORT" );
buttonbox.add( abortButton );
buttonbox.add(new Box.Filler(minSizeB, prefSizeB, maxSizeB));
box.add( Box.createVerticalStrut (10) );
// set up results
resultsArea = new JTextArea( results_string, 6, 50 );
resultsArea.setEditable( false );
box.add( new JScrollPane( resultsArea ) );
// add box to panel
panel.add( box );
// register event handlers
spanField.addActionListener( this );
chordField.addActionListener( this );
thicknessField.addActionListener( this );
massField.addActionListener( this );
altitudeField.addActionListener( this );
velocityField.addActionListener( this );
trajectory_angleField.addActionListener( this );
time_incrementField.addActionListener( this );
rotation_factorField.addActionListener( this );
startButton.addActionListener( this );
resetButton.addActionListener( this );
contButton.addActionListener( this );
abortButton.addActionListener( this );
reset();
} // end method init
public void t_r_a_test (double trajectory_angle) throws Tare {
if (trajectory_angle > MAX || trajectory_angle < MIN)
throw new Tare("\ntrajectory_angle "
+ trajectory_angle + " is outside of allowable range\n\n"
+ "Try another value for the trajectory angle\n"
+ "( " + MIN + " <= trajectory angle <= " + MAX + " )" );
} // end method t_r_a_test
public void a_r_e_test (double altitude) throws Are {
if ( altitude > MAX_ALTITUDE )
throw new Are("\naltitude "
+ altitude + " is outside of allowable range\n\n"
+ "Try value for altitude\n"
+ "( " + MIN_ALTITUDE + " <= altitude <= "
+ MAX_ALTITUDE + " )" );
} // end method a_r_e_test
public void n_v_test (boolean value) throws Nve {
if ( value == false ){
if( span < 0 ){
span = 0;
throw new Nve("\nValue for "
+ " span must not be negative\n\n"
+ "Try another value ");
}
if( chord < 0 ){
chord = 0;
throw new Nve("\nValue for "
+ " chord must not be negative\n\n"
+ "Try another value ");
}
if( thickness < 0 ){
thickness = 0;
throw new Nve("\nValue for "
+ " thickness must not be negative\n\n"
+ "Try another value ");
}
if( mass < 0 ){
mass = 0;
throw new Nve("\nValue for "
+ " mass must not be negative\n\n"
+ "Try another value ");
}
if( altitude < 0 ){
altitude = 0;
throw new Nve("\nValue for "
+ " altitude must not be negative\n\n"
+ "Try another value ");
}
if( velocity < 0 ){
velocity = 0;
throw new Nve("\nValue for "
+ " velocity must not be negative\n\n"
+ "Try another value ");
}
if( time_increment < 0 ){
time_increment = 0;
throw new Nve("\nValue for "
+ " time increment must not be negative\n\n"
+ "Try another value ");
}
if( rotation_factor < 0 ){
rotation_factor = 0;
throw new Nve("\nValue for "
+ " rotation factor must not be negative\n\n"
+ "Try another value ");
}
} //end if( value == false )
} // end method n_v_test
// process events
public void actionPerformed( ActionEvent event )
{
// process spanField
if( event.getSource() == spanField ) {
span_string = spanField.getText();
span = Double.parseDouble( span_string);
}
// process chordField
if( event.getSource() == chordField ) {
chord_string = chordField.getText();
chord = Double.parseDouble( chord_string);
}
// process thicknessField
if( event.getSource() == thicknessField ) {
thickness_string = thicknessField.getText();
thickness = Double.parseDouble( thickness_string);
}
// process massField
if( event.getSource() == massField ) {
mass_string = massField.getText();
mass = Double.parseDouble( mass_string);
}
// process altitudeField
if( event.getSource() == altitudeField ){
altitude_string = altitudeField.getText();
altitude = Double.parseDouble( altitude_string);
}
// process velocityField
if( event.getSource() == velocityField ){
velocity_string = velocityField.getText();
velocity = Double.parseDouble( velocity_string);
}
// process trajectory_angleField
if( event.getSource() == trajectory_angleField ){
trajectory_angle_string = trajectory_angleField.getText();
trajectory_angle = Double.parseDouble( trajectory_angle_string);
}
// process time_incrementField
if( event.getSource() == time_incrementField ){
time_increment_string = time_incrementField.getText();
time_increment = Double.parseDouble( time_increment_string);
}
// process rotation_factorField
if( event.getSource() == rotation_factorField ){
rotation_factor_string = rotation_factorField.getText();
rotation_factor = Double.parseDouble( rotation_factor_string);
}
// process startButton event
if ( event.getSource() == startButton )
strtb();
// process resetButton event
if ( event.getSource() == resetButton )
reset();
// process contButton event
if ( event.getSource() == contButton )
cont();
// process abortButton event
if ( event.getSource() == abortButton )
abort();
} // end method actionPerformed
public void strtb()
{
try{
span = Double.parseDouble( spanField.getText() );
chord = Double.parseDouble( chordField.getText() );
thickness = Double.parseDouble( thicknessField.getText() );
mass = Double.parseDouble( massField.getText() );
altitude = Double.parseDouble( altitudeField.getText());
velocity = Double.parseDouble( velocityField.getText());
trajectory_angle = Double.parseDouble( trajectory_angleField.getText());
time_increment = Double.parseDouble( time_incrementField.getText() );
rotation_factor = Double.parseDouble( rotation_factorField.getText() );
if( span < 0 || chord < 0 || thickness < 0 || mass < 0
|| altitude < 0 || velocity < 0
|| time_increment < 0 || rotation_factor < 0 )
value = false;
t_r_a_test( trajectory_angle );
n_v_test( value );
a_r_e_test( altitude );
while(sentinel){
Z.rundata(this);
if( altitude < 10 )
sentinel = false;
}
results();
resultsArea.setText( results() );
}//end try
// process improperly formatted input
catch ( NumberFormatException numberFormatException ) {
JOptionPane.showMessageDialog( this,
"You must enter numbers in decimal format or integers",
"Invalid Number Format" ,
JOptionPane.ERROR_MESSAGE );
} // end catch NumberFormatException
catch ( ArithmeticException arithmeticException ) {
JOptionPane.showMessageDialog( this,
arithmeticException.toString(), "Arithmetic Exception" ,
JOptionPane.ERROR_MESSAGE );
} // end catch ArithmeticException
catch ( Tare tare ) {
JOptionPane.showMessageDialog( this,
tare.toString(), "-90 <= range <= 90 " ,
JOptionPane.ERROR_MESSAGE );
} // end catch Tare
catch ( Nve nve ) {
JOptionPane.showMessageDialog( this,
nve.toString(), " value less than zero" ,
JOptionPane.ERROR_MESSAGE );
} // end catch Nve
catch ( Are are ) {
JOptionPane.showMessageDialog( this,
are.toString(), " value greater than maximum" ,
JOptionPane.ERROR_MESSAGE );
} // end catch Are
} // end method strtb
public void reset()
{
span_string = "";
chord_string = "";
thickness_string = "";
mass_string = "";
altitude_string = "";
velocity_string = "";
trajectory_angle_string = "";
time_increment_string = "";
rotation_factor_string = "";
results_string = "";
spanField.setText( span_string );
chordField.setText( chord_string );
thicknessField.setText( thickness_string );
massField.setText( mass_string );
altitudeField.setText( altitude_string );
velocityField.setText( velocity_string );
trajectory_angleField.setText( trajectory_angle_string );
time_incrementField.setText( time_increment_string );
rotation_factorField.setText( rotation_factor_string );
resultsArea.setEditable( true );
resultsArea.setText( results_string );
resultsArea.setEditable( false );
span = 0;
chord = 0;
thickness = 0;
mass = 0;
altitude = 0;
velocity = 0;
trajectory_angle = 0;
time_increment = 0;
rotation_factor = 0;
distance = 0;
velocity_fps = 0;
elapsed_time = 0;
value = true;
}// end method reset
public void cont()
{
//later
}
public void abort()
{
//later
}
public String results()
{
results_string =
"Distance =\t\t" + distance + " miles\n"
+ "Altitude =\t\t" + altitude + " feet\n"
+ "Trajectory Angle =\t" + trajectory_angle + " degrees\n"
+ "Velocity =\t\t" + velocity_fps + " feet per second\n"
+ "Elapsed Time =\t\t" + elapsed_time + " seconds\n";
return results_string;
}
} //end class Trajectory
Calculate.java >
// Trajectory Analysis Program: Calculate.java
public class Calculate {
// Calculate constructor
public Calculate()
{
rundata( );
}
public void rundata( Trajectory T)
{
T.altitude--;
}
} // end class Calculate
Nve.java ->
// Trajectory Analysis Program: Nve.java
import java.awt.event.*;
public class Nve extends Exception{
public Nve (){ }
public Nve (String msg)
{ super(msg); }
} // end class Nve
Tare.java ->
// Trajectory Analysis Program: Tare.java
import java.awt.event.*;
public class Tare extends Exception{
public Tare (){ }
public Tare (String msg)
{ super(msg); }
} // end class Tare
Are.java ->
// Trajectory Analysis Program: Are.java
import java.awt.event.*;
public class Are extends Exception{
public Are (){ }
public Are (String msg)
{ super(msg); }
} // end class Are
[tangent]
> <applet code = "Trajectory.class" width = "600" height = "480" >
> Your browser is completely ignoring the <APPLET> tag!
> </applet>
If the browser completely ignores the applet tag, won't this display as 'Your browser is completely ignoring the tag!' ?
Pete
[/tangent]
Calculate.java:10: rundata(Trajectory) in Calculate cannot be applied to ()
rundata( );
^
The rundata method takes one argument. You have not supplied any, nor does there seem to be a valid reason for calling it here.
Trajectory.java:539: cannot resolve symbol
symbol : variable Z
location: class Trajectory
Z.rundata(this);
^
The only occurance of the Z variable is in another method. If you wish to make it visible to more than one method, make it a field.
Why is it called 'Z' anyway? How would you know what Nve means without look *** at the source of the method that throws it? The only additional information added to the exception class by the Nve subclass is the type, and the label of the type is almost meaningless, and you have to break encapsulation to get any meaning.
Normally you obsfucate Java after you compile it.
classes.methods.and.variables.should.have.meaningful.names.
Why is the presentation and trajectory state in one class, but the trajectory claculation method in another? Either put everything in one if you don't want to take advantage of OOD, or break up the functionality sensibly, so the dynamics updates a state vector (if you need to use different dynamics models), which is then presented by something else, in the first instance an applet.
Pete
Pete:
"If the browser completely ignores the applet tag, won't this display as 'Your browser is completely ignoring the tag!' ?"
Sure it will display it if my browser isn't compatible with the HTML. I put it there as good programming practice since some browsers may not support the code. It provides a message if that scenario occurs so the problem can be understood. It doesn't harm anything.
"The rundata method takes one argument. You have not supplied any, nor does there seem to be a valid reason for calling it here."
Good assertion. I don't seem to need any argument if the variables subject to change are suppposed to be virtually global in both classes.
Take another look at where my variables are declared and tell me how it affects scope since I prefer the variables to be in scope for both classes. I need to call some method to do the calculation in Calculate class.
"The only occurance of the Z variable is in another method. If you wish to make it visible to more than one method, make it a field."
?
Calculate Z = new Calculate(); exists in method init(). Z should be a new instance of Calculate. So it should identify rundata as belonging to Calculate class. I don't understand what you mean by making it a field. Maybe the instantiatian is in wrong place and therefore out of scope, but I don't know for sure that is the problem.
"Why is it called 'Z' anyway? How would you know what Nve means without look *** at the source of the method that throws it? The only additional information added to the exception class by the Nve subclass is the type, and the label of the type is almost meaningless, and you have to break encapsulation to get any meaning."
It doesn't have to be called Z, It just facilitated the instantiatian above. Z should have nothing to do with Nve, but it should be important to Calculate. As for the exception class coding, it all works just fine and I don't see any error messages to indicate otherwise when I run a different version of the code without the code segments relevant to the Calculate class.
"classes.methods.and.variables.should.have.meaningful.names."
I agree. I can change that when the more important matters are resolved. The current use actually helps me simplify debugging. I don't have too many unmeaningful names.
"Why is the presentation and trajectory state in one class, but the trajectory calculation method in another? Either put everything in one if you don't want to take advantage of OOD, or break up the functionality sensibly, so the dynamics updates a state vector (if you need to use different dynamics models), which is then presented by something else, in the first instance an applet."
I could put it all into the Trajectory class, but I striving for easier code maintenance. What you see now is simple for the rundata method and Calculate class. When I get this problem resolved by having Calculate class I'll modify by adding more code for a much more complex calculation. You have not seen the meat of this code yet since I need to convert several hundred lines of code from a C++ program into java code with the bulk of it in Calculate class. To get a feel for what I'm doing go to my page at:
http://home.comcast.net/~weldonchafinjr/wsb/html/view.cgi-home.html-.html
> "Why is the presentation and trajectory state in one
> class, but the trajectory calculation method in
> another? Either put everything in one if you don't
> want to take advantage of OOD, or break up the
> functionality sensibly, so the dynamics updates a
> state vector (if you need to use different dynamics
> models), which is then presented by something else, in
> the first instance an applet."
>
> I could put it all into the Trajectory class, but I
> striving for easier code maintenance.
You are misunderstanding Pete's recommendation.
His (and my) opinion are that, as structured, your code is less maintainable than if it were in one file.
Therefore:
DO THIS -
A) put all the code in one class
OR THIS -
B) seperate ALL the calculation data from the applet, and combine it with the calculation code. Then have the applet ask the data/calculation code class for the values when it wants to display them
Think of it this way, if all the data and calculation code is in one class; that class can be tested and verified without messing around with the UI.
larsona:
Ok, I think I'll put it all into Trajectory class and eliminate Calculate class. I originally began to make classes imported as packages, but my ISP had a problem with that. The error seems to be originating outside the GUI logic anyway. I think you have answered the feasibility of what I intended.
> Pete:
>
> "If the browser completely ignores the applet tag,
> won't this display as 'Your browser is completely
> ignoring the tag!' ?"
>
>
> Sure it will display it if my browser isn't compatible
> with the HTML. I put it there as good programming
> practice since some browsers may not support the code.
> It provides a message if that scenario occurs so the
> problem can be understood. It doesn't harm anything.
The point was that the message includes the applet tag which the browser ignores. So the important part of the message, what tag is ignored, is not presented to the user. Furthermore, it is not valid HTML to have applet tags within applet tags.
A message saying 'Your browser is completely ignoring the tag' is less meaningful than, for example, 'Your browser is completely ignoring the <i>applet</i> tag' or, assuming the reader would be looking at the page's source code if they cared about tags, 'Your browser doen't not appear to support embedded Java content'.
Pete
Actual html is different since I had to modify for specific use at my website rather than on my home computer which was used to compile code. I don't see any big problem now since I have already added the "meat" and refined the code. This applet is in use at my website now as the Trajectory Program link. Feel free to visit my website and test some inputs since I still need to deal with some other logic problems that could cause improper reaction to some exceptions. My current concern has shifted toward adding progress monitor design.