ActionListeners in one panel effecting objects in another

Hi All,
I am setting up a gui which contains a JFrame, within which I am adding classes extended from JPanels. These in turn, have more classes derived from JPanels add to then, in the standard Swing way. I want to know the best way of listening for say a button press in one of the base panels, and it causing an effect in another panel?
I can think of several ways, based around lots of listeners and the messages basically been passed up and across the chain (well tree type structure), but this seems a little cumbersome. If there a way of setting the required available actions without having to do this?
Adam

You can use the Mediator Pattern where a 'mediator class handles events.
The mediator is instantiated in upon the start of the App. then it is passed to all
classes that need it. Then, those classes that the Mediator needs to have a link to should register
themselves with the mediator.
With that said, let's say Class A needs a button actioon to do something to Class B.
Have a process in Mediator called registerClassB(ClassB classB) so the Mediator has a link to it.
Then have mediator passed to Class A and Class B. Class A will set it event listeners to the mediator
(since the mediator will have the proper event listners like mouse and action listners. Class B
will invoke the mediators registerClassB and pass itself.
Whatever event you wan to happen, have it set up in the mediator.

Similar Messages

  • Assigning object of one class to object of another class.

    Hi,
    How will i assign an object of one class to an object of another class?
    Ex:
    ClassX A=some_method();
    Now how will I assign the object A of class ClassX to the object 'B' of another class 'ClassY'.

    In java you can only assign a object reference of one class into object reference of another class if the first class is the Second class (in other words the first class is a subclass of second class).
    for example if this is a inheritance chart
    Car ==========>Mercedes
    "===========>Audi
    then you can use
    Audi a1 = new Audi();
    Car c1 = a1;
    or Mercedes m1 = new Mercedes();
    Car c1 = m1;
    but not
    a1 = m1;
    before assigning a variable into another variable of different class, use:
    if(variable1 instanceOf ToBeAssignedIn Class){
    variable2 = variable1;
    example:
    Audi a1;
    Car c1;
    if(a1 instanceOf Car){
    c1 = a1;
    Edited by: gaurav.suse on Apr 10, 2012 1:14 PM
    Edited by: gaurav.suse on Apr 10, 2012 1:15 PM

  • How to assign one JSP request object to another JSP

    Hi,
    I want to assign one JSP request object (i.e., previous JSP Page request object) to another JSP (i.e., current JSP page request object).
    I don't want to use "<jsp:forward>" tag or "RequestDispatcher" obect here.
    Because i want to display one message in the current JSP page, before sending both JSP pages' request to a servlet. How to do this ?
    please help
    Thanks in advance
    Vishnu

    You cannot assign a request and response object of one jsp/servlet to another, every jsp or a servlet get is own fresh copy of request and response object with the request parameter data from the previous page.
    Unless u use request dispatcher or jsp:forward action, this solution that u r looking for by re-assigning the request and response object doesn't work

  • How can I from one panel access elements on another panel ?

    I have a JFrame with 2 panels and a JMenu
    I am struggling to find a way how I can access JMenu from one of my panels ...
    Also how can I access elements on one panel from other panel ? At the moment I am passing a reference from one panel to other in the constructor but it's only one way communication now ... I can't go from second panel to first ...
    I am sure there must be an elegant way to solve this problem.
    Many thanks.
    Sergei

    OK I'll give you more details...
    I have a JFrame with multiple panels...
    Also I have a JMenu on JFrame...
    Now when user clicks a button on one of the panels I need to disable a menu item ... this is issue#1
    issue#2 is:
    how do I get two panels (they are separate classes) talking to each other ??? At the moment when I initialize a panel#2 from my Frame I pass to it reference to panel#1 and in this way panel#2 can talk to panel#1 but panel#1 can't talk to panel#2 ...
    I know there must be an elegant way to solve this problem... and I don't like having 2 classes tightly coupled like this... Can I use some kind of nice OO trick for this ? I was reading about custom listeners but I don't want to go crazy on this as I don't have time... actualy I've got only 1 day to solve this issue so any help will be greatly appreciated.
    Many thanks
    Sergei

  • How to 'hide' one stroked-only object behind another?

    I'm struggling with something that shouldn't be this difficult!
    I'm laying-out a white-only T-Shirt logo (to go on a dark-green T-shirt)
    For the sake of simplicity, let's say I have two ovals with no fill, just a white stroke.  A small oval overlapping (on-top-of) part of the edge of a larger (underneath) oval.    I
    Any advice on how to 'hide' the line that's 'behind' the top object?
    Thusly: http://i.imgur.com/ZghWTMa.jpg  

    Actually, I'm not completely sure yet.
    Steve's answer assumes screen printing with a single opaque white ink. It won't work if printing to non-opaque composite transfers, or cutting from aplique vinyl, or if you're going to import the two-ellipse artwork for combination with other artwork.
    Since you don't know:
    1. Draw the two circles with a stroke color and a fill color (ex: black Stroke, white fill) on both.
    2. Apply the desired stroke weight.
    3. Object>Path>Outline Stroke.
    4. Pathfinder palette: Merge.
    5. White pointer: Select the two inside regions and delete.
    6. You now have a single Compound Path; no overlapping objects, and actual "holes" where you want the substrate to show through. Apply whatever fill color (white, etc.) you need.
    But bear in mind what has already been stated: White, unless defined as a Spot Color, does not "print." Think in terms of inks, not in terms of "color". In a program like Illustrator, "white" normally means "no ink." And you always have to know what printing method you are designing for.
    JET

  • Can i copy values from one object to another ?

    One more help..
    How do i compare the input values with the ones in an object of another class ?
    Can i copy values of one object of a class to different object of another class ?
    Thanks,
    Sanlearns

    How do i compare the input values with the ones in an
    object of another class ?By getting and comparing them?
    Can i copy values of one object of a class to
    different object of another class ?Yes, you can. But you shouldn't, as you're breaking encapsulation all over the place. You could use setter methods (if available) to set the values.

  • Problem updating a control on one panel based on a value change in another control on a different panel

    Hi,
    I am trying to update the value of a control on one panel when the value of another control on a different panel is changed.  The two panels are saved in two different .uir files, so there are two associated .h files generated by CVI.  The problem is that, inside the callback function for the control that is being modified (Ctrl_Id_A on Panel_A), when I call SetCtrlVal(Panel_B, Ctrl_Id_B, Value); 'Panel_B' and 'Ctrl_Id_B' (which have the same numeric values as Panel_A = 1 and Ctrl_Id_A = 2 in their respective .h files) are being interpreted as Panel_A and Ctrl_Id_A.  I never understood how CVI makes this distinction, eg. knowing which of PANEL_A = 1 and PANEL_B = 1 is being referred to, but didn't worry about it since I never needed cross-communication between panels until now.  Any help on how to implement this would be greatly appreciated.  Thanks!
    Solved!
    Go to Solution.

    This is a basic issue on which you can find tons of forum posts
    The online help for the function recitates:
    int SetCtrlVal (int panelHandle, int controlID, ...);
    Parameters
    Input
    Name
    Type
    Description
    panelHandle
    int
    Specifier for a particular panel that is currently in memory. You obtain this
    handle from LoadPanel, NewPanel, or DuplicatePanel.
    controlID
    int
    The defined constant, located in the .uir header file, that you assigned to the control in the User Interface Editor, or the ID returned by NewCtrl or DuplicateCtrl.
    value
    New value of the control. The data type of value must match the data type of the control.
    That is, you must not use the panel constant name in the first parameter of SetCtrlVal, use the panel handle instead. The system guarantees that all panel handles are unique throughout the whole application whichever is the number of panels used in every moment.
    int SetCtrlVal (int panelHandle, int controlID, ...);
    Purpose
    Sets the value of a control to a value you specify.
    When you call SetCtrlVal on a list box or a ring control, SetCtrlVal
    sets the current list item to the first item that has the value you
    specify. To set the current list item through a zero-based index, use SetCtrlIndex.
    When you call SetCtrlVal on a text box, SetCtrlVal appends value to the contents of the text box and scrolls the text box to display value. Use ResetTextBox to replace the contents of the text box with value.
    Note   This function updates the displayed value immediately. Use SetCtrlAttribute with ATTR_CTRL_VAL to set the control value without immediately updating the displayed value. For this reason, SetCtrlAttribute with ATTR_CTRL_VAL is generally faster than SetCtrlVal. However, if the control in which you are setting the value is the active control in the panel, SetCtrlAttribute with ATTR_CTRL_VAL displays the value immediately.
    Note   This function is not valid for graph and strip chart controls.
    Parameters
    Input
    Name
    Type
    Description
    panelHandle
    int
    Specifier for a particular panel that is currently in memory. You obtain this
    handle from LoadPanel, NewPanel, or DuplicatePanel.
    controlID
    int
    The defined constant, located in the .uir header file, that you assigned to the control in the User Interface Editor, or the ID returned by NewCtrl or DuplicateCtrl.
    value
    New value of the control. The data type of value must match the data type of the control.
    Proud to use LW/CVI from 3.1 on.
    My contributions to the Developer Zone Community
    If I have helped you, why not giving me a kudos?

  • Add Tags to Document tool put one object behind another or just deletes page content?

    Using Acrobat XI Pro to make documents 508 compliant PDF. I've had a number of issues went using Add Tags to document option, it’s put one object behind another or deleting it all together. Also had issues when trying to adjust the reading order, content is moved or deleted. This PDF is created from InDesing CS5
    Anybody know what I'm talking about or have any ideas about how to fix it? Thank

    Content should not ever be deleted by adding tags, but it may appear so since - as you note - objects may go into hiding behind other objects. In theory you can bring them out of hiding by rearrange things in the Order pane, but I have much better luck using the Content pane - it provides a much finer level of control. If text is hidden behind a shaded box, for example, I will move the box above the text in the Content order, then usually convert the box to an artifact if it is not one already.
    Hope this helps.
    a 'C' student

  • Replace one preset effect with another

    Is it possible to replace one preset effect with another withouth having to undo a prior preset effect? 
    When I used Aperture, holding down the Option key would allow me to replace one preset with another.

    Store > Sign Out
    Store > Sign In
    All purchases remain tied to the account used to buy them, but you can authorize iTunes to multiple accounts and put protected content from up to five on your devices. Generally best to stick to one account if possible. More so once you get to iOS devices as managing app updates over multiple devices is a chore.
    tt2

  • How to lod Hierarchy from one info object to anothe info object

    Dear Friends,
    I am facing one problem with the loading of hierarchy from one object to another.
    Please find my scenario below.
    We are having 0material with hierarchy.This hierarchy is loading from R/3.We have to load this hierarchy to anothe object by replacing the nodes.So can you guys please suggest how to achieve this.Please let me know if you people are required additional information.
    Thanks in advance.
    Regards
    Madhu

    Hi Madhu,
    By default, you cant use a transformation to load data into the Hierarchy Master data.
    I havent tried it myself, but for you to explore, I'll suggest the below idea.
    Write an ABAP program to download the hierarchy table data from 0material into a flat file.
    Create flat file datasource to upload hierarchy to the other infoobject.
    Put both of them in a process chain and execute one after another.
    Hope this helps. Pls let us know.
    Regards,
    Bijesh

  • How do I drag an image icon or image from one panel to another panel?

    Please help.
    I know to need how to drag an image icon from one panel to the other. For example, the first panel would shows the image files that is inside my folder. How can i code it so that I can drag the image that appear on the first panel into the second panel which will hold the images that I want to embed my barcode inside?
    The thumbnail size of the image and showing all the image files in my folder was done already, I only need to know how can I make the image icon to be able to drag from one panel to the other.
    Thanks.

    I found this code in some websites:
    public class ImageSelection extends TransferHandler {
         private static final DataFlavor flavors[] = {DataFlavor.imageFlavor};
         public int getSourceActions(JComponent c) {
              return TransferHandler.COPY;
         public boolean canImport(JComponent comp, DataFlavor flavor[]){
              if (!(comp instanceof JLabel)){
                   return false;
              for (int i=0, n=flavor.length; i<n; i++){
                   for (int j=0, m=flavors.length; j<m; j++){
                        if (flavor.equals(flavors[j])){
                             return true;
              return false;
         public Transferable createTransferable(JComponent comp) {
              if (comp instanceof JLabel) {
                   JLabel label = (JLabel)comp;
                   Icon icon = label.getIcon();
                   if (icon instanceof ImageIcon){
                        final Image image = ((ImageIcon)icon).getImage();
                        final JLabel source = label;
                        Transferable transferable = new Transferable(){
                             public Object getTransferData(DataFlavor flavor){
                                  if (isDataFlavorSupported(flavor)){
                                       return image;
                                  return null;
                             public DataFlavor[] getTransferDataFlavors(){
                                  return flavors;
                             public boolean isDataFlavorSupported(DataFlavor flavor){
                                  return flavor.equals(DataFlavor.imageFlavor);
                        return transferable;
              return null;
         public boolean importData(JComponent comp, Transferable t){
              if (comp instanceof JLabel){
                   JLabel label = (JLabel)comp;
                   if (t.isDataFlavorSupported(flavors[0])){
                        try {
                             Image image = (Image)t.getTransferData(flavors[0]);
                             ImageIcon icon = new ImageIcon(image);
                             label.setIcon(icon);
                             return true;
                        catch (UnsupportedFlavorException ignored){
                        catch (IOException ignored) {
              return false;
    What this codes does is to get the image from the imageicon and replace the image to the imageicon that you drag the source from. However, I had no clue how I can get the source's file name. Anyone can teach me how?
    Thanks.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • How to merge the Panel with another Panel to One Panel?

    As Title!!

    i will give it a shot. by no means do i say it is correct being a beginner myself
    Panel aPanel = new Panel();
    Panel anotherPanel = new Panel();
    Panel mythirdPanel = new Panel();
    aPanel.add(anotherPanel);
    aPanel.add(myThirdPanel);
    this should create one panel called aPanel with two panels inside - another Panel first, followed by mythirdPanel second. This should be in FlowLayout pattern as that is default unless specified.
    That is my guess and my shot.
    8)

  • ATTACHING one object to another - best way?

    Whats the best way to ATTACH one object to another in my 3D composition?
    For example, I have a circular logo which I am spinning and moving in 3D space. I want to attach a lens flare graphic to it at it's right edge.
    I will then animate the brightness of this lens flare for a few seconds.
    How do I make sure BOTH of these graphics are spinning and moving married together x,y,z all the time?
    Thanks,,
    Message was edited by: Bansaw

    Howdy,
    As Certified said, grouping multiple elements and animating the group is ideal, but as you pointed out, you often animate one object and only later decide to include more elements in the animation.
    You can copy and paste the keyframes/behaviors or drag-and-drop the animated channels from one object to the next, but that means having to update a bunch of elements every time you want to make a change. The best solution: the Match Move behavior (sound of trumpets).
    In addition to pixel-based tracking, Match Move can tell one object to simply match the transforms of another. It has two modes: attach and mimic. Attach basically nails the match-moved object to its source. Mimic has the match-moved object perform the same animation as the source. A movie that better shows the distinction can be found here.
    This works for position, scale and rotation transforms. By default, Match Move will set the next object down in the Layers List to be the source. Just drag and drop a new source (if need be) and you're good to go. Keep in mind that the behavior is overriding the targeted transforms channels on the object, so any other animation on those channels will be ignored. This is why doing the group thing is the most flexible.

  • Multiple Panels Effect Toggle

    I created the top navigation for this site based on the
    multiple slides effect -
    http://www.johnvenaproduce.com/beta/
    It works very nicely, the only problem is that once you click
    on one of the top buttons and a panel slides down, there is no way
    to close it unless you click on a different link. For instance, I
    would like to make it so that if you click on About Us, the panel
    opens, and if you click on About Us again, that panel will close,
    but I also want to have only one panel open at a time. The toggle
    is set to true, but it only affects the clicks between panels, not
    the same one. Does anyone know how I can achieve this, or perhaps
    another approach I should take?

    After much trial and error, I found a way to make it work. I
    have no idea if this is the right way to go about things, but it
    makes the menu function as I wanted it to. Here is the code, should
    anyone run into the same problem.
    <script>
    var observer = {};
    observer.nextEffect = false;
    observer.onPostEffect = function(e){
    if (this.nextEffect)
    var eff = this.nextEffect;
    setTimeout(function(){eff.start();}, 5);
    this.nextEffect = false;
    function myPanelsSlides(currentPanel)
    // The list of all the panels that need sliding
    var panels = ['about', 'products', 'media', 'contact'];
    var opened = -1;
    // Let's check if we have an effect for each of these
    sliding panels
    if (typeof effects == 'undefined')
    effects = {};
    for (var i=0; i < panels.length; i++)
    if (typeof effects[panels
    ] == 'undefined'){
    effects[panels] = new Spry.Effect.Blind(panels
    , {duration: 500, from: '0%', to: '100%', toggle: true,
    transition:Spry.sinusoidalTransition});
    effects[panels].addObserver(observer);
    if (effects[panels
    ].direction == Spry.forwards && currentPanel !=
    panels)
    opened = i;
    //prevent too fast clicks on the buttons
    if (effects[panels
    ].direction == Spry.backwards &&
    effects[panels].isRunning)
    observer.nextEffect = effects[currentPanel];
    return;
    if (opened != -1)
    observer.nextEffect = effects[currentPanel];
    effects[panels[opened]].start();
    else if (effects[currentPanel].direction != Spry.forwards)
    effects[currentPanel].start();
    //here is what I added to make the panels close when clicked
    twice
    else if (effects[currentPanel].direction != Spry.backwards)
    effects[currentPanel].start();
    </script>

  • How to get the data from one table and insert into another table

    Hi,
    We have requirement to build OA page with the data needs to be populated from one table and on save data into another table.
    For the above requirement what the best way to implement in OAF.
    I understand that if we attach VO object instance to region/page, we only can pull and put data in to only one table.
    Thanks

    You can achieve this in many different ways, one is
    1. Create another VO based on the EO which is based on the dest table.
    2. At save, copy the contents of the source VO into the dest VO (see copy routine in dev guide).
    3. commiting the transaction will push the data into the dest table on which the dest VO is based.
    I understand that if we attach VO object instance to region/page, we only can pull and put data in to only one table.
    if by table you mean a DB table, then no, you can have a VO based on multiple EOs which will do DMLs accordingly.Thanks
    Tapash

Maybe you are looking for

  • How to deal with BRS for the below scenario?

    Hi, I would like to know the solution for the below scenario for BRS: I have a customer who was maintaining their accounts with Tally software for their previous Financial Year. This year they have shifted to SAP B1 2005B. They have issued few cheque

  • Open a form as a pop up (sub form)

    In Dreamweaver 8, how do I open a form as a pop up (or sub form)? On a form users will be able to select an item. When they do I want to open a form, on top of the form that the user made the selection, and display information about their selection.

  • Why are unwanted tabs opening, trying to sell me something or repair registry problems? (obviously scam).

    How do I prevent unwanted tabs (scam & sales ads) from opening, both at start-up and when perusing the web? I'm using FF 3.6.8. This problem began around July 2010. My homepage loads just fine, but a second tab loads as well (which isn't in my homepa

  • IPhone 4 charging but doesn't show signs of charging and wont connect to windows pc

    Hi. I tried to charge my iPhone 4 today however it didn't appear to be charging. I tried different cables, chargers, computers, turning the phone on and off - including holding the home button and lock button down simulationsly, but still wouldn't wo

  • WebService URL in Admin and Managed Server????

    All, WLS configuration: Admin Server:7001 Managed Server:7003 Both Admin and Managed Servers reside in the same machine. Which is the correct URL for accessing the webservice? http://localhost:7001/test/testWebService?WSDL           OR http://localho