Event handling with multiple panels

Hi there,
Like many here, I'm very new to this stuff so please bear with me..
I've been building a gui, using a main "parent" JPanel and several
subpanels. The main reason for creating subpanels was to help me
with the layout (someone might let me know if this was a bad idea!).
Now, all of the subpanels generate events in one form or another. What I'd
like to do is find out the best way to handle ALL of the events that
can be generated from my various subpanels from the "parent" panel. Hopefully
this makes sense :) Could anyone offer any suggestions as to the best way
to achieve this?
For example, panel1 is a JPanel contains a slider and a button.
multipanel is another JPanel that contains 6 panel1's. finally
the main (parent) panel contains the multipanel.
So, a program that creates an instance of the parent panel wants to know
the value that one of the sliders on one of the panels in the multipanel
has (!). How does it get the value?
I hope I explained myself! Many thanks in advance for any advice offered,
dan

class InnerPanel extends JPanel {
Vector listeners;
public void add(SwingEventListener lsnr) {
listeners.add(lsnr);
protected void notifyListeners(AWTEvent ev) {
for (Iterator i = listeners.iterator();i.hasNext();) {
SwingEventListener lsnr = (SwingEventListener) i.next();
lsnr.eventPeformed(ev);
public void actionPerformed(ActionEvent ev) {
notifyListener(ev);
Your SwingEventListener will be
interface SwingEventListener {
public void eventPefromed(AWTEvent event);
public ParentPanel extends JPanel implements SwingEventListener {
public void eventPerformed(AWTEvent event) {
... do what is required.

Similar Messages

  • Event handling with button

    Hi All,
    I am trying to write an event handling on my button, but i seem dont know where to start from. My code are below:
    import java.net.*;
    import java.io.*;
    public class ReadWrite
    public static void main(String[] args) throws Exception {
    URL myLocalhost = new URL("http://localhost/Write.pl");
    URLConnection myURL = myLocalhost.openConnection();
    BufferedReader myBR = new BufferedReader(
    new InputStreamReader(
    myURL.getInputStream()));
    String inputLine;
    while ((inputLine = myBR.readLine()) != null)
    System.out.println(inputLine);
    myBR.close();
    I want to write a code with a button to run the above code.
    Could you please advise?
    Thank for any consideration you may give me.

    here's the code to read a file, modify for your url connection
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import java.io.*;
    class Testing extends JFrame implements ActionListener
      public Testing()
        setLocation(400,300);
        setSize(200,100);
        setDefaultCloseOperation(EXIT_ON_CLOSE);
        JPanel panel = new JPanel();
        JButton btn = new JButton("Read/Write");
        btn.addActionListener(this);
        panel.add(btn);
        getContentPane().add(panel);
      public void actionPerformed(ActionEvent ae)
        BufferedReader myBR = null;
        try
          myBR = new BufferedReader(new FileReader("Test.txt"));
          String inputLine;
          while ((inputLine = myBR.readLine()) != null)
            System.out.println(inputLine);
          myBR.close();
        catch(Exception e){e.printStackTrace();}
      public static void main(String args[]){new Testing().setVisible(true);}
    }

  • C# control event handling with javascript

    How can I get javascript to execute for "onchange" / "OnSelectedIndexChanged" event instead of a CodeBehind method? I think "OnSelectedIndexChanged" event has to be handled by CodeBehind; but how can I replace that (or onchange) with
    a javascript event handler?
    I have the following in my xyz.ascx file:
    <asp:DropDownList ID="ddlTypeCar" CssClass="BatsRefAddressTypes" runat="server"
                      onchange="javascript: testAlert();"
                      OnSelectedIndexChanged="ddlTypeCar_SelectedIndexChanged"
                      AutoPostBack="True" />
    I could not get the javascript to execute, even though I removed OnSelectedIndexChanged="ddlTypeCar_SelectedIndexChanged" and/or set AutoPostBack="false".
    Additionally, I tried added the following in xyz.ascx.cs Page_Load() method.
    ddlTypeOfAddress.Attributes.Add("onchange", "javascript: testAlert();");
    which didn't help.
    Thanks for your help in advance.

    Hi,
    you can control client events instead of server events with javascript
    look this url for more information
    http://www.w3schools.com/js/js_events.asp
    Regards

  • Registering event handler with preloader

    As you can see from the code below, I have an application
    with a custom preloader designated in the Application tag.
    I would like the preloader to be able to receive a message
    from my main application but in order to that I need to register a
    method in the preloader as an event handler for an event fired by
    my application and in order to do that I have to have a reference
    to both the preloader and the application.
    Where can I get a reference to both? this.preloader seems to
    be null when the initialize() event is fired in my application and
    mx.core.Application.application is null in my preloader. Is there
    any way at all to do this?
    I would GREATLY appreciate any help with this! I've been
    struggling with this for hours :(
    Thanks!
    Moshe

    Thank you Nayan..
    BR
    Aliye

  • 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.

  • 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

  • Event Handler with parameters

    I am to create a generic event handler ro process XML
    returned from the server. Its name is this code is "loadFormData".
    Here is my code:
    var params:Object = new Object();
    params.requesttype = 'send';
    params.datarequest = 'xml';
    params.methodexecute = 'mProcessFileRequest';
    params.formname = "FileIdAction";
    params.fileid = parentApplication.cboFileList.id;
    var t:loadFileData = new loadFileData();
    xmlModuleData.addEventListener(ResultEvent.RESULT,
    t.loadFormData(ResultEvent, frmGeneral));
    var r:runXML = new runXML();
    r.getXMLData(xmlModuleData, params);
    It would work if I dont send any parameters to
    t.loadFormData. But then it is not a generic solution. Is it
    possible to send parameters to a callback function?
    Thanks

    Thanks Charlie
    Liao
    and congrats to all :-)
    * Charlie,
    is there a new "Auto Spam Filter"?
    [Personal Site] [Blog] [Facebook]

  • Event Handler with Internal Loops

    Hi...
    I'm trying to update a basic program to handle control events more efficiently.  The program needs to perform the following functions on start button press:
    1)  Import data file and parse instrument settings from multiple (X) rows
    2)  Perform loop with case for each row changing input settings, the read test equipment, and store data in new output data file
    I've looked at producer/consumer example and the continuous measurement and logging example, but not sure if either (or none) of the following two options is the best way to handle the looping from the file...
    A)  Use events to trigger looping for all input cases within a consumer (I've had a problem with this due to not being able to terminate the loop within the consumer with an abort button)
    B)  Make the consumer only a single data acquisition and load loop inputs as queues and generate output queues to be handled by another parallel logging loop
    Any advice?

    Hi bripple,
    Based on what you've described above, a Producer/Consumer Design Pattern (Events) might work. There is a template for this design pattern that ships with LabVIEW which you can access by going to File > New > VI > From Template > Frameworks > Design Patterns. When the user clicks the start button on your front panel, you can queue up a command that will trigger your consumer loop to read the file and loop over each instrument setting. Within that loop, you should be able to queue up additional events corresponding to each instrument setting and reading.
    In terms of error handling, you can conditionally stop a loop if you detect an error. If your user decides to push a button on the front panel to stop the entire process, you can use Enqueue Element at Opposite End to put a stop command at the beginning of the queue. When your consumer loop encounters this event, it can flush the queue and do any cleanup it needs to perform.
    One additional thing to be cautious of is that queues can only handle one data type. Because of that, you may also want to consider a Queued Message Handler design pattern. This design pattern allows you to send both a command and data along with that command. I think that would be ideally situated for you since you could send a "Read Instrument" command along with the data for its settings. You can access this design pattern from within LabVIEW as well. If you have LabVIEW 2012 or LabVIEW 2013, see these instructions. The things I've said above also hold true for the Queued Message Handler as well.
    Let me know if you have any questions or if this is helpful.
    Regards,
    Matthew B.
    Applications Engineer
    National Instruments

  • Message handling with multiple lines to display

    We have a requirement to issue an error message during dialog processing (PAI) and I'd like to use standard message handling if possible.  The syntax
    MESSAGE W008(ZTM) DISPLAY LIKE 'I'.
    gives me a dialog box but handles the message as an error hence processing stops and the user returns to the screen.  I want this functionality but with the ability to display several lines in the message pop up box.  I've looked at the function modules POPUP_DISPLAY_MESSAGE but this displays only 1 line and POPUP_TO_CONFIRM which handles multiple lines but doesn't stop processing (unless further code is added to handle the response).  Can someone suggest a standard of way of achieving this requirement or how to handle a response as an error in the subsequent processing after a call to function module POPUP_TO_CONFIRM.

    hi,
    you can handle like this.
    call function 'POPUP_TO_CONFIRM'
            exporting
              titlebar                    = text-000
      DIAGNOSE_OBJECT             = ' '
              text_question               = v_text
              text_button_1               = 'YES'
      ICON_BUTTON_1               = ' '
              text_button_2               = 'NO'
      ICON_BUTTON_2               = ' '
              default_button              = '1'
              display_cancel_button       = 'X'
      USERDEFINED_F1_HELP         = ' '
             start_column                 = 25
             start_row                    = 6
      POPUP_TYPE                  =
      IV_QUICKINFO_BUTTON_1       = ' '
      IV_QUICKINFO_BUTTON_2       = ' '
           importing
             answer                      = v_ans
    TABLES
      PARAMETER                   =
           exceptions
             text_not_found              = 1
             others                      = 2
          if sy-subrc <> 0.
            message id sy-msgid type sy-msgty number sy-msgno
                    with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
          endif.
          case v_ans.
            when '1'.
              leave program.
            when '2'.
              call screen 100.
            when others.
              call screen 100.
          endcase.
      endcase.
    Here : 1 means yes,
              2 means no.
    Regards
    Sandeep Reddy

  • Event handling with UIScrollView and it's subview

    Hi,
    I have a UIScrollView and inside it a UIImageView. I have a lot of difficulities to handle the events with these two views. Here is what I want to do:
    If it is a multi-touch event (event.allTouches.count > 2), I want the UIScrollView to handle the event, i.e Zoom in/out and pan. If it a single touch event (event.allTouches.count == 1), I want the UIImageView to handle the event.
    Could you please tell me how to do this?
    Thank you very much.
    ff

    Take a look at the JSF Value-Changed Listener sections

  • Event handling with buttons and mouse

    Hi, Im a beginner in Java...!!!
    I have 4 buttons with me- 2 for color(red,blue) and 2 for size(big,small)..
    How do we divide the frame into 2 panels..one for Buttons and Other for Mouse events...
    Now,if I click on RED button and BIG button..and later click in the Mouse Panel area..I shud get a big rectangle filled with red color..and similarly for small / blue..etc...if a new selection is made..the previous rectangles should remain as they are...
    Im unable to get the implementation...any help will be appreciated.
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    class ButtonPanel extends JPanel
    implements ActionListener, MouseMotionListener
    {  public ButtonPanel()
    blueButton = new JButton("Blue");
    redButton = new JButton("Red");
    bigButton = new JButton("Big");
    smallButton = new JButton("small");
    add(blueButton);
    add(redButton);
    add(bigButton);
    add(smallButton);
    blueButton.addActionListener(this);
    redButton.addActionListener(this);
    bigButton.addActionListener(this);
    smallButton.addActionListener(this);
    public void actionPerformed(ActionEvent evt)
    Color color = getBackground();
    repaint();
    // Paint Method
    public void paintComponent(Graphics g)
    {  super.paintComponent(g);
    class ButtonFrame extends JFrame
    {  public ButtonFrame()
    {  setTitle("ButtonTest");
    setSize(300, 200);
    addWindowListener(new WindowAdapter()
    {  public void windowClosing(WindowEvent e)
    {  System.exit(0);
    Container contentPane = getContentPane();
    contentPane.add(new ButtonPanel());
    public class ButtonTest
    {  public static void main(String[] args)
    {  JFrame frame = new ButtonFrame();
    frame.show();
    }

    can U kindly code it for me....!!!you're getting closer,
    http://saloon.javaranch.com/cgi-bin/ubb/ultimatebb.cgi?ubb=get_topic&f=2&t=011033but rent-a-coder is that way ---->

  • Working with multiplie Panels And C Files

    Hi !
    I have a general question...
    I'm workign with CVI 9.1 , and i have serveral C files .
    At the main.c file I'm loading all my panels for ex Panel Name - PREF, Panel Handle - panelPrefHandle
    At the service.c file I'm trying to use GetCtrlVal(panelPrefHandle,....,...);
                                                  OR  GetCtrlVal(PREF,....,...);
    At service.c i'm including #include "main.h"
    Still I'm getting the error :
    NON-FATAL RUN-TIME ERROR:   "Service.c", line 677, col 29, thread id 0x00000D30:   Library function error (return value == -42 [0xffffffd6]). The handle is not a panel handle
    so my question is how can i pass panel handel over serveral c files ?
    Kobi Kalif
    Software Engineer

    Hi,
    you need to include the include file of the panel: if you build and save a panel in the UIR editor, a corresponding *.h file is generated; you need to include this file in the *.c file which will access this panel, because the panel name etc. are defined in the panels' include file.
    Hth, Wolfgang

  • Event handling with TextArea

    hi all,
    i'm really new to java programming !
    so, i will be glad for any help that is given by you.
    this is the problem:
    when we add text in to a TextArea, an event should be
    fired. that means, we should capture the status change of the TextArea.
    i tried with: implementing Actionlistener
    ItemStateChanged
    but didn't work !
    any suggestions ?
    thanx
    neo

    Try adding a TextListener.

  • Putting Rectangle On top of Frame With Multiple Panels

    Ok, I can't Figure out how place a Black Rectangle that Covers The whole Frame, while the frame contains 3 panels (for example).
    Here is what I tried to do.
    import javax.swing.*;
    import java.awt.Color;
    import java.awt.Graphics;
    import java.awt.Graphics2D;
    * @author Sammy
    public class TestEngine {
    private JPanel pnl;
      private Graphics g;
        private JPanel pnl1;
        private JPanel pnl2;
       public static void main(String[] args) {
       TestEngine test =  new TestEngine();
                test.gui();
       public void gui (){
           JFrame frame = new JFrame("Aurora Engine -- 1.0 Test  ");
           frame.setSize(400, 400);
           frame.setVisible(true);
           frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
           frame.setLocationRelativeTo(null);
           pnl = new JPanel();
           pnl1 = new JPanel();
           pnl2 = new JPanel();
        frame.add(pnl);
        frame.add(pnl);
        frame.add(pnl2);
        g = frame.getGraphics();
        Graphics2D g2 = (Graphics2D) g;
                g2.drawRect(0, 0, pnl.getWidth(), pnl.getHeight());
                g2.setColor(Color.BLACK);
                g2.fillRect(1, 1, pnl.getWidth(), pnl.getHeight());
            frame.paint(g2);
    }

    1. Don't do any custom painting in a top level window. Use a JComponent or JPanel.
    2. Never never never use getGraphics in custom painting. Use an override to a painting method.
    how place a Black Rectangle that Covers The whole Frame, while the frame contains 3 panels (for example).Place the 3 panels in a parent panel with a paint() override that invokes the super implementation and then draws the rectangle. For example:import java.awt.*;
    import javax.swing.*;
    public class OvalOverlay {
      public static void main(String[] args) {
        SwingUtilities.invokeLater(new Runnable() {
          @Override
          public void run() {
            new OvalOverlay().makeUI();
      public void makeUI() {
        JPanel outer = new JPanel(new GridLayout(2, 2)) {
          @Override
          public void paint(Graphics g) {
            super.paint(g);
            g.setColor(Color.RED);
            g.fillOval(50, 50, getWidth() - 100, getHeight() - 100);
        Color[] backgrounds = {Color.YELLOW, Color.GREEN, Color.CYAN, Color.ORANGE};
        for (Color background : backgrounds) {
          JPanel inner = new JPanel();
          inner.setBackground(background);
          outer.add(inner);
        JFrame frame = new JFrame();
        frame.add(outer);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setSize(400, 400);
        frame.setLocationRelativeTo(null);
        frame.setVisible(true);
    }db

  • Event configured with multiple receivers

    We have a business object event(say service order technically completed) configured (SWETYPVor SWE2) in our system for two receivers, one a workflow and another is just DUMMY with custom receiver function module. What we are noticing is that the events meant for the DUMMY receiver are going to the workflow receiver.
    How do we route the event to the appropriate receiver? Sometimes, the event raised is relevant for the DUMMY receiver and other times, it is relevant for the workflow receiver.

    Hello,
    You say:
    "What we are noticing is that the events meant for the DUMMY receiver are going to the workflow receiver."
    I'm not sure if that's the right way to look at it. An event just exists, it's other processes and objects that listen out for it.
    What they do with that event is up to them. If you want to differentiate then either create separate events or provide a parameter that the recipient can test for.
    regards
    Rick Bakker
    Hanabi Technology

Maybe you are looking for

  • Photoshop CS5 crashing when opening/creating a new file. (OSX)

    I've seen several threads with this issue but so far none of the solutions have worked. I've tried: -Resetting the preferences -Deleting the mediabrowser.plist and photoshop.plist -Changing the default printer -Updating Photoshop -Updating OSX Crash

  • FILE SYSTEM BACKUP IS HANGING ON OSB

    Hi all i am having a test setup for OSB ( using windows 2003 ent 32 bit , administrative server + mediaserver ) , i am using HP c1537a scsi Tape drive ( driver details Microsoft 10/1/2012 version 5.2.3790.0 ) , and while firing the file system backup

  • Are all the materials and videos going to be removed after July 13th?

    Hello, I would like to know if the whole lessons' material (videos, tutorials, homework, ecc.) will be removed from the course pages after the quiz deadline (July 13th). It would be great to have it accessible in the future for further learning. Than

  • "**Fail to create VM" log files??

    Hi, I am building a dual boot laptop for demonstration and learning purposes. I have successfully installed the virtual server and I'm trying to load the OV Manager template. After the user questionnaire (network, serverpool questions, etc etc) it un

  • ICON_CREATE on button on a screen

    Dear expers, I have a requirement to expand and collaspe a subscreen on click of a button. But i stuck in changing the icon of a button on every click. I have a example to change the icon of a button on selection screen but its not working on a scree