Jump to content

Physics App help

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
3 replies to this topic

#1
ary56

ary56

    Newbie

  • Members
  • Pip
  • 2 posts
I created this:
import java.awt.*;
import java.awt.event.*;


    public class Accelerator extends java.applet.Applet implements ActionListener {
    double v1 = 0;
    double v2 = 0;
    double time = 0;
    double a = 0;
    TextField txt1 = new TextField("Initial Velocity",30);
    TextField txt2 = new TextField("Final Velocity",30);
    TextField txt3 = new TextField("Time",30);
    TextField txt4 = new TextField("Meters/S ",30);
    Button btn1 = new Button(" Compute ");
    Button btn2 = new Button(" Reset ");


        public void init() {
        add(txt1);
        add(txt2); 
        add(txt3);
        add(btn1);
        btn1.addActionListener(this); 
        add(btn2);
        btn2.addActionListener(this); 
        add(txt4);
        txt4.setEditable(false);
        
    }


        public void actionPerformed(ActionEvent e) {
        Object source = e.getSource();


            if (source == btn1) {
            double v1 = (double)((Double.parseDouble(txt1.getText())));
            double v2 = (double)((Double.parseDouble(txt2.getText())));
            double time = (double)((Double.parseDouble(txt3.getText())));
            a = (v2 - v1) / time;
            txt4.setText("Meters/S =" + a);
        }


            if (source == btn2) {
            txt1.setText("Initial Velocity");
            txt2.setText("Final Velocity");
            txt3.setText("Time");
            txt4.setText("Meters/S ");
        }


            else {
        }

    }

    
}


and JCreator says I have one error which is listed as:

" at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:276)
at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
Exception in thread "main"
Process completed."



Can someone please help me get this to run properly?


Thankss

Edited by WingedPanther, 03 March 2009 - 07:01 PM.
add code tags (the # button)


#2
TALucas

TALucas

    Learning Programmer

  • Members
  • PipPipPip
  • 91 posts
This is an applet, and must be run either in a browser or the Java applet viewer. Only programs that have a main function can be executed using Jcreator or the java command.

Do you need to have this program in an applet?
Your thoughts are the architects of your destiny.
[SIGPIC][/SIGPIC]

#3
ary56

ary56

    Newbie

  • Members
  • Pip
  • 2 posts
Yeah I do need it in an applet but I don't exactly know how to, trying to get it on a website.

#4
TALucas

TALucas

    Learning Programmer

  • Members
  • PipPipPip
  • 91 posts
Try this:

1 create a folder to put your files in....I called my acc and put it on my c drive.

2 create an html file, and put it in the folder. I called mine accelerator.htm...you can use this one, but make sure you've compiled the the class object in the same directory as the html file.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>

<head>

<title>Untitled Document</title>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

</head>


<body>

<applet code="Accelerator.class" width="32" height="32">

</applet>


</body>

</html>

3. Execute your code by typing the following at the command prompt, and make sure you are in the directory where the htm file and the java class files are. You may have to resize the window once it starts.
appletviewer accelerator.htm

Your thoughts are the architects of your destiny.
[SIGPIC][/SIGPIC]