Swing application with network event handling

Hello, hope this is the right place for this post. I'm the design phase of a client application in java which talks to a remote server written in C via sockets. I have a design problem: I want my Swing app to have a GUI with buttons and all for normal activities, which activities report to the server, and I want the client to react to server calls anytime without interrupting normal GUi activities. Plus, all must work together, so I would prefer having a single thread for the app. (Think of an IRC client: the user uses the GUI for activities and sendim messages, and meanwhile the client listens for messages from the server and display them as they arrive). My question is: is this possible?
I have something like (in pseudo-java):
classMyApp extends JFrame {
  public MyApp() {
    // Manages and create the GUI
    NetHandler h = new NetHandler(this);
    h.connect();
    while(true) {
      h.pollNetEvents();
class NetHandler {
  private BufferedReader iStream;
  private PrintWriter oStream;
  private MyApp app;
  public NetHandler(MyApp a) {
    app = a;
    Socket socket = createSocket(ip, port);
    iStream = new BufferedReader(new InputStreamReader(socket.getInputStream()));
    oStream = new PrintWriter(socket.getOutputStream());
    handshakeWithServer(); // Login & Password
  public pollNetEvents() {
    try {
      String s;
      for (;;) {
        s = iStream.readLine();
        if (s.equals("") == false)
          break;
        else
          app.parseCommand(s);
    catch (IOException e) {
      app.sendMessage("Error in pollNetEvent: " + e);
}Roughly, something like this. With this solution the GUI works, but I cannot get the message the server sends.
I hope my message is clear enough. Can anybody help me with the design of my app? Thanks a lot.
Fabio.

You might consider posting this in the Swing forum. You might get a more complete response there, but here are my first thoughts.
-- I think you will end up wanting to use multiple threads, but only one thread will update the UI. For more about threading in Swing, see this tutorial: http://java.sun.com/docs/books/tutorial/uiswing/misc/threads.html
and maybe also here: http://www.sourcebeat.com/TitleAction.do?id=10 (look at the sample chapter on Threads)
-- For the polling code ...
Of course, if you use the classes provided for client/server communication described below, you don't need to write your own polling code. You may still wish worry about threading so that your UI remains responsive and does not encounter major issues: http://java.sun.com/developer/JDCTechTips/2005/tt0419.html#1
-- Updates to the UI from thread(s) that are not on the Event Dispatch Thread (the one that controls the UI) must be posted using the SwingUtilities methods, such as invokeLater
Message was edited by:
pthorson

Similar Messages

  • Swing locks up during event handling of a simple button... bug or feature?

    I have the following code:
    import java.awt.BorderLayout;
    import java.awt.Dimension;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JPanel;
    import javax.swing.JScrollPane;
    import javax.swing.JToolBar;
    import javax.swing.SwingUtilities;
    public class Test extends JFrame {
         private static final long serialVersionUID = 1L;
         private JButton button;
         public static void main(String[] args)
              SwingUtilities.invokeLater(new Runnable(){public void run(){new Test();}});
         public Test()
              setSize(200,00);
              setLayout(new BorderLayout());
              JToolBar toolbar = new JToolBar();
              button = new JButton("button");
              button.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { button.setEnabled(false);}});
              toolbar.add(button);
              getContentPane().add(toolbar, BorderLayout.SOUTH);
              JPanel panel = new JPanel();
              panel.setPreferredSize(new Dimension(200,10000));
              for(int i=0;i<10000; i++) { panel.add(new JLabel(""+(Math.random()*1000))); }
              JScrollPane scrollpane = new JScrollPane();
              scrollpane.getViewport().add(panel);
              scrollpane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
              scrollpane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
              scrollpane.setPreferredSize(getSize());
              scrollpane.setSize(getSize());
              getContentPane().add(scrollpane, BorderLayout.CENTER);
              setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              setLocationRelativeTo(null);
              setVisible(true);
              pack();
    }This code is lethal to swing: when pressing the button, for no identifiable reason the entire UI will lock up, even though all the event handler is doing is setting the button's "enabled" property to false. The more content is located in the panel, the longer this locking takes (set -Xmx1024M and the label loop to 1000000 items, then enjoy timing how long it takes swing to realise that all it has to do is disable the button...)
    Does anyone here know of how to bypass this behaviour (and if so, how?), or is it something disastrous that cannot be coded around because it's inherent Swing behaviour?
    I tried putting the setEnabled(false) call in a WorkerThread... that does nothing. It feels very much like somehow all components are locked, while the entire UI is revalidated, but timing revalidation shows that the panel revalidates in less than 50ms, after which Swing's stalled for no reason that I can identify.
    Bug? Feature?
    how do I make it stop doing this =(
    - Mike

    However, if you replace "setEnabled(false)" with "setForeground(Color.red)") the change is instant,I added a second button to the toolbar and invoked setEnabled(true) on the first button and the change is instant as well. I was just looking at the Component code to see the difference between the two. There are a couple of differences:
        public void setEnabled(boolean b) {
            enable(b);
         * @deprecated As of JDK version 1.1,
         * replaced by <code>setEnabled(boolean)</code>.
        @Deprecated
        public void enable() {
            if (!enabled) {
                synchronized (getTreeLock()) {
                    enabled = true;
                    ComponentPeer peer = this.peer;
                    if (peer != null) {
                        peer.enable();
                        if (visible) {
                            updateCursorImmediately();
                if (accessibleContext != null) {
                    accessibleContext.firePropertyChange(
                        AccessibleContext.ACCESSIBLE_STATE_PROPERTY,
                        null, AccessibleState.ENABLED);
         * @deprecated As of JDK version 1.1,
         * replaced by <code>setEnabled(boolean)</code>.
        @Deprecated
        public void enable(boolean b) {
            if (b) {
                enable();
            } else {
                disable();
         * @deprecated As of JDK version 1.1,
         * replaced by <code>setEnabled(boolean)</code>.
        @Deprecated
        public void disable() {
            if (enabled) {
                KeyboardFocusManager.clearMostRecentFocusOwner(this);
                synchronized (getTreeLock()) {
                    enabled = false;
                    if (isFocusOwner()) {
                        // Don't clear the global focus owner. If transferFocus
                        // fails, we want the focus to stay on the disabled
                        // Component so that keyboard traversal, et. al. still
                        // makes sense to the user.
                        autoTransferFocus(false);
                    ComponentPeer peer = this.peer;
                    if (peer != null) {
                        peer.disable();
                        if (visible) {
                            updateCursorImmediately();
                if (accessibleContext != null) {
                    accessibleContext.firePropertyChange(
                        AccessibleContext.ACCESSIBLE_STATE_PROPERTY,
                        null, AccessibleState.ENABLED);
        }The main difference appears to be with the KeyboardFocusManager. So instead of using a toolbar, I changed it to a JPanel (so the buttons are focusable). I then notice the same lag when I try to tab between the two buttons. So the problem is with the focus manager, not the setEnabled() method.

  • Help with combobox event handling

    hey techies
    does knw any1 tutorial or where any URL which helps me adding event handling to combobox
    iam new at event handling
    i tried
    jc1.addItemListener(this);
    public void itemStateChanged(ItemEvent event)
              if(event.getSource()==jc1)
              System.out.println("hello");
         }is this way correct to specify event handling in combobox
    i tired this iam getting NPE like this
    Exception in thread "main" java.lang.NullPointerException
    at FinalMobile.<init>(FinalMobile.java:213)
    at FinalMobile.main(FinalMobile.java:740)
    plz jst let me knw and dnt tell me to refer swing tutorial i have been reffering it
    any help is appreciated

    does knw any1 tutorial or where any URL which helps me adding event handling to comboboxExcuse me, I've told you at least 4 times now to download and read the Swing tutorial which has all this information with working examples. I even provided you with the download link.
    How do you have the nerve to say you can't find any tutorial?

  • Swing application with JavaHelp crashes outside Netbeans IDE.

    Hi guys I have developed a small swing application in Netbeans IDE. I used the following code inside the IDE for JH.
    public void createHelp()
           try {
                   URL hsURL = new URL("jar:file:eDictionaryHelp.jar!/eDictionaryHelp/eDictionary.hs");
                   hs = new HelpSet(null, hsURL);
           catch (Exception ee)
            // Say what the exception really is
            System.out.println( "HelpSet " + ee.getMessage());
            System.out.println("HelpSet "+ helpHS +" not found");
            JOptionPane.showMessageDialog(new JFrame(), ee.getMessage(), "Error", ERROR_MESSAGE);
            hb = hs.createHelpBroker();
       }When I run the program inside the IDE and and click on the corresponding MenuItem.. JavaHelp comes up as it should! No problems with that.
    But when I build the project and tried to run it from the .jar file in the PROJECT_HOME/dist/ the swing got displayed till this function was called. and then it simply crashed.
    Investigating further and commenting out one line at a time and compiling I found out that whenever the hs = new HelpSet(null, hsURL); is encountered, the app crashes (it doesnt throw any error).
    But as I said this is not the case when i run and compile inside the IDE. I only get this problem when running the app from outside the IDE.
    I have tried all kinds of combinations of the URL .. for eg ( I am aware of Bug 4149782)
    ClassLoader cl = this.getClass().getClassLoader();
    try {
                   URL hsURL = HelpSet.findHelpSet(cl, helpHS);
    .What can be the problem guys? Any suggestions?
    Thanks!

    Anyone has an answer on this?
    I am facing the same problem.. I am using NetBeans 5.5
    arijit_datta, do u have a solution for this problem already?
    Thanks,
    SK

  • Coding Swing Applications with Large JDBC ResultSets

    Hi,
    Does anyone know where I can find information regarding efficient ways to code Swing UI's with large JDBC result sets. I have been using JTextArea but my application seems to constantly run out of memory when I encounter a large result set. Also, any information regarding threading and if running database queries should be done entirely off the event thread vs SwingUtilities.invokeLater() would be of tremendous help.
    Thanks,
    John Meah

    If doing operations in the awt thread starts to impair the performance of your app, then create a new class that implements Runnable, and do this:
    Thread t = new Thread (new yourRunnable());
    t.start();
    t should have lower priority than the AWT thread.
    As far as large result sets, it is a fairly universal problem. My recommendation is that you arbitrarily impose a limit on how many of the records returned are displayed, like maybe 25 records. This should fix your problem

  • Unable to launch Java Swing application with JSE 5.0

    Hi,
    we have a swing appln that gets downloaded via java webstart - which was working fine with 1.4.x until 5.0 came. I know that JSE 5.0 includes java webstart too - but when I start my application, I get Marshal error & filenotfound Exception. What we are doing in the application is to download some XML files that are to be used by the program. But the program is unable to find the files.
    If I manually install 1.4.x & Web Start separately, everything works fine.....
    Is there any change needed in the JNLP file?
    TIA

    Hi there,
    Here's the issue:
    I have modified our web page that helps the user download the swing appln - as per the guidelines given in the web site:
    http://java.sun.com/j2se/1.5.0/docs/guide/javaws/developersguide/launch.html
    Let's say that I already have JRE 1.4x & JWS installed on my m/c. When I visit our web page that downloads / starts the client application, I get an error:
    Java Web Start : Invalid Argument Error.
    General
    An error occurred while launching/running the application.
    Category: Invalid Argument error
    Could not load file/URL specified: http://myserver:8080/testdev/app/testb.jnlp
    Exception
    CouldNotLoadArgumentException[ Could not load file/URL specified: http://myserver:8080/testdev/app/testb.jnlp]
         at com.sun.javaws.Main.main(Unknown Source)
    Wrapped Exception
    java.io.IOException: Service Unavailable : http://myserver:8080/testdev/app/testb.jnlp
    at com.sun.javaws.jnl.LaunchDescFactory.buildDescriptor(Unknown Source)
    at com.sun.javaws.Main.main(Unknown Source)
    If I uninstall JRE 1.4+ & etal - JRE 5.0 gets downloaded and everything works smooth. But I need to take care of backward compatibility... Hence this post....
    BTW, the JNLP file looks like:
    <?xml version="1.0" encoding="utf-8"?>
    <jnlp spec="1.0+"
         codebase="$$codebase"
         href="testb.jnlp">
    <information>
    <title>Test Application</title>
    <vendor>TP</vendor>
    <homepage href="help.htm"/>
    <description>TEST Application using Java Web Start </description>
    <description kind="short">TEST Application.</description>
    <icon href="logocropped.jpg"/>
    <icon kind="splash" href="logocropped.jpg"/>
    <offline-allowed/>
    </information>
    <resources>
    <j2se version="1.4+"/>
    <jar href="bars.jar" part="lpc" />
    <jar href="castor-0.9.4.3.jar" part="lpc" download="eager" />
    <jar href="xercesImpl.jar" download="eager"/>
    <jar href="xmlParserAPIs.jar" download="eager"/>
    <jar href="bsh-1.2b6.jar" download="eager"/>
    <jar href="gnujaxp.jar" download="eager"/>
    <jar href="itext-0.99.jar" download="eager"/>
    <jar href="jcommon-0.8.2.jar" download="eager"/>
    <jar href="junit.jar" download="eager"/>
    <jar href="pixie-0.8.0.jar" download="eager"/>
    <jar href="BarsUtil.jar" download="eager"/>
    </resources>
    <application-desc main-class="bars.Bars"/>
    <security>
    <all-permissions/>
    </security>
    </jnlp>
    Is there a version incompatibility issue that I need to take care of ?
    TIA for any help/direction......

  • Create a swing application with reflection

    Hi folks, I'm seeing the possibility to create a application like eclipse wich loads the classes in a folder and builds the application , but I have a doubt, how organize the components in application , how I will add a component in a menu, how I will build the hierarchy , separating menus,panel and buttons , anyone have idea ?
    Thanks .

    1) Use JEditorPane
    2) Need to Highlight syntax
    3) Need to show lines
    check out these links
    coweb.cc.gatech.edu/mediaComp-plan/uploads/95/JESGutter.1.java
    http://javaalmanac.com/egs/javax.swing.text/style_HiliteWords2.html
    Now to popup
    setLayout for the JEditorPane to null
    You will have one JComboBox /or popup with all the properties and methods
    of the class.
    now add that JComboBox to JEditorPane
    You can get the position of the dot by using
    Point point = editorPane.getCaret().getMagicCaretPosition();
    popupMenu.show( jEditorPane,
    (int)point.getX(),
    (int)point.getY());
    Here you can show JComboBox too. (Absolute positioning).
    Now as you need to use JEditorPane implement DocumentListener on it.
    Using caret listener you can get the current word.
    You can use getClass() for that. Add all the methods and properties in JComboBox or Popup.
    As for other properties such as saving keywords, search, 'files opened' etc.
    you can use xml.

  • SystemManagerHandler bug with otherSystemManager event handling?

    I've run across an issue with PopUpManager & Alerts generating stack overflow errors.
    When I have multiple windows in AIR open with Alerts active, and I click on any window with out an alert, I get the stack overflow error.
    (Note: You have to open the multiple windows first .. then trigger the alerts. If you open a window 1 at a time, and trigger the alerts .. you get no stack overflow)
    Anyways .. I traced this down inside of systemManagerHandler to the function windowedManagerHandler
    In that function is a piece of code for handling events triggered from other system managers:
    private function systemManagerHandler(event:Event):void
            if (event["name"] == "sameSandbox")
                event["value"] = currentSandboxEvent == event["value"];
               return;
    Notice in this code the last == ... that seems to be a coding error. If i change the line to  event["value"] = currentSandboxEvent = event["value"]; my stack overflow errors go away.
    Can anyone else confirm that this is indeed a coding error in systemManagerHandler ?

    Hi Luk,
    You don't mention which version or patch level of SBO your client is using. Does this happen for you on different patches?
    I did a quick test on one of my test systems (SBO 2007A SP1 Patch 9 HF1) and I only get one resize event firing. It's the same whether I run with no addons or with an addon that I wrote that adds controls to the sales order form and which moves those items when the form is resized.
    Kind Regards,
    Owen

  • How can I create JScrollPane in my swing application with scroll bars movin

    Hi,
    How can we create scrollpanes moving with scrollbars.I tried many times with custom layout.but it does not work if i set custom layout.I hope that I will get my problem solved.
    Thanks and Regards,
    Rameh RK

    This means it is not possible to create a pure unicode file without the byte order mark?
    You wouldn't happen to know how a file with byte order mark should read on a Linux system?
    Or if this possible or not?
    Regards
    Christian

  • What is the problem with this event handler in LabView 8.0?

    Please find attached a copy of a simple Event Structure VI. Can anyone please tell me why the Pos 0, Pos 1, Pos 2 work fine, but Pos 3 does Not????? It works in Version 7.1 of Labview, but Not in version 8.0. Any help here would be appreciate
    Everything is Free! Until you have to pay for it.
    Attachments:
    ValChgEventBug.vi ‏29 KB

    Hi,
    It doesn't work because the logic is flawed.  If you run the VI in Execution-Highlight mode you will see that for a value-change of, say, 7.0, all the cases (except the first one) are True!  And since there is no data dependency, whatever case executes last will set the final position. 
    You will want to change the logic to check if the value falls in a range, rather than just being greater than something.  For isntance, the psuedo-code would be: 
    "go to position 2 IF value >= 4  AND < 6" 
    You are missing the "AND" part.  Hope this helps.
    -Khalid

  • Event handling in Network UI element in Webdynpro

    Hi ,
       I am developing a hierarchial graph using Network UI element.I want to incorporate event handling so that the graph will respond to user actions like on double clicking a node an URL will be opened.I can notproceed with the event handling.
                         Can anyone tell me the procedure to do this from webdynpro java.
    Regards
    Nayeem

    Hi Nayeem,
    The Network UI element has lots of events defined for it which can be handled to get the desired functionality.
    Go to the View in which you have added the Network Element, select the Element and go to the
    properties tab.
    Under events , you can see a list of events defined for this UI element.
    Select the event you wish to handle and press the Create button which gets visible once
    an event say onNodeSelected is selected
    You can then give a name to the action say UserClicked and save it .
    In the properties tab of the UI element , the action will be registed against the event .
    Now select the event again and press the go button.
    It will redirect you to the java editor of the view where in you can place your event handling logic.
    Alternatively, if you have created the UI element dynamically then you can add the event to the UI element by using the following code
    IWDNetwork network = (IWDNetwork)view.createElement(IWDNetwork.class);
    network.setOnNodeSelected(/*Your Action handler already defined in the View*/);
    Regards,
    Ashish

  • Drop Down List in ALV with Event handler

    Hi All ,
    I have created an ALV grid with a dropdown as one of the columns. This all works fine, except that I want to be able to react to a change in the value of each line's dropdown the next column values should change according to the user selection in the 1st column .
    Is this possible?
    As an example, I have a table of records with one column as a dropdown called " Replace Function Module "   and in 2nd column i have call function of that Replace Function Module , If a  change in " Replace Function Module " should change the call function of in the 2nd column .
    I am using these objects lvc_t_drop , lvc_s_drop and  the method  " set_drop_down_table ",
    Please Can any 1 tel me how to do this with any event handler ar any other way !

    Hi,
    You need to use event handler for this. Check if the below link gives some direction.
    [http://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/cda3992d-0e01-0010-90b2-c4e1f899ac01|http://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/cda3992d-0e01-0010-90b2-c4e1f899ac01]
    I guess you should create a method inside which you call the FM using the FM name from the selected cell in ALV.
    I have not tried it out, but its worth a try.
    Hope this helps!
    Regards,
    Saumya

  • Event Handling with Java API.: Adding to a hierarchy table throws 2events

    I´m having some problems with the event handling. I´ve registered a Class with extends AbstractDataListener as EventListener. When there are changes in the product hierarchy table, some extra work should be done. However if i add a new record into the hierarchy, two events are fired.
    DEBUG DataEventListener.java:123 - Added:Development;PRODUCT_HIERARCHY;R17;Getra?nke, SEW
    DEBUG DataEventListener.java:123 - Added:Development;PRODUCT_HIERARCHY;R17;32 Zoll, B&R
    DEBUG DataEventListener.java:123 - Added:Development;PRODUCT_HIERARCHY;R18;56 Zoll, Lenze
    DEBUG DataEventListener.java:123 - Added:Development;PRODUCT_HIERARCHY;R18;20 Zoll, allgemein
    In this case, i added the records "32 Zoll, B&R" and then "20 Zoll, allgemein". As you can see in both cases two events are fired and the first event seems to come with wrong data. The reported id for the newly created record is R17. For the logging, i did lookup the entry in the hierarchy table by id and use the displayvalue of the record. But the first event always shows the displayvalue from some already existing entry.
    How can i avoid duplicate events or if this is not possible, how i can recognize that the display value of the first event is not valid.

    I have not tetsted it yet, because I'm waiting for my server to be updated, but SAP told me that the API version 5.5.42.67 should fix the problem.
    Thanks for your post.

  • ?? Several applications with one JVM ??

    Hi,
    I need to run several swing application with a single JVM. (for performance reasons, especially with memory). This is ok.
    But swing applications uses only one AWT-Event-Thread that is shared by all applications (Frames).
    The consequence is, per example, that a modal dialog in one of the applications will block all other running applications.
    Actually, this problem is bug-id = 4080029.
    But there's no workaround.
    Is there anyone who knows how to deal with this ??
    I read an article about AppContext where I understand that it should be possible to assign a different context to each application, and also a different EventQueue to each application.
    But I cannot find any documentation about AppContext, and can't understand how to use it.
    Is there someone who can help with AppContext ??
    -Herbien (Switzerland)

    I've found the following in the src directory of JDK1.3.1 -- it's supposed to be part of javax.swing but I can't find it documented anywhere, so here goes (don't forget the Dukes if this helps):
    V.V.
    * @(#)AppContext.java     1.7 00/02/02
    * Copyright 1998-2000 Sun Microsystems, Inc. All Rights Reserved.
    * This software is the proprietary information of Sun Microsystems, Inc. 
    * Use is subject to license terms.
    package javax.swing;
    import java.util.Hashtable;
    import java.util.Enumeration;
    * The AppContext is a per-SecurityContext table which stores application
    * service instances.  (If you are not writing an application service, or
    * don't know what one is, please do not use this class.)  The AppContext
    * allows applet access to what would otherwise be potentially dangerous
    * services, such as the ability to peek at EventQueues or change the
    * look-and-feel of a Swing application.<p>
    * Most application services use a singleton object to provide their
    * services, either as a default (such as getSystemEventQueue or
    * getDefaultToolkit) or as static methods with class data (System).
    * The AppContext works with the former method by extending the concept
    * of "default" to be SecurityContext-specific.  Application services
    * lookup their singleton in the AppContext; if it hasn't been created,
    * the service creates the singleton and stores it in the AppContext.<p>
    * For example, here we have a Foo service, with its pre-AppContext
    * code:<p>
    * <code><pre>
    *    public class Foo {
    *        private static Foo defaultFoo = new Foo();
    *        public static Foo getDefaultFoo() {
    *            return defaultFoo;
    *    ... Foo service methods
    *    }</pre></code><p>
    * The problem with the above is that the Foo service is global in scope,
    * so that applets and other untrusted code can execute methods on the
    * single, shared Foo instance.  The Foo service therefore either needs
    * to block its use by untrusted code using a SecurityManager test, or
    * restrict its capabilities so that it doesn't matter if untrusted code
    * executes it.<p>
    * Here's the Foo class written to use the AppContext:<p>
    * <code><pre>
    *    public class Foo {
    *        public static Foo getDefaultFoo() {
    *            Foo foo = (Foo)AppContext.getAppContext().get(Foo.class);
    *            if (foo == null) {
    *                foo = new Foo();
    *                getAppContext().put(Foo.class, foo);
    *            return foo;
    *    ... Foo service methods
    *    }</pre></code><p>
    * Since a separate AppContext exists for each SecurityContext, trusted
    * and untrusted code have access to different Foo instances.  This allows
    * untrusted code access to "system-wide" services -- the service remains
    * within the security "sandbox".  For example, say a malicious applet
    * wants to peek all of the key events on the EventQueue to listen for
    * passwords; if separate EventQueues are used for each SecurityContext
    * using AppContexts, the only key events that applet will be able to
    * listen to are its own.  A more reasonable applet request would be to
    * change the Swing default look-and-feel; with that default stored in
    * an AppContext, the applet's look-and-feel will change without
    * disrupting other applets or potentially the browser itself.<p>
    * Because the AppContext is a facility for safely extending application
    * service support to applets, none of its methods may be blocked by a
    * a SecurityManager check in a valid Java implementation.  Applets may
    * therefore safely invoke any of its methods without worry of being
    * blocked.
    * @author  Thomas Ball
    * @version 1.7 02/02/00
    final class AppContext {
        /* Since the contents of an AppContext are unique to each Java
         * session, this class should never be serialized. */
        /* A map of AppContexts, referenced by SecurityContext.
         * If the map is null then only one context, the systemAppContext,
         * has been referenced so far.
        private static Hashtable security2appContexts = null;
        // A handle to be used when the SecurityContext is null.
        private static Object nullSecurityContext = new Object();
        private static AppContext systemAppContext =
            new AppContext(nullSecurityContext);
         * The hashtable associated with this AppContext.  A private delegate
         * is used instead of subclassing Hashtable so as to avoid all of
         * Hashtable's potentially risky methods, such as clear(), elements(),
         * putAll(), etc.  (It probably doesn't need to be final since the
         * class is, but I don't trust the compiler to be that smart.)
        private final Hashtable table;
        /* The last key-pair cache -- comparing to this before doing a
         * lookup in the table can save some time, at the small cost of
         * one additional pointer comparison.
        private static Object lastKey;
        private static Object lastValue;
        private AppContext(Object securityContext) {
            table = new Hashtable(2);
            if (securityContext != nullSecurityContext) {
                if (security2appContexts == null) {
                    security2appContexts = new Hashtable(2, 0.2f);
                security2appContexts.put(securityContext, this);
         * Returns the appropriate AppContext for the caller,
         * as determined by its SecurityContext. 
         * @returns the AppContext for the caller.
         * @see     java.lang.SecurityManager#getSecurityContext
         * @since   1.2
        public static AppContext getAppContext() {
            // Get security context, if any.
            Object securityContext = nullSecurityContext;
    Commenting out until we can reliably compute AppContexts
            SecurityManager sm = System.getSecurityManager();
            if (sm != null) {
                Object context = sm.getSecurityContext();
                if (context != null) {
                    securityContext = context;
            // Map security context to AppContext.
            if (securityContext == nullSecurityContext) {
                return systemAppContext;
            AppContext appContext =
                (AppContext)security2appContexts.get(securityContext);
            if (appContext == null) {
                appContext = new AppContext(securityContext);
                security2appContexts.put(securityContext, appContext);
            return appContext;
         * Returns the value to which the specified key is mapped in this context.
         * @param   key   a key in the AppContext.
         * @return  the value to which the key is mapped in this AppContext;
         *          <code>null</code> if the key is not mapped to any value.
         * @see     #put(Object, Object)
         * @since   1.2
        public synchronized Object get(Object key) {
            if (key != lastKey || lastValue == null) {
                lastValue = table.get(key);
                lastKey = key;
            return lastValue;
         * Maps the specified <code>key</code> to the specified
         * <code>value</code> in this AppContext.  Neither the key nor the
         * value can be <code>null</code>.
         * <p>
         * The value can be retrieved by calling the <code>get</code> method
         * with a key that is equal to the original key.
         * @param      key     the AppContext key.
         * @param      value   the value.
         * @return     the previous value of the specified key in this
         *             AppContext, or <code>null</code> if it did not have one.
         * @exception  NullPointerException  if the key or value is
         *               <code>null</code>.
         * @see     #get(Object)
         * @since   1.2
        public synchronized Object put(Object key, Object value) {
            return table.put(key, value);
         * Removes the key (and its corresponding value) from this
         * AppContext. This method does nothing if the key is not in the
         * AppContext.
         * @param   key   the key that needs to be removed.
         * @return  the value to which the key had been mapped in this AppContext,
         *          or <code>null</code> if the key did not have a mapping.
         * @since   1.2
        public synchronized Object remove(Object key) {
            return table.remove(key);
         * Returns a string representation of this AppContext.
         * @since   1.2
        public String toString() {
            Object securityContext = nullSecurityContext;
            SecurityManager sm = System.getSecurityManager();
            if (sm != null) {
                Object context =
                    System.getSecurityManager().getSecurityContext();
                if (context != null) {
                    securityContext = context;
            String contextName = (securityContext.equals(nullSecurityContext) ?
                "null" : securityContext.toString());
         return getClass().getName() + "[SecurityContext=" + contextName + "]";
    }

  • Applet Event Handler

    Would someone please help me. I am new to applet development and I get a compile error associated with the event handling in my first ever applet code as follows:
    C:\j2sdk1.4.2_01\bin>javac trajectory_j.java
    trajectory_j.java:248: illegal start of expression
    private class Handler implements ActionListener {
    ^
    trajectory_j.java:248: ';' expected
    private class Handler implements ActionListener {
    ^
    2 errors
    de.
    This is the code:
    // trajectory Analysis Program: trajectory_j.java
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class trajectory_j extends JApplet implements ActionListener {
         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, termButton;
         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;
         double span, chord, thickness, mass, altitude, velocity, trajectory_angle, time_increment,
              rotation_factor, distance, velocity_fps, elapsed_time;
         int status_a;
         int status_b;
         int status_c;
    /* deletion of code segment a
              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;
         // create objects
         public void init()
              status_a = 0;
              status_b = 0;
              status_c = 0;
              // 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 inputbox3 = Box.createHorizontalBox();
              Box buttonbox = Box.createHorizontalBox();
              introduction_string = "This is the introduction";
              // 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);
              // set up span
              spanLabel = new JLabel( "span (feet)" );
              spanField = new JTextField(5 );
              inputbox1.add( spanLabel );
              inputbox1.add( spanField );
              Dimension minSize = new Dimension(5, 15);
              Dimension prefSize = new Dimension(5, 15);
              Dimension maxSize = new Dimension(Short.MAX_VALUE, 15);
              inputbox1.add(new Box.Filler(minSize, prefSize, maxSize));
              // set up chord
              chordLabel = new JLabel( "chord (feet)" );
              chordField = new JTextField(5 );
              inputbox1.add( chordLabel );
              inputbox1.add( chordField );
              inputbox1.add(new Box.Filler(minSize, prefSize, maxSize));
              // set up thickness
              thicknessLabel = new JLabel( "thickness (feet)" );
              thicknessField = new JTextField(5 );
              inputbox1.add( thicknessLabel );
              inputbox1.add( thicknessField );
              inputbox1.add(new Box.Filler(minSize, prefSize, maxSize));
              // set up mass
              massLabel = new JLabel( "mass (slugs)" );
              massField = new JTextField(5);
              inputbox1.add( massLabel );
              inputbox1.add( massField );
              box.add( Box.createVerticalStrut (10) );
              box.add( inputbox2);
              // set up altitude
              altitudeLabel = new JLabel( "altitude (feet)");
              altitudeField = new JTextField(5 );
              inputbox2.add( altitudeLabel );
              inputbox2.add( altitudeField );
              inputbox2.add(new Box.Filler(minSize, prefSize, maxSize));
              // set up velocity
              velocityLabel = new JLabel( "velocity (Mach Number)");
              velocityField = new JTextField(5);
              inputbox2.add( velocityLabel );
              inputbox2.add( velocityField );
              inputbox2.add(new Box.Filler(minSize, prefSize, maxSize));
              // set up trajectory_angle
              trajectory_angleLabel = new JLabel( "trajectory angle ( -90 degrees <= trajectory angle <= 90 degrees )");
              trajectory_angleField = new JTextField(5);
              inputbox2.add( trajectory_angleLabel );
              inputbox2.add( trajectory_angleField );
              box.add( Box.createVerticalStrut (10) );
              box.add( inputbox3);
              Dimension minSizeF = new Dimension(70, 15);
              Dimension prefSizeF = new Dimension(70, 15);
              Dimension maxSizeF = new Dimension(Short.MAX_VALUE, 15);
              inputbox3.add(new Box.Filler(minSizeF, prefSizeF, maxSizeF));
              // set up time_increment
              time_incrementLabel = new JLabel( "time increment (seconds)" );
              time_incrementField = new JTextField(5);
              inputbox3.add( time_incrementLabel );
              inputbox3.add( time_incrementField );
              inputbox3.add(new Box.Filler(minSizeF, prefSizeF, maxSizeF));
              // set up rotation_factor
              rotation_factorLabel = new JLabel( "rotation factor ( non-negative number)" );
              rotation_factorField = new JTextField(5);
              inputbox3.add( rotation_factorLabel );
              inputbox3.add( rotation_factorField );
              inputbox3.add(new Box.Filler(minSizeF, prefSizeF, maxSizeF));
              box.add( Box.createVerticalStrut (10) );
              box.add( buttonbox);
              // set up start
              startButton = new JButton( "START" );
              buttonbox.add( startButton );
              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 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 term
              termButton = new JButton( "END" );
              buttonbox.add( termButton );
              box.add( Box.createVerticalStrut (10) );          
              // set up results
              resultsArea = new JTextArea( results_string, 10, 50 );
              resultsArea.setEditable( false );
              box.add( new JScrollPane( resultsArea ) );
              // add box to panel
              panel.add( box );
              // register event handlers
              Handler handler = new Handler();
              spanField.addActionListener( handler );
              chordField.addActionListener( handler );          
              thicknessField.addActionListener( handler );
              massField.addActionListener( handler );
              altitudeField.addActionListener( handler );
              velocityField.addActionListener( handler );          
              trajectory_angleField.addActionListener( handler );
              time_incrementField.addActionListener( handler );
              rotation_factorField.addActionListener( handler );
              startButton.addActionListener( handler );
              resetButton.addActionListener( handler );
              contButton.addActionListener( handler );
              termButton.addActionListener( handler );
    // private inner class for event handling
    private class Handler implements ActionListener {
         // process handler events
         public void actionPerformed( ActionEvent event )
              // process resetButton event
              if ( event.getSource() == resetButton )
                   reset();
              // process contButton event
              if ( event.getSource() == contButton )
                   cont();
              // process endButton event
              if ( event.getSource() == termButton )
              // process span event
              if( event.getSource() == spanField ) {
                   span = Double.parseDouble( event.getActionCommand() );
                   spanField.setText( span_string );
                   status_b++;
              // process chord event
              if( event.getSource() == spanField ) {
                   span = Double.parseDouble( event.getActionCommand() );
                   spanField.setText( chord_string );
                   status_b++;     
              // process thickness event
              if( event.getSource() == thicknessField ) {
                   thickness = Double.parseDouble( event.getActionCommand() );
                   spanField.setText( thickness_string );     
                   status_b++;
              // process mass event
              if( event.getSource() == massField ) {
                   mass = Double.parseDouble( event.getActionCommand() );
                   spanField.setText( mass_string );
                   status_b++;     
              // process altitude event
              if( event.getSource() == altitudeField ) {
                   altitude = Double.parseDouble( event.getActionCommand() );
                   spanField.setText( altitude_string );     
                   status_b++;
              // process velocity event
              if( event.getSource() == velocityField ) {
                   velocity = Double.parseDouble( event.getActionCommand() );
                   spanField.setText( velocity_string );
                   status_b++;
              // process trajectory_angle event
              if( event.getSource() == trajectory_angleField ) {
                   trajectory_angle = Double.parseDouble( event.getActionCommand() );
                   spanField.setText( trajectory_angle_string );
                   status_b++;
              // process time_increment event
              if( event.getSource() == time_incrementField ) {
                   time_increment = Double.parseDouble( event.getActionCommand() );
                   spanField.setText( time_increment_string );
                   status_b++;
              // process rotation_factor event
              if( event.getSource() == rotation_factorField ) {
                   rotation_factor = Double.parseDouble( event.getActionCommand() );
                   spanField.setText( rotation_factor_string );
                   status_b++;
              // process startButton event
              if ( event.getSource() == startButton && status_b == 9 ) {
                   status_c = 1;
         } // end method event handler
    } // end Handler class
         } // end method init
         public void strtb()
    /* deletion of code segment 1
              startButton.addActionListener(
                   new ActionListener() {  // anonymous inner class
                        // set text in resultsArea
                        public void actionPerformed( ActionEvent event )
                        if( status_c == 1 ){
                        calculate();
                        results();
                        resultsArea.setText( results() );
    /* deletion of code segment 2                    
                        }// end method actionPerformed1
                   } // end anonymous inner class1
              ); // end call to addActionlistener1
         } // end method strtb
         public void reset()
    /* deletion of code segment 3
              resetButton.addActionListener(
                   new ActionListener() {  // anonymous inner class
                        // set text in resultsArea
                        public void actionPerformed( ActionEvent event )
                        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;
    /* deletion of code segment 4               
                        } // end method actionPerformed2
                   } // end anonymous inner class2
              ); // end call to addActionlistener2
         } // end method reset
         public void cont()
         //later
         public void calculate()
         distance = 1;
         altitude = 2;
         trajectory_angle = 3;
         velocity_fps = 4;
         elapsed_time = 5;
         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"
         + "\nstatus_a = " + status_a + "\nstatus_b = "
         + status_b + "\nstatus_c = " + status_c;
         return results_string;
    public void start()
    if(status_a == 0 )
    strtb();
    if (status_b == 0)
    reset();
    }// end method start
    } //end class trajectory_a

    The following are copies of html and java source code files for a prior runnable version ( trajectory_b ) of this program which can enlighten some functionality intended by the program.
    (trajectory_b.html):
    <html>
    <appletcode = "trajectory_b.class" width = "800" height = "600">
    </applet>
    </html>
    (trajectory_b.java):
    // trajectory Analysis Program: trajectory_b.java
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class trajectory_b extends JApplet implements ActionListener {
         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, termButton;
         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;
         double span, chord, thickness, mass, altitude, velocity, trajectory_angle, time_increment,
              rotation_factor, distance, velocity_fps, elapsed_time;
         int status_a;
         int status_b;
         int status_c;
    /* deletion of code segment a
              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;
         // create objects
         public void init()
              status_a = 0;
              status_b = 0;
              status_c = 0;
              // 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 inputbox3 = Box.createHorizontalBox();
              Box buttonbox = Box.createHorizontalBox();
              introduction_string = "This is the introduction";
              // 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);
              // set up span
              spanLabel = new JLabel( "span (feet)" );
              spanField = new JTextField(5 );
              inputbox1.add( spanLabel );
              inputbox1.add( spanField );
              Dimension minSize = new Dimension(5, 15);
              Dimension prefSize = new Dimension(5, 15);
              Dimension maxSize = new Dimension(Short.MAX_VALUE, 15);
              inputbox1.add(new Box.Filler(minSize, prefSize, maxSize));
              // set up chord
              chordLabel = new JLabel( "chord (feet)" );
              chordField = new JTextField(5 );
              inputbox1.add( chordLabel );
              inputbox1.add( chordField );
              inputbox1.add(new Box.Filler(minSize, prefSize, maxSize));
              // set up thickness
              thicknessLabel = new JLabel( "thickness (feet)" );
              thicknessField = new JTextField(5 );
              inputbox1.add( thicknessLabel );
              inputbox1.add( thicknessField );
              inputbox1.add(new Box.Filler(minSize, prefSize, maxSize));
              // set up mass
              massLabel = new JLabel( "mass (slugs)" );
              massField = new JTextField(5);
              inputbox1.add( massLabel );
              inputbox1.add( massField );
              box.add( Box.createVerticalStrut (10) );
              box.add( inputbox2);
              // set up altitude
              altitudeLabel = new JLabel( "altitude (feet)");
              altitudeField = new JTextField(5 );
              inputbox2.add( altitudeLabel );
              inputbox2.add( altitudeField );
              inputbox2.add(new Box.Filler(minSize, prefSize, maxSize));
              // set up velocity
              velocityLabel = new JLabel( "velocity (Mach Number)");
              velocityField = new JTextField(5);
              inputbox2.add( velocityLabel );
              inputbox2.add( velocityField );
              inputbox2.add(new Box.Filler(minSize, prefSize, maxSize));
              // set up trajectory_angle
              trajectory_angleLabel = new JLabel( "trajectory angle ( -90 degrees <= trajectory angle <= 90 degrees )");
              trajectory_angleField = new JTextField(5);
              inputbox2.add( trajectory_angleLabel );
              inputbox2.add( trajectory_angleField );
              box.add( Box.createVerticalStrut (10) );
              box.add( inputbox3);
              Dimension minSizeF = new Dimension(70, 15);
              Dimension prefSizeF = new Dimension(70, 15);
              Dimension maxSizeF = new Dimension(Short.MAX_VALUE, 15);
              inputbox3.add(new Box.Filler(minSizeF, prefSizeF, maxSizeF));
              // set up time_increment
              time_incrementLabel = new JLabel( "time increment (seconds)" );
              time_incrementField = new JTextField(5);
              inputbox3.add( time_incrementLabel );
              inputbox3.add( time_incrementField );
              inputbox3.add(new Box.Filler(minSizeF, prefSizeF, maxSizeF));
              // set up rotation_factor
              rotation_factorLabel = new JLabel( "rotation factor ( non-negative number)" );
              rotation_factorField = new JTextField(5);
              inputbox3.add( rotation_factorLabel );
              inputbox3.add( rotation_factorField );
              inputbox3.add(new Box.Filler(minSizeF, prefSizeF, maxSizeF));
              box.add( Box.createVerticalStrut (10) );
              box.add( buttonbox);
              // set up start
              startButton = new JButton( "START" );
              buttonbox.add( startButton );
              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 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 term
              termButton = new JButton( "END" );
              buttonbox.add( termButton );
              box.add( Box.createVerticalStrut (10) );          
              // set up results
              resultsArea = new JTextArea( results_string, 10, 50 );
              resultsArea.setEditable( false );
              box.add( new JScrollPane( resultsArea ) );
              // add box to panel
              panel.add( box );
              // register event handlers
              Handler handler = new Handler();
              spanField.addActionListener( handler );
              chordField.addActionListener( handler );          
              thicknessField.addActionListener( handler );
              massField.addActionListener( handler );
              altitudeField.addActionListener( handler );
              velocityField.addActionListener( handler );          
              trajectory_angleField.addActionListener( handler );
              time_incrementField.addActionListener( handler );
              rotation_factorField.addActionListener( handler );
              startButton.addActionListener( handler );
              resetButton.addActionListener( handler );
              contButton.addActionListener( handler );
              termButton.addActionListener( handler );
    } // end method init
         // process handler events
         public void actionPerformed( ActionEvent event )
              // process resetButton event
              if ( event.getSource() == resetButton )
                   reset();
              // process contButton event
              if ( event.getSource() == contButton )
                   cont();
              // process endButton event
              if ( event.getSource() == termButton )
              // process span event
              if( event.getSource() == spanField ) {
                   span = Double.parseDouble( event.getActionCommand() );
                   spanField.setText( span_string );
                   status_b++;
              // process chord event
              if( event.getSource() == spanField ) {
                   span = Double.parseDouble( event.getActionCommand() );
                   spanField.setText( chord_string );
                   status_b++;     
              // process thickness event
              if( event.getSource() == thicknessField ) {
                   thickness = Double.parseDouble( event.getActionCommand() );
                   spanField.setText( thickness_string );     
                   status_b++;
              // process mass event
              if( event.getSource() == massField ) {
                   mass = Double.parseDouble( event.getActionCommand() );
                   spanField.setText( mass_string );
                   status_b++;     
              // process altitude event
              if( event.getSource() == altitudeField ) {
                   altitude = Double.parseDouble( event.getActionCommand() );
                   spanField.setText( altitude_string );     
                   status_b++;
              // process velocity event
              if( event.getSource() == velocityField ) {
                   velocity = Double.parseDouble( event.getActionCommand() );
                   spanField.setText( velocity_string );
                   status_b++;
              // process trajectory_angle event
              if( event.getSource() == trajectory_angleField ) {
                   trajectory_angle = Double.parseDouble( event.getActionCommand() );
                   spanField.setText( trajectory_angle_string );
                   status_b++;
              // process time_increment event
              if( event.getSource() == time_incrementField ) {
                   time_increment = Double.parseDouble( event.getActionCommand() );
                   spanField.setText( time_increment_string );
                   status_b++;
              // process rotation_factor event
              if( event.getSource() == rotation_factorField ) {
                   rotation_factor = Double.parseDouble( event.getActionCommand() );
                   spanField.setText( rotation_factor_string );
                   status_b++;
              // process startButton event
              if ( event.getSource() == startButton && status_b == 9 ) {
                   strtb();
         } // end method event handler
         public void strtb()
              startButton.addActionListener(
                   new ActionListener() {  // anonymous inner class
                        // set text in resultsArea
                        public void actionPerformed( ActionEvent event )
                        calculate();
                        results();
                        resultsArea.setText( results() );
                        }// end method actionPerformed1
                   } // end anonymous inner class1
              ); // end call to addActionlistener1
         } // end method strtb
         public void reset()
              resetButton.addActionListener(
                   new ActionListener() {  // anonymous inner class
                        // set text in resultsArea
                        public void actionPerformed( ActionEvent event )
                        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;
                        } // end method actionPerformed2
                   } // end anonymous inner class2
              ); // end call to addActionlistener2
         } // end method reset
         public void cont()
         //later
         public void calculate()
         distance = 1;
         altitude = 2;
         trajectory_angle = 3;
         velocity_fps = 4;
         elapsed_time = 5;
         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"
         + "\nstatus_a = " + status_a + "\nstatus_b = "
         + status_b + "\nstatus_c = " + status_c;
         return results_string;
    public void start()
    if(status_a == 0 )
    strtb();
    if (status_b == 0)
    reset();
    }// end method start
    } //end class trajectory_b

Maybe you are looking for

  • File Storage with IPhoto 6

    Version 6 has made a real dogs breakfast of my photo filing system. Previously photo files after import were stored in a date hierarchy - Year/Month/Date. All very simple but now it uses Year/Roll Number. Roll numbers mean nothing and make it very di

  • Ctxload error DRG-11530: token exceeds maximum length

    I downloaded the 11g examples (formerly the companion cd) with the supplied knowledge base (thesauri), unzipped it, installed it, and confirmed that the droldUS.dat file is there. Then I tried to use ctxload to create a default thesaurus, using that

  • Payroll Journal Import Error EF04

    Hi, we are working in oracle applications 11i (11.5.0) TEST Instance. As monthly operations the payroll personnel upload the salaries journal to Gl Interface with oracle web adi. We have oracle hrms full install. We are trying to setup and use the di

  • Copy tape from Hi8mm player to the macbook directly

    I have a slew of Hi8mm tapes that I want to convert to digital. How can I get the connection to my macbook correct?

  • I need a phone number to ring for help

    I been a phone number to ring for help to got started with my new iPad thanks