How do I use a Frame to set up an applet animation?

I am working on this program for a physics class. It is supposed to be an applet which animates a spring. I first set the animation with dummy values and it works fine (aside from a little flicker). I set up a frame which pops up and allows a user to input values. The frame looks and collects the information as I wanted; now I am trying to get these values passed to the init() method of my applet to be the basis of the animation. I was thinking something like JOptionPane; but, I wanted it to be more customized.
This is the inner class in Launcher which prepares information and disposes the frame. I would like to pass this array
"out."
     private class Exe implements ActionListener{
          public void actionPerformed(ActionEvent event){
               String execute = event.getActionCommand();
               if (execute == "Ok"){
                    out = new double[5];
                    for(int c = 0; c < 5; c++){
                         out[c] = Double.parseDouble(input[c].getText());}
                    dispose();}}}}This is the init() method which sets up all the information required for the animation. I want to receive the array here:
public class Spring extends Applet implements Runnable{
     double t = 0;
     double x,v,a,k;
     int s;
     int delay;
     Thread animator;
     double mass, omega, phi,gravity,equilibrium,amplitude, positionI, velocityI, phiHat;
     double scaler;
     Panel buttons;
     Button start;
     Button pause;
     Button back;
     Button forward;
     Button stop;
     Button restart;     
     Frame l;
     public void init(){
          //Opens the menu which allows user inputs
          l = new Launcher();
          l.setSize(500,450);
          l.setVisible(true);
          //Sets the ammount of time the system waits to refresh
          //Smaller numbers create a more accurate picture
          //This is in milliseconds
          delay = 100;
          //Calculates info about the system
          mass = 5;
          equilibrium = .5;
          gravity = 9.8;
          k = (mass * gravity)/equilibrium;
          omega = Math.pow(k/mass,.5);
          //Differential Equation
          positionI = .1;
          velocityI = -.1;
          amplitude = Math.pow(Math.pow((positionI/Math.cos(omega*0)),2)+
                    Math.pow((velocityI/(omega*Math.cos(omega*0))),2),.5);
          phiHat = Math.abs(Math.atan((positionI/Math.cos(omega*0))/(velocityI/(omega*Math.cos(omega*0)))));
          if((positionI/Math.cos(omega*0)) > 0 && (velocityI/(omega*Math.cos(omega*0))) > 0){
               phi = phiHat;}
          if((positionI/Math.cos(omega*0)) < 0 && (velocityI/(omega*Math.cos(omega*0))) < 0){
               phi = Math.PI + phiHat;}
          if((positionI/Math.cos(omega*0)) < 0 && (velocityI/(omega*Math.cos(omega*0))) > 0){
               phi = (2*Math.PI) - phiHat;}
          if((positionI/Math.cos(omega*0)) > 0 && (velocityI/(omega*Math.cos(omega*0))) < 0){
               phi = Math.PI - phiHat;}
          //scales the spring to the animation grid
          if (amplitude !=  0)
               scaler = amplitude / 105;
          else
               scaler = 1;
          //Adds buttons to applet          
          buttons = new Panel();
          buttons.setLayout(new FlowLayout(FlowLayout.CENTER));
          start = new Button("Start");
          buttons.add(start);
          pause = new Button("Pause");
          buttons.add(pause);
          back = new Button("Back");
          buttons.add(back);
          forward = new Button("Forward");
          buttons.add(forward);
          stop = new Button("Stop");
          buttons.add(stop);
          restart = new Button("Restart");
          buttons.add(restart);
          this.setLayout(new BorderLayout());
          add(buttons, BorderLayout.SOUTH);}

I was trying to tweak my animation and I have ran into some problems:
To refresh, I have an applet which animates a spring. The equation which drives the animation is taken from user input which is entered in a frame that launches when the applet loads. The user has the option to control the animation with buttons as opposed to the applet running itself. Anyway, everything worked fine until I rewrote the applet with an image buffer. Now, the frame launches and is automatically placed in the background (on the desktop). The start, stop, and pause buttons work; but the step back and forward buttons do not work. If you have time to offer suggestions they would be appreciated.
Set Up Buttons and Frame:
     public void init(){
          l = new Frame("Information About Your Spring");
          l.setLayout(new GridLayout(4,1));
          directions = new TextArea(text);
          directions.setEditable(false);
          l.add(directions);
          GravityHandler a = new GravityHandler();
          gravityButtons = new Container();
          gravityButtons.setLayout(new GridLayout(bodies.length/4,4));
          gravityL = new JRadioButton[bodies.length];
          g = new ButtonGroup();
          for(int x = 0; x < bodies.length; x++){
               if(bodies[x].equals("Earth")){
                    gravityL[x] = new JRadioButton(bodies[x], true);
                    gravityL[x].addActionListener(a);}
               else{
                    gravityL[x] = new JRadioButton(bodies[x], false);
                    gravityL[x].addActionListener(a);}
               g.add(gravityL[x]);
               gravityButtons.add(gravityL[x]);}
          l.add(gravityButtons);
          lables = new TextField[5];
          input = new TextField[5];
          otherInput = new Container();
          otherInput.setLayout(new GridLayout(3,4,5,5));
          lables[0] = new TextField("Mass:");
          lables[0].setEditable(false);
          otherInput.add(lables[0]);
          input[0] = new TextField(20);
          otherInput.add(input[0]);
          lables[1] = new TextField("Gravity:");
          lables[1].setEditable(false);
          otherInput.add(lables[1]);
          input[1] = new TextField("9.81",20);
          input[1].setEditable(false);
          otherInput.add(input[1]);
          lables[2] = new TextField("Equilibrium:");
          lables[2].setEditable(false);
          otherInput.add(lables[2]);
          input[2] = new TextField(20);
          otherInput.add(input[2]);
          lables[3] = new TextField("Displacement:");
          lables[3].setEditable(false);
          otherInput.add(lables[3]);
          input[3] = new TextField(20);
          otherInput.add(input[3]);
          lables[4] = new TextField("Initial Velocity:");
          lables[4].setEditable(false);
          otherInput.add(lables[4]);
          input[4] = new TextField(20);
          otherInput.add(input[4]);
          l.add(otherInput);
          Exe now = new Exe();
          buttonPlace = new Container();
          buttonPlace.setLayout(new FlowLayout(FlowLayout.CENTER));
          Ok = new Button("Ok");
          Ok.addActionListener(now);
          buttonPlace.add(Ok);
          l.add(buttonPlace);
          l.setSize(425,500);
          l.setResizable(false);
          l.toFront();
          l.setVisible(true);
          delay = 100;
          buttons = new Panel();
          buttons.setLayout(new FlowLayout(FlowLayout.CENTER));
          start = new Button("Start");
          buttons.add(start);
          pause = new Button("Pause");
          buttons.add(pause);
          back = new Button("Back");
          buttons.add(back);
          forward = new Button("Forward");
          buttons.add(forward);
          stop = new Button("Stop");
          buttons.add(stop);
          restart = new Button("Restart");
          buttons.add(restart);
          this.setLayout(new BorderLayout());
          add(buttons, BorderLayout.SOUTH);
          display = createImage(size().width, size().height);
          dspl = display.getGraphics();
          l.toFront();}The frame is handled by ActionListener
Action based on the buttons:
     public boolean action(Event e, Object args){
          if (e.target == start){
               animator = new Thread(this);
               animator.start();}
          if (e.target == stop){
               animator.stop();
               animator = null;
               t = 0;
               repaint();}
          if (e.target == pause){
               animator.stop();
               animator = null;}
          if (e.target == restart){
               animator.stop();
               animator = null;
               t = 0;
               repaint();
               animator = new Thread(this);
               animator.start();}
          if (e.target == back){
               animator.stop();
               animator = null;
               t -= .1;
               repaint();}
          if (e.target == forward){
               animator.stop();
               animator = null;
               t += .1;
               repaint();}
          return true;}
draw animation:
     public void run(){
          while(Thread.currentThread() == animator){
               try{
                    Thread.sleep(delay);}
               catch(InterruptedException e){}
               if(animator != null){
                    t+= .1;}
               else{
                    repaint();}     
               dspl.setColor(Color.black);
               dspl.fillRect(0,0,size().width,size().height);
               dspl.setColor(Color.white);
               k = (mass * gravity)/equilibrium;
               omega = Math.pow(k/mass,.5);
               amplitude = Math.pow(Math.pow((positionI/Math.cos(omega*0)),2)+
                         Math.pow((velocityI/(omega*Math.cos(omega*0))),2),.5);
               phiHat = Math.abs(Math.atan((positionI/Math.cos(omega*0))/(velocityI/(omega*Math.cos(omega*0)))));
               if((positionI/Math.cos(omega*0)) > 0 && (velocityI/(omega*Math.cos(omega*0))) > 0){
                    phi = phiHat;}
               if((positionI/Math.cos(omega*0)) < 0 && (velocityI/(omega*Math.cos(omega*0))) < 0){
                    phi = Math.PI + phiHat;}
               if((positionI/Math.cos(omega*0)) < 0 && (velocityI/(omega*Math.cos(omega*0))) > 0){
                    phi = (2*Math.PI) - phiHat;}
               if((positionI/Math.cos(omega*0)) > 0 && (velocityI/(omega*Math.cos(omega*0))) < 0){
                    phi = Math.PI - phiHat;}
               if (amplitude !=  0)
                    scaler = amplitude / 105;
               else
                    scaler = 1;
               dspl.drawRect(5, 5, 442, 240);
               dspl.drawLine(200,5,200,245);
               dspl.drawLine(200,120,447,120);
               dspl.drawLine(20,20, 20, 230);
               dspl.drawLine(20, 20, 24, 20);
               dspl.drawString( String.format("%.2f m", amplitude) , 24,21);
               dspl.drawLine(20, 230, 24, 230);
               dspl.drawString( String.format("%.2f m", amplitude) , 24,231);
               dspl.drawLine(20, 125, 24, 125);
               dspl.drawString( "0 m", 24, 126);
               x = amplitude*Math.sin((omega*t)+phi); //Calculate position
               v = (amplitude*omega)*Math.cos((omega*t)+phi); //Calculate velovity
               a = -(Math.pow(omega,2)*amplitude)*Math.sin((omega*t)+phi); //Calculate acceleration
               dspl.drawString("Kinematics:", 210,20);
               dspl.drawString(String.format("Time: %.1f Seconds",t), 210, 40);
               dspl.drawString(String.format("Position: %.2f m",x), 210,60 );
               dspl.drawString(String.format("Velocity: %.2f m/s",v), 210,80 );
               dspl.drawString(String.format("Acceleration: %.2f m/sec sq",a),210,100 );
               dspl.drawString("Atributes:", 210, 140);
               dspl.drawString(String.format("Equation: x(t) = %.2fsin(%.2ft + %.3f)",amplitude,omega,phi),210,160);
               dspl.drawString(String.format("Spring Constant: %.2f n/m",k),210,180);
               dspl.drawString(String.format("Period: %.2f Seconds", (2*Math.PI)/omega), 210,200);
               dspl.drawString(String.format("Frequency: %.2f Hz",omega/(2*Math.PI)),210,220);
               dspl.drawString(String.format("Amplitude: %.2f",amplitude),210,240);
               s = (int) (x/scaler + 126);
               dspl.drawLine(128,5,128,s-12);
               dspl.drawString(String.format("%.0f kg Mass",mass), 104, s);
               repaint();}}
     public void update(Graphics g){
          paint(g);}
     public void paint(Graphics g){
          g.drawImage(display,0,0,this);}Thanks

Similar Messages

  • How can I use dns-sd to set up a priner to work with AirPrint?

    How can I use dns-sd to set up a priner to work with AirPrint?
    The priner is an HP LaserJet 1200 connected to the network with an HP JetDirect.

    Some of the third-party apps like "handyPrint" are able to configre the HP JetDirect to work with AirPrint.
    I am trying to work up my own solution.
    SyBB

  • How should i use the two results sets in one single report data region?

    Hi frnz,
     I have to create a report using the below condition...
    Here my given data  set query gives you the two result sets ,so how should i use that two result sets information in single report....when i accessing that data set query it will take the values off the first result set not for the second result set.
    without using sub report and look up functionality..... if possible
    is there any way to achieve this.....Please let me know..
    Thanks!

    You cant get both resultsets in SSRS. SSRS dataset will only take the first resultset
    you need to either create them as separate queries or merge them into a single resultset and return with ad additional hardcoded field which indicates resultset (ie resultset1,resultset2 etc)
    Then inside SSRS report you can filter on the field to fetch individual resultsets at required places. While merging you need to make sure metadata of two resultsets are made consistent ie number of columns and correcponding column data types should be same.
    In absence of required number of columns just put some placeholders using NULL
    Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs

  • How do I use a JDBC Resource set-up in Sun Java System Appliation Server?

    How do I use a JDBC Resource set-up in Sun Java System Appliation Server 8.2?
    I created a JDBC Resource labeled "jdbc/__PetroPool" that is backed by a Connection Pool labeled "PetroPool".
    Since this is set-up in Sun Java System Appliation Server 8.2, I am looking for suggestions, examples or guides on how I can use this connection.
    I've been browsing the developer's guide for Sun Java System Appliation Server 8.2 without much luck.
    Googling really doesn't provide a lot of useful information either...
    Any suggestions, examples or guides on how I can use this connection is greatly appreciated.
    Thanks,
    --Todd                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

    How do I use a JDBC Resource set-up in Sun Java System Appliation Server 8.2?
    I created a JDBC Resource labeled "jdbc/__PetroPool" that is backed by a Connection Pool labeled "PetroPool".
    Since this is set-up in Sun Java System Appliation Server 8.2, I am looking for suggestions, examples or guides on how I can use this connection.
    I've been browsing the developer's guide for Sun Java System Appliation Server 8.2 without much luck.
    Googling really doesn't provide a lot of useful information either...
    Any suggestions, examples or guides on how I can use this connection is greatly appreciated.
    Thanks,
    --Todd                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • In an inbuild example of can .. that CAN transmit periodic vi .. i am unable to understand how the extended and standard frame is set?

    In an inbuild example of can .. that CAN transmit  periodic vi .. i am unable to understand how the extended and standard frame is set?
    plz help me .. stuck up very badly
    thanks
    mahadev
    Solved!
    Go to Solution.

    I suggest this KB which explains usage of Ext IDs with NI-CAN
    http://digital.ni.com/public.nsf/allkb/2FA120A37EDBC51D86256854004FB0C7

  • How Can i use Html frames with  simple JSP???

    How Can i use Html frames with simple JSP???
    Actually i am creating an application in which i have used Index.html as frame.
    Noew i am trying that if i click on a link of one frame(say menu frame) the \result shoul come to some other frame(say frame named mainwindow).
    Hoe can i do like this???
    Anand Pritam

    Well i am using..
    < Base target="mainwindow">
    But it is no working is there some other way??

  • How can get & use java true type fonts in my applets

    Hi
    I could get the System fonts in my Applet by making use of Toolkit.getFontList()
    I have used getGraphicsEnvironment to get fonts but my browser doesn't support it.I get ClassNotFoundException.
    How can I get & make use True Type Fonts in my Java Applet.
    any body knows reply immediate pls
    Siva

    similar problem:
    http://forum.java.sun.com/thread.jsp?forum=31&thread=164516
    sorry, thats all i know.
    tobias

  • How can I use a different scroll setting for my mouse and my track pad?

    I'd like to be able to hook a mouse up to Macbook Air and have it scroll properly, without breaking the scroll direction on its trackpad (or my magic pad). In other words, I want to disable "Move content in the direction of finger movement when scrolling" for mice, and enable "Scroll direction: natural" for trackpads. These seem to be the same setting, though, as checking/unchecking one has the same effect on the other.
    How can I do this, as I'd love to be able to easily switch to a mouse, without having to mentally reverse the direction of the scroll wheel.

    Go to System>Preferences>Mouse>Point & Click and System>Preferences>Trackpad>Scroll & Zoom.
    The each have their own scroll directions setting.
    I use both a mouse and a trackpad and have the exact settings you're looking for.
    Matt

  • How can I use Chrome Frame when the downlevel stage always displays?

    I wan't to try Chrome frame but even after the user installs chrome frame the Edge animation will display the downlevel stage content because it detects the browser is older than IE9. Is there some technique to reset play the HTML5 content after installing the plugin?

    Hi DickW
    Thank you for your help!
    I have tried the example.But the example shows how to connect one CAN network with two ports.
    I want each port connect to the net can both read and write;
    I want to apply the function like this:
    1.config the port1 and port2
    2,open port1 and port2
    But after I open port1 or port2 the other port can't be opened;
    After I open the second port it always returns negative.
    In the codes I use CAN0 and CAN1 as the CAN objects.
    Attachments:
    twoport.zip ‏1184 KB

  • How to reset "Use your current location" setting?

    Today, I downloaded an app that when I first ran it it asked me if it "could use my current location". I mistakenly touched the "Don't Allow" selection. I really wanted the app to use my current location.
    Now it is not asking me to use my current location, instead it simply states "Your location could not be determined".
    I went into settings hoping that I would find the app listed there and that I could change a setting to force it to use my current location, but discovered that the app is not listed in the settings apps grouping.
    I deleted the app and then went to the app store and reinstalled it, all to no avail.
    Anyone got an idea about how this "use my current location" can be restored?

    An easier route is to go to Settings -> General -> Location Services
    It will list all the apps that can use location services and you can turn them on or off.

  • How do I use an extension to set a default font size and page zoom on web pages.

    every time I go to a site I have to zoom in 3 times. I saw an answer that said use an extension to fix the zoom so it would stay where I wanted it. It gave two extensions to use, but I don't know where or how to apply them.

    Here are two I've tried in the past:
    * Default FullZoom Level: [https://addons.mozilla.org/firefox/addon/default-fullzoom-level/]
    * NoSquint: [https://addons.mozilla.org/firefox/addon/nosquint/]
    After installing an extension and restarting Firefox, you can use the extension's Options dialog to adjust the starting zoom level. If the extension doesn't have its own menu entry or toolbar button, you can usually find that Options button here:
    orange Firefox button (or Tools menu) > Add-ons > Extensions category
    Any luck?

  • How do I use a variable to set movie clip properties?

    I'm building a simple contact page that allows users to
    select a city from a comboBox. I'd like to pass the selected
    comboBox data through a variable that controls a movie clip with
    the same name. (already on the stage)
    locationListener.change = function (loc_obj:Object) {
    var loc_mc = loc_obj.target.selectedItem.data;
    loc_mc._visible = true;
    So far this hasn't worked. I've tested hardcoding the movie
    clip instance name (Atlanta._visible = true) and it works, but I
    can't figure out why using the variable loc_mc won't trigger
    interaction with the movie clip.
    Something simple, I assume. Thanks in advance for any
    help.

    clbeech:
    I tried using your suggestion, but for some reason it doesn't
    recognize it as naming the movie clip instance. I traced the
    variable and confirmed that the correct value (Atlanta) is being
    passed.
    I assume this is because the variable is not declared as a
    MovieClip, but I can't figure out how to convert it inside the
    function.

  • How can i use toArray to transfer Set to Array ?

    Dear All,
    Currently, I just can do it by the following code, is there any good idea ?
              Object[] object = set.toArray();
              int[] bb = new int[set.size()];
              for(int i=0; i<object.length; i++) {
                   Object object_aa = object;
                   bb[i] = Integer.parseInt(object_aa.toString());
    Thank you very much

    >      Object[] object = set.toArray();
         int[] bb = new int[set.size()];
         for(int i=0; i<object.length; i++) {
              Object object_aa = object;
              bb[i] = Integer.parseInt(object_aa.toString());
    What type of objects are in your set? Are they String or Integer? You will have to do what you showed--converting each object one by one (or just iterate through the Set using an Iterator instead of using toArray, since you won't need the Object [] when you are done).
    If they are String:
    String[] stringArray = (String []) set.toArray(new String[set.size()]);then you won't need to call toString.
    If they are Integer:
    Integer[] integerArray = (Integer[]) set.toArray(new Integer[set.size()]);Then use integerArray.intValue to fill in
    your int array.
    Or:
    int [] bb = new int[set.size()];
    for (Iterator iter = set.iterator(), i=0;
           iter.hasNext(); i++)
       bb[i] = Integer.parseInt(iter.next().toString());
    }where the middle parseInt and toString can be changed, depending on what type of object your set contains.
    Please use code tags, so that your code gets formatted as above (see buttons above posting box).

  • How can I use internal frames with buttons to call others internal frames?

    Hello.
    I'm building a MDI-application using JFrames and several JInternalFrames, but I have problems.
    A JFrame has JMenuBar with JMenu and JMenuItem. One of these, call the first JInternal that has its interface. In this interface has a button that call other type (a class extension of JInternalFrame) JInternalFrame.
    When I clicked button happen a exception (java.lang.NullPointer).
    What happening?
    Help me, please.

    What i usually do is to give my desktop to my internal frames. So within the internalframe, you can use your desktop and add other internal frames to it.
    The code should look something like the following.
    desktop = your JDesktopPane
    MyInternalFrame = an InternalFrame
    AnotherMyInternalFrame = another InternalFrame
    public class MyInternalFrame extends JInternalFrame implements ActionListener
      private JButton jb = new JButton("Launch");
      private JLayeredPane desktop = null;
      public MyInternalFrame(JLayeredPane desktop)
        this.desktop = desktop;
        getContentPane().add(jb);
        jb.addActionListener(this);
      public void actionPerformed(ActionEvent ae)
        if (ae.getSource() == jb)
          desktop.add(new AnotherMyInternalFrame(desktop),JLayeredPane.DEFAULT_LAYER);
    }

  • My iMac is back after hard drive replacement! Now how do I use time machine to set it back up?

    Ok .. Please can someone give me step by step info on how to bring my mac back to life. It has a new hard drive, I have a time machine back up. I have just turned it on and I am at a loss as to what to do.... Do I need discs, do I need to turn time machine on again and just filter back in time?  Confused...  Thanks for any info. 

    Uumm?.... Think I'm there!  I have just booted holding down CMD and R and chose time machine backup... It's now restoring... Fingers crossed.

Maybe you are looking for

  • Options for ABAP report output in Dashboard type presentation

    Background Monash University environment is SAP ERP ECC6 - no BW. The University has undertaken considerable analysis of spend as part of developing a strategic approach to procurement. The data used to undertake this analysis was extracted from SAP

  • Critical issue regarding file to website interface

    hi all,   I am working on one scenario in which sender is an File. and receiver is an HTML page(actually it is a website) which responds according on the input data. when i visited that site I came to know that there are three fields. as follows... u

  • Determining where a test case is being used

    I have a test case in TFS 2013.  I need to know what test plans/suites use this test case.  How can I determine that? I want to know if I can delete that test case but I can't figure out how to tell where it is used. If I add the test case to a test

  • R12.1.3 PSU patching conflict question

    12.1.3 running on RH Linux 5.8 and trying to apply PSU patch 17540582 on my 11.2 OH which is currently at 11.2.0.3.5. 17540582->opatch prereq CheckConflictAgainstOHWithDetail -ph ./ Oracle Interim Patch Installer version 11.2.0.3.6 Copyright (c) 2013

  • Ipod on windows 8

    Why is my iPod not synchronizing on windows 8?