Question on program structure about event handling in nested JPanels in GUI

Hi All,
I'm currently writing a GUI app with a wizard included in the app. I have one class that acts as a template for each of the panels in the wizard. That class contains a JPanel called contentsPanel that I intend to put the specific contents into. I also want the panel contents to be modular so I have a couple of classes for different things, e.g. name and address panel, etc. these panels will contain checkboxes and the like that I want to event listeneres to watch out for. Whats the best way of implementing event handling for panel within panel structure? E.g for the the checkbox example,would it be a good idea to have an accessor method that returns the check book object from the innerclass/panel and use an addListener() method on the returned object in the top level class/panel. Or is it better to have the event listeners for those objects in the same class? I would appreciate some insight into this?
Regards!

MyMainClass.main(new String[] { "the", "arguments" });
// or, if you defined your main to use varags (i.e. as "public static void main(String... args)") then you can just use
MyMainClass.main("the", "arguments");But you should really extract your functionality out of the main method into meaningful classes and methods and just use those from both your console code and your GUI code.

Similar Messages

  • Questions from a rookie about event structures

    Hello,
       I am currently scheduled for Labview classes next month,
    so I want to apologize in advance for "dumb questions". I have created
    a program that is starting
    to be a CPU resource hog. The majority of my program is inside a while
    loop so that the program will "react" to changes in controls, etc. I am
    assuming that
    if I incorporate "event structures" in my program that my program will
    not be a resource hog.  Is the use of event structures the correct
    way to go? If using
    event structures is the correct way to go, what is the best way to
    learn how to incorporate "event structures"?  I am assuming that
    the examples in Labview will show me how. Are there any good reading
    materials about event structures?
    Regards,
    Kaspar

    To fix the CPU resource issue, you need to place a small wait statement in your loop. It will solve two problems:
    Slow down the loop (you don't need to check for UI changes more that 10x/second)
    It will allow other, parallel tasks a chance to run after each iteration. Without a wait, it will hog the CPU for 55ms before releasing control.
    If your loop currently spins one million times a second and you would place a 1ms wait, the CPU would go from 100% to 0.1%!
    The event structure is a fantastic tool to solve most UI issues and it makes the diagram automatically simpler, more self-documenting and easier to read. Have a look at some of the examples that ship with LabVIEW.
    The event structure is easy to learn, so dive right in. Read the online help for some important considerations. As a rule of thumb you should stick to a single event structure per diagram.
    LabVIEW Champion . Do more with less code and in less time .

  • Question about event handling in JComponents

    I have often found it useful to create a component that acts as an event handler for events the component generates itself. For example, a panel that listens for focus events that effect it and handle these events internally. (See below).
    My question is: Can this practice cause synchronization issues or any other type of problem that I need to watch out for? Is it good/bad or neither. Are there any issues I should be aware of?
    Thanks in advance for the help.
    Example:
    public class qPanel extends JPanel implements FocusListener
    public qPanel () {
    super.addFocusListener(this);
    public void focusGained(FocusEvent e) {
    //Do stuff
    public void focusLost(FocusEvent e) {
    //Do stuff
    }

    Hi,
    Handling events this way is completely fine and saves on number of classes. Only thing you may want to watch out for is that the handler methods have to be public. This means that someone could use your component and call one of the methods. For example, I could write:
    panel.focusGained(new FocusEvent(....))
    when it's not really gaining focus. So, if you're writing this component for re-use you might want to be aware of this.
    An alternative:
    Use a single internal class to handle all events. It can then delegate to private methods of your component. Example:
    class MyEventHandler implements FocusListener, MouseListener, etc... {
    public void focusGained(FocusEvent fe) {
    doFocusGained(fe);
    public void mousePressed(MouseEvent me) {
    doMousePressed(me);
    Then your component could have:
    private void doFocusGained(FocusEvent fe) {
    private void doMousePressed(MouseEvent me) {
    etc...
    Just ideas :)
    Thanks!
    Shannon Hickey (Swing Team)
    I have often found it useful to create a component
    that acts as an event handler for events the component
    generates itself. For example, a panel that listens
    for focus events that effect it and handle these
    events internally. (See below).
    My question is: Can this practice cause
    synchronization issues or any other type of problem
    that I need to watch out for? Is it good/bad or
    neither. Are there any issues I should be aware of?
    Thanks in advance for the help.
    Example:
    public class qPanel extends JPanel implements
    FocusListener
    public qPanel () {
    super.addFocusListener(this);
    public void focusGained(FocusEvent e) {
    //Do stuff
    public void focusLost(FocusEvent e) {
    //Do stuff

  • About event handler

    hi
    i am trying to develop a event handler for all the attributes of a resource that when user is modified is attributes. he need get a notification that paritcular attribute or u r data is modified..
    actually i have seen that they have return adapter for each attribute but dont want so many adapters to be writtten so i want to develop a event handler for that scenario... please provide the sample code so that i can modifie or re coding it....
    thanks
    avinash

    Hi,
    I had created one dissconnected resource and one application form for it... the user had filled the form of that resource and submitted and when he want to update the form once again the event handler should be tirrger and paritcular attribute should be update and he had to send email notification that attribute is changed...
    here is once thing that if he had change numberof attributes at a time but we have to send only one email notification for all the attributes...
    regards
    avinash

  • About Event Handling in user Defined Form (In Addon)

    Hi Every One,
    Can Anyone Give Me Notes On EventHandling in forms That are Disgened using Sdk UIAPI .Like Button event ,application event, menuevent... etc with saple code
    Regards
    Srinivas

    Hi Sura,
    Hope this helps. C# sample code.
    //   SAP MANAGE UI API 2005 SDK Sample
    //   File:      CatchingEvents.cs
    //   Copyright (c) SAP MANAGE
    //  THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
    //  ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
    //  THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
    //  PARTICULAR PURPOSE.
    //  BEFORE STARTING:
    //  1. Add reference to the "SAP Business One UI API"
    //  2. Insert the development connection string to the "Command line argument"
    //  1.
    //     a. Project->Add Reference...
    //     b. select the "SAP Business One UI API 2005" From the COM folder
    //  2.
    //      a. Project->Properties...
    //      b. choose Configuration Properties folder (place the arrow on Debugging)
    //      c. place the following connection string in the 'Command line arguments' field
    //  0030002C0030002C00530041005000420044005F00440061007400650076002C0050004C006F006D0056004900490056
    using System;
    using System.Windows.Forms;
    class CatchingEvents  {
        //  This parameter will use us to manipulate the
        //  SAP Business One Application
        private SAPbouiCOM.Application SBO_Application;
        private void SetApplication() {
            //  Use an SboGuiApi object to establish connection
            //  with the SAP Business One application and return an
            //  initialized appliction object
            SAPbouiCOM.SboGuiApi SboGuiApi = null;
            string sConnectionString = null;
            SboGuiApi = new SAPbouiCOM.SboGuiApi();
            //  by following the steps specified above, the following
            //  statment should be suficient for either development or run mode
            sConnectionString = System.Convert.ToString( Environment.GetCommandLineArgs().GetValue( 1 ) );
            //  connect to a running SBO Application
            SboGuiApi.Connect( sConnectionString );
            //  get an initialized application object
            SBO_Application = SboGuiApi.GetApplication( -1 );
        public CatchingEvents() {
            //  set SBO_Application with an initialized application object
            SetApplication();
            // events handled by SBO_Application_AppEvent
            SBO_Application.AppEvent += new SAPbouiCOM._IApplicationEvents_AppEventEventHandler( SBO_Application_AppEvent );
            // events handled by SBO_Application_MenuEvent
            SBO_Application.MenuEvent += new SAPbouiCOM._IApplicationEvents_MenuEventEventHandler( SBO_Application_MenuEvent );
            // events handled by SBO_Application_ItemEvent
            SBO_Application.ItemEvent += new SAPbouiCOM._IApplicationEvents_ItemEventEventHandler( SBO_Application_ItemEvent );
            // events handled by SBO_Application_ProgressBarEvent
            SBO_Application.ProgressBarEvent += new SAPbouiCOM._IApplicationEvents_ProgressBarEventEventHandler( SBO_Application_ProgressBarEvent );
            // events handled by SBO_Application_StatusBarEvent
            SBO_Application.StatusBarEvent += new SAPbouiCOM._IApplicationEvents_StatusBarEventEventHandler( SBO_Application_StatusBarEvent );
        private void SBO_Application_AppEvent( SAPbouiCOM.BoAppEventTypes EventType ) {
            //  the following are the events sent by the application
            //  (Ignore aet_ServerTermination)
            //  in order to implement your own code upon each of the events
            //  place you code instead of the matching message box statement
            switch ( EventType ) {
                case SAPbouiCOM.BoAppEventTypes.aet_ShutDown:
                    SBO_Application.MessageBox( "A Shut Down Event has been caught" + Environment.NewLine + "Terminating Add On...", 1, "Ok", "", "" );
                    //  Take care of terminating your AddOn application
                    System.Windows.Forms.Application.Exit();
                    break;
                case SAPbouiCOM.BoAppEventTypes.aet_CompanyChanged:
                    SBO_Application.MessageBox( "A Company Change Event has been caught", 1, "Ok", "", "" );
                    //  Check the new company name, if your add on was not meant for
                    //  the new company terminate your AddOn
                    //     If SBO_Application.Company.Name Is Not "Company1" then
                    //          Close
                    //     End If
                    break;
                case SAPbouiCOM.BoAppEventTypes.aet_LanguageChanged:
                    SBO_Application.MessageBox( "A Languge Change Event has been caught", 1, "Ok", "", "" );
                    break;
        private void SBO_Application_MenuEvent( ref SAPbouiCOM.MenuEvent pVal, out bool BubbleEvent ) {
            //  in order to activate your own forms instead of SAP Business One system forms
            //  process the menu event by your self
            //  change BubbleEvent to False so that SAP Business One won't process it
            BubbleEvent = true;
            if ( pVal.BeforeAction == true ) {
                SBO_Application.SetStatusBarMessage( "Menu item: " + pVal.MenuUID + " sent an event BEFORE SAP Business One processes it.", SAPbouiCOM.BoMessageTime.bmt_Long, true );
                //  to stop SAP Business One from processing this event
                //  unmark the following statement
                //  BubbleEvent = False
            else {
                SBO_Application.SetStatusBarMessage( "Menu item: " + pVal.MenuUID + " sent an event AFTER SAP Business One processes it.", SAPbouiCOM.BoMessageTime.bmt_Long, true );
        private void SBO_Application_ItemEvent( string FormUID, ref SAPbouiCOM.ItemEvent pVal, out bool BubbleEvent ) {
            //  BubbleEvent sets the behavior of SAP Business One.
            //  False means that the application will not continue processing this event.
            BubbleEvent = true;
            if ( pVal.FormType != 0 ) {
                //  the message box form type is 0
                //  I chose not to deal with events triggered by a message box
                //  every event will open a message box with the event
                //  name and the form UID how sent it
                SAPbouiCOM.BoEventTypes EventEnum = 0;
                EventEnum = pVal.EventType;
                // To prevent an endless loop of MessageBoxes,
                // we'll not notify et_FORM_ACTIVATE and et_FORM_LOAD events
                if ( ( EventEnum != SAPbouiCOM.BoEventTypes.et_FORM_ACTIVATE ) & ( EventEnum != SAPbouiCOM.BoEventTypes.et_FORM_LOAD ) ) {
                    SBO_Application.MessageBox( "An " + EventEnum.ToString() + " has been sent by a form with the unique ID: " + FormUID, 1, "Ok", "", "" );
        private void SBO_Application_ProgressBarEvent( ref SAPbouiCOM.ProgressBarEvent pVal, out bool BubbleEvent) {
            SAPbouiCOM.BoProgressBarEventTypes EventEnum = 0;
            EventEnum = pVal.EventType;
            BubbleEvent = true;
            SBO_Application.MessageBox( "The event " + EventEnum.ToString() + " has been sent", 1, "Ok", "", "" );
        private void SBO_Application_StatusBarEvent( string Text, SAPbouiCOM.BoStatusBarMessageType MessageType ) {
            SBO_Application.MessageBox( @"Status bar event with message: """ + Text + @""" has been sent", 1, "Ok", "", "" );
    Regards,
    Jay.

  • Question about event handling in a button

    I recently coded a console version of my java program (just outputs stuff into the system console and a logger). I am now adding a simple GUI with a set of buttons to start and stop the program. In order to do this, do I just copy paste the main function contents of the console version of my code into the button's event handlers or is there a way I can just run the main class? I was googling for Class loading in java but I'm not sure if this is what I should be looking at... Can someone please help me out?

    MyMainClass.main(new String[] { "the", "arguments" });
    // or, if you defined your main to use varags (i.e. as "public static void main(String... args)") then you can just use
    MyMainClass.main("the", "arguments");But you should really extract your functionality out of the main method into meaningful classes and methods and just use those from both your console code and your GUI code.

  • Problem about event handling or dispatching

    I created a JFrame with a JButton in it. A keyListener is add to the jframe.
    Key events can be catched if JDK1.3.1_08 is employed. However, it doesn't work if JDK1.4.1_02 is empolyed. Can anyone tell me the problem? Thanks a lot!
    The following is the source code:
    public class drawa extends JFrame implements KeyListener
    public static void main(String[] args) {  
         drawa frame = new drawa();
    public drawa() {   
         super("drawa");
         Container c=getContentPane();
         c.setLayout(null);
         JButton jb=new JButton("L");
         jb.setSize(80,40);
         c.add(jb);     
         addKeyListener(this);
         setSize(500,450);          
         setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
         setVisible(true);          
    public void keyPressed(KeyEvent evt){
         System.out.println("a");
    public void keyTyped(KeyEvent evt){}
    public void keyReleased(KeyEvent evt){}

    Your frame must return true for isFocusable ().
    Kind regards,
      Levi

  • About event handling

    Hi
    I am using jdev11.1.1.5.0
    I created a search page in jspx page
    I put there a inputText in which user enter a value and there is a command button named search which perform search operation which is defined in backing.
    Now I want to add a listener that after entering value into input text component user press enter and search should be perform properly
    How can I do the same.?
    Thanks

    Hi Arun
    Thanks for your solution but i need something else
    I already have a separate method for search.
    and i do not want to filter table on input time
    My need is when user have entered the search value in inputtext after that either by pressing enter key by keyboard or by pressing search button on screen ,search should be performed

  • How can I execute an external program from within a button's event handler?

    I am using Tomcat ApacheTomcat 6.0.16 with Netbeans 6.1 (with the latest JDK/J2EE)
    I need to execute external programs from an event handler for a button on a JSF page (the program is compiled, and extremely fast compared both to plain java and especially stored procedures written in SQL).
    I tried what I'd do in a standalone program (as shown in the appended code), but it didn't work. Instead I received text saying the program couldn't be found. This error message comes even if I try the Windows command "dir". I thought with 'dir' I'd at least get the contents of the current working directory. :-(
    I can probably get by with cgi on Apache's httpd server (or, I understand tomcat supports cgi, but I have yet to get that to work either), but whatever I do I need to be able to do it from within the button's event handler. And if I resort to cgi, I must be able to maintain session jumping from one server to the other and back.
    So, then, how can I do this?
    Thanks
    Ted
    NB: The programs that I need to run do NOT take input from the user. Rather, my code in the web application processes user selections from selection controls, and a couple field controls, sanitizes the inoputs and places clean, safe data in a MySQL database, and then the external program I need to run gets safe data from the database, does some heavy duty number crunching, and puts the output data into the database. They are well insulated from mischeif.
    NB: In the following array_function_test.pl was placed in the same folder as the web application's jsp pages, (and I'd tried WEB-INF - with the same result), and I DID see the file in the application's war file.
            try {
                java.lang.ProcessBuilder pn = new java.lang.ProcessBuilder("array_function_test.pl");
                //pn.directory(new java.io.File("K:\\work"));
                java.lang.Process pr = pn.start();
                java.io.BufferedInputStream bis = (java.io.BufferedInputStream)pr.getInputStream();
                String tmp = new String("");
                byte b[] = new byte[1000];
                int i = 0;
                while (i != -1) {
                    bis.read(b);
                    tmp += new String(b);
                getSelectionsDisplayTextArea().setText(getSelectionsDisplayTextArea().getText() + "\n\n" + tmp);
            } catch (java.io.IOException ex) {
                getSelectionsDisplayTextArea().setText(getSelectionsDisplayTextArea().getText() + "\n\n" + ex.getMessage());
            }

    Hi Fonsi!
    One way to execute an external program is to use the System Exec.vi. You find it in the functions pallet under Communication.
    /Thomas

  • Multiple event-handling threads?

    I am writing a Java program that will launch other Java programs within the same JVM. This feature is for an RAD IDE that currently uses Runtime.exec.
    The main problem is that the launcher is an IDE that will try to launch Swing applications within the same JVM. If a badly-written program traps the event-handling thread, it will bring the whole IDE down. The IDE's "Kill" button wont even work.
    Is there any way to tell the JVM to use different event-handling threads for my application? Alternatively, does anybody know of any obscure functions I could use to maybe cause the event-handling thread to delegate processing to another one of my own threads? Ugly hacks are welcome.

    After I first posted this question, I've taken a look at the java.awt.EventQueue class. The API provides an easy way to use your own EventQueue that could possibly dispatch events with multiple threads. If you make sure that you only use one thread at a time for each virtual JVM, I don't think that there will be any thread issues (unless there are any assumptions in AWT/Swing code about there only being one thread).
    About the load time being 0.5 seconds. I'm sure it'll improve, but a failed load only loads and links a minimum number of classes. I wrote a program that runs the java compiler from com.sun.tools.javac.Main and it looks like the load time is about 1.75 seconds. Since the compile time itself is usually under a second for around 2000 lines of code, this kind of makes a difference (500MHz P3, by the way). This load time will probably be even greater for Swing applications.
    When you're lauching a big program it may not matter much but the load time really kills Java's ability to create a quick command-line tool (not that it's best-suited for such a tool anyway, but it would be nice to have that barrier removed).
    The biggest problem with creating a lightweight JVM right now is probably the stupid File class. Even if you change "user.dir" in the system properties, many File methods still resolve relative to the original "user.dir". Though many other problems exist, this is the one that really kills it because of the pervasiveness of the File class.

  • Event handler

    Hi...
       I would like to know about event handler txn code: "crmv_event"
      Can any one educate me about this ? How is this functionality used.?
    Any example ?
    Regards,
    sanjana

    hi sanjana
    CRMV_EVENT t code is used to establish the vents from background
    since you are a functional consultant you must know that for any action to trigger in foreground there must be an event which actually triggers the event
    there are many events to establish that event ,this is just one of the way
    here using the calling options you can sopecify that whatever event you are trying to establish ,you are doing it for what application
    technically whenever event is created or triggered it alwaays do that from the class,that is known as event handler class
    so if we say in the definition of the event handler method, event parameter sender is imported. You can access this parameter at any ABAP Objects event although it is not listed as an event parameter in the Class Builder. This parameter imports a reference to the instance that has triggered the event. This reference can then be used directly to call methods of this instance.
    to say in functional lingo the event which we have just created using the t code can be used to trigger the action in appliocation in which we have tried to call that event
    that mean the event once established will flow throught teh entire structure everytime it is being called,
    this way we decides the timings of the actions in the background of which we have created that event
    hope i clear ur doubt
    best regards
    ashish

  • Migration from Serial polling to Serial queue with event handler

    Hi, I am trying to migrate from classical serial polling communications to serial queue with "event handler" for the buttons pressed by the user. I have placed four while loops, one for the event handler, a second one for serial reading, a third one for serial writing (depending on what button was pressed) and the last one for processing what was read from the serial reading while loop, via a queue.
    My attached device reads the signals from 8 sensor ( 4 temperature and another 4 temperature plus humidity in the same sensor ) and send them via serial to Lavbiew.
    First of all, only once just after running the LV program, I must turn on my attached device with an ON command plus a carriage return after that the device will respond with the number of sensors plugged to it, disabling the corresponding buttons in the front panel. Then labview must wait until I pressed Acquire Button (event handler) and send a CF command plus what sensors to acquire plus a carriage return, then the device will respond continuously to labview with the sensor readings until I press the stop button (event handler), there is also another button to exit the program, also with event handler.
    I am having problems using the event handler and the queues because I am new using these structures, I have looked at  the LV examples but there is nothing concrete on using serial with event handler and queue.
    Take a look at my VI and you will soon notice what kind of problems I am having, any suggestions will welcome.
    Thank's in advance.
    Regards.
    Attachments:
    serial queue.zip ‏76 KB

    Hi Luisete,
    Maybe the problem arise because you are En- and DeQueue in parallel. You do a lot of things in parallel, that is nice if you are sure that one loop doesn't have to wait for another loop. Make sure you don't dequeue before enqueue.
    Hope this helps
    I never knew that the standard error cluster output could be wired directly to the loop control of a while loop.
    First time I see this

  • Event handling using CAN?

    I am aware of how to make LabView respond to user interface events (keyboard presses, button presses, mouse moves, etc) and I'm also aware that the same event handling structure can be used to handle external (non-GUI) events- like those generated by a digital edge on a DAQmx input.  My question is whether the same event handling structure can be used to handle external events coming in on a CAN network- via NI-CAN or otherwise?
    Is there a good reference which summarizes ALL general types of events that can be handled in this way- not just the standard GUI events?  I have a feeling that ActiveX and VISA are other ways to generate events, but can't find a good resource in general - or specifics on the NI-CAN side.
    Thanks!
    Nate 

    Thanks Mike-   still not sure I understand.  What should I wire to the Create User Event block in order for available events to show up in the dialog which allows me to configure events in a given frame?  For example, I have an external micro-controller communicating with LabVIEW using a CAN network.  Usually the communication is started by LabVIEW and sends commands out- but I also want to be able to handle asynchronous messages generated by this micro-controller in an event fashion without having do any polling.   Is there some reference I can wire to the Create User Event block which will make an event like "Incoming CAN Network Traffic" available to be handled in an event structure?
    Thanks again! 

  • Event handling with JSF

    Hi Everybody,
    I have a question about event handling and I am just wondering if I can do the following with JSF.
    I have two HTML dropdown lists A and B. When ever a value changes in list A, based on the selected value, list B has to be populated. Is it possible to do with JSF? Can you guys give me pointers where some code samples may be available?
    Cheers!
    Krish

    Take a look at the JSF Value-Changed Listener sections

  • Use event handler programmatically

    Hello, I use the Labview 8.2.1 and I would like to ask something about event handler.
    I have some buttons and I use an event handler to perform their tasks. The buttons are used only with the mouse and not programmatically.
    Now, I want to use a button programmatically without pressing it. I didn't find how to do this, so I created a boolean variable and I added to the event handler of a button a second "Event Specifier" of that boolean variable with the event "value change".
    I assumed that it would work, but it does not, that is, the event handler is not used when the value of the boolean variable changes.
    How can I solve it?
    Thank you in advance.
    Solved!
    Go to Solution.

    Write to the Value(Sgnl) property node of the variable you want to change.  This will set off an event programatically.
    - tbob
    Inventor of the WORM Global

Maybe you are looking for

  • Should I keep my MacBook Pro or exchange it for more Ram and SSD space?

    Hello, I decided to purchase a MacBook Pro 15 inch with Retina display. I thought I would just bite the bullet and get it with the upgraded 16gb Ram and 512 SSD as I want this computer to last me at least 5 years. I don't know exactly what I will be

  • System.getProperty("user.dir") returns "/home/user" on Linux

    Has anyone else had the error when launching a jar from Linux (just by clicking it), System.getProperty("user.dir") returns the "/home/user" (or "~") value instead of the folder that the jar is in? Essentially, it returns "user.home" instead of "user

  • What app do I need to replace adobe

    When I go to watch a video or tv program it tells me I need adobe, but I know u can't down load it on iPads so what other program/app do I use? I did buy photon app but that doesn't seem to be working!

  • How to create the compensate activity in 11.1.1.5

    Hi Can anyone please let me know how to use the compensate activity in bpel flow. Like i have 4 DB adapters in a flow if any one fails i want do the roll back by using compensate activity. I am femiliar with transactions proparties, I want to do it f

  • [AIR 3.2 BUG] flash.media.scanHardware  stop working.

    From the adobe air Air 3.2 release day, a lot of support calls comeing in. Customer can't see any cameras in the our software! Today, I find the problem. Adobe Air scanHardware() function stop working!!!!! var ar:ArrayCollection = new ArrayCollection