"Best practice" for components calling components on different panels.

I'm very new to Swing. I have been learning from tutorials, but these are always relatively simple interfaces , in which every component and container is initialised and added in the constructor of a main JFrame (extension) object.
I would assume that more complex, real-world examples would have JPanels initialise themselves. For example, I am working on a project in which the JFrame holds multiple JPanels. One of these Panels holds a group of JToggleButtons (grouped in a ButtonGroup). The action event for each button involves calling the repaint method of one of the other Panels.
Obviously, if you initialise everything in the JFrame, you can simply have the ActionListener refer to the other JPanel directly, by making the ActionListener a nested class within the JFrame class. However, I would like the JPanels to initialise their own components, including setting the button actions, by using an extension of class JPanel which includes the ActionListeners as nested classes. Therefore the ActionListener has no direct access to JPanel it needs to repaint.
What, then, is considered "best practice" for allowing these components to interact (not simply in this situation, but more generally)? Should I pass a reference to the JPanel that needs to be repainted to the JPanel that contains the ActionListeners? Should I notify the main JFrame that the Action event has fired, and then have that call "repaint"? Or is there a more common or more correct way of doing this?
Similarly, one of the JPanels needs to use a field belonging to the JFrame that holds it. Should I pass a reference to this object to the JPanel, or should I have the JPanel use "getParent()", or some other method?
I realise there are no concrete answers to this query, but I am wondering whether there are accepted practices for achieving this. My instinct is to simply pass a JPanel reference to the JPanel that needs to call repaint, but I am unsure how extensible this would be, how tightly coupled these classes would become.
Any advice anybody could give me would be much appreciated. Sorry the question is so long-winded. :)

Hello,
nice to get feedback.
I've been looking at a few resources on this issue from my last post. In my application I have been using the Observer and Observable classes to implement the MVC pattern suggested by T.PD.(...)
Two issues (not fatal, but annoying) with this are:
-Observable is a class, not an interface; since most of my Observers already extend JPanel (or some such), I have had to create inner classes.
-If an Observer is observing multiple Observables, it will have to determine which Observer called its update() method (by using reference equality or class comparison or whatever). Again, a very minor issue, but something to keep in mind.I don't deem those issues are minor. The second one in particular, is rather annoying in terms of maintenance ("Err, remind me, which widget is calling this "update()" method?").
In addition to that, the Observable/Observer are legacy non-generified classes, that incurr a loosely-typed approach (the subject and context arguments to the update(Observable subject, Object context) methods give hardly any info in themselves, and they generally have to be cast to provide app-specific information.
Note that the "notification model" from AWT and Swing widgets is not Observer-Observable, but merely EventListener . Although we can only guess what reasons made them develop a specific notification model, I deem this essentially stems from those reasons.
The contrasting appraoches are discussed in this article from Bill Venners: The Event Generator Idiom (http://www.artima.com/designtechniques/eventgenP.html).
N.B.: this article is from a previous-millenary series of "Design Techniques" articles that I found very useful when I learned OO design (GUI or not).
One last nail against the Observer/Observable model: these are general classes that can be used regardless of the context (GUI/non-GUI code), so this makes it easier to forget about Swing threading rules when using them (essentially: is the update method called in the EDT or not).
If anybody has any information on the performance or efficiency of using Observable/ObserverI would be very surprised if this had any performance impact. If it had, that would mean that you have either:
- a lot of widgets that are listening to one another (and then the Mediator pattern is almost a must to structure such entangled dependencies). And even then I don't think there could be any impact below a few thousands widgets.
- expensive or long-running computation in the update methods. That's unrelated to the notification model itself.
- a lot of non-GUI components that use the Observer/Observable to communicate among themselves - all the more risk then, to have a GUI update() called outside the EDT, see remark above.
(or whether there are inbuilt equivalents for Swing components)See discussion above.
As far as your remark 2 goes (if one observer observes more than one subjects, the update() method contains branching logic) : this also occurs with the Event Delegation model indeed: for example, it is quite common that people complain that their actionPerformed() method becomes unwieldy when the same class listens for several JButtons.
The usual advice for this is, use anonymous listeners, each of which handles the event from only one source (and generally very close in code to the definition of that source), and that simply translates the "generic" event notification method into a specific method call of a Controller or Mediator .
Best regards.
J.
Edited by: jduprez on May 9, 2011 10:10 AM

Similar Messages

  • Best Practice for EJB calls from servlet?

    Hi folks
    I could not find general rules for making calls to an stateful EJB from the web container (e.g. from a backingBean). In some books they say it is a bad programming style calling them directly from a common servlet. The book says create first an HTTPSession Object and from there call the stateful EJB.
    I'm a bit confused because, I'm missing some best practice guide from where to initiate such calls.
    Can somebody please point me in the right direction?
    Kind Regards
    Bruno
    Edited by: zajoho on Oct 30, 2008 11:14 PM

    Hi Bruno,
    The main issue with the combination of stateful session beans and servlets is the servlet threading model.
    It is dangerous to store a stateful session bean reference in servlet instance state, since the servlet instance
    can be accessed concurrently, yet a stateful session bean reference is intended to be used by only one
    client.
    As you point out, one alternative is to store the reference in the HttpSession. That associates the reference
    with a particular client, which matches the stateful session bean programming model.

  • Best practice for displaying calling party ID

    I have several different office codes in a CM 4.0. I need to prepend the area code and first two digits to the actual 5 digit extension for outgoing caller ID. I am doing this by setting External Phone Number Mask on each line and telling my route group to use that value. Is this the best way to display caller ID in this situation?

    You can do this any way you want. You can check ext. ph number mask and set the mask on each phone. If you dont want to do this (too much work), you can set the prefix at the route pattern or route list level. route list level overrides route pattern level.
    HTH
    Sankar
    PS: please remember to rate posts!

  • Best practice for database calls from Java components?

    I have a java component that encapsulates some complex database logic. In unit tests, I pass in a jdbc connection.
    Is there a way to pass in a database connection from PBL for a database defined as an External Resource in an ALBPM project? That way, I can test it using the "abstract" definition in the project and know that when it is deployed to production it will use the concrete definition. And, I won't have to maintain a separate configuration of the JDBC url.
    Is there a better way to do this? Or is it possible?
    Thanks,
    Todd

    Hi Bruno,
    The main issue with the combination of stateful session beans and servlets is the servlet threading model.
    It is dangerous to store a stateful session bean reference in servlet instance state, since the servlet instance
    can be accessed concurrently, yet a stateful session bean reference is intended to be used by only one
    client.
    As you point out, one alternative is to store the reference in the HttpSession. That associates the reference
    with a particular client, which matches the stateful session bean programming model.

  • What is best practice for multi camera edit with differing lengths?

    I have three cameras that took video of an engagement party. Camera A and B took it all (with some early extra material exclusive to each camera). Camera C took some, then stopped, then took more.
    So I have four sets of clips - A and B which are complete, then C then D.
    Should I create sequence 1 with A, B and C synchonised, then create sequence 2 with A, B and D synchronised, then sequence 3 with sundry early non-multi camera clips, plus sequence 1 plus sequence 2 then late non-multi camera clips?
    Or can I synchronise A, B and C, then on the same timeline synchronise A, B and D? I'm concerned that the second synchronisation will put C out of sync.
    What is the best way to approach this?
    Thanks in advance.

    A and B which are complete, then C then D.
    I think you're looking at this in the wrong way.  You have only three cameras, A, B and C, but you don't really have a D camera, as those are just other clips from camera C.  You might call them C1 and C2 if you like, but calling them D seems to be confusing the issue, as it's still only three cameras, and three shots to choose from when cutting the sequence.  (Except for the gap between C clips, where you will have only the A and B shots to choose.)
    You can absolutely sync all the clips form camera C on the same sequence as A and B.  And it will probably be easier to do so.

  • Best practice for method calling on objects within a collection.

    Hi guys
    As you may be aware, based on my other thread here. I'm designing a card game in Java. I was hoping for some advice on the best practise on how methods should be called on a custom Object contained within a custom Collection.
    I have an instance variable for the Deck class as follows: List<Card> deckWhen creating an instance of the class I use deck = new ArrayList<Card>();So I have a Deck which only holds Card objects. My question is, for the Card methods, should I call them on the Card objects after 'getting' the Cards from the Deck or should I write methods within the Deck class which handles this method calling. Code explanation is as follows:
    Deck standardDeck = new Deck();I want to retrieve the suit value of a card within the deck. Is this the best way to do it this way:
    standardDeck.getCardAt(50).getSuit();
    //getCardAt is a method within the Deck class, getSuit() is a method within the Card classor this way:
    standardDeck.getSuitForCardAt(50);
    //getSuitForCardAt() is a method within the Deck class. This method calls the getSuit() method within its method body.Cheers for any help guys.
    Edited by: Faz_86 on Jul 10, 2010 9:53 AM

    Hey Saish
    Thanks for the response.
    My Card class does indeed override hashCode(), equals() and toString().
    The reason I am asking a card from the deck for its Suit is simply because of the rules of the game being played. The game I made is a 'Card Shredding' game where a player attempts to remove as many cards from their hand during each turn. The first to remove all their cards is the winner.
    When the game starts, two decks are created. A standard 52 card deck and an empty deck. Then 8 cards are dealt to each player and one card is dealt into the empty deck. The suit and value of the card on the empty deck called the 'shredding deck' dictates which moves are valid during each turn; The played card must match the Suit or the Value of the current card on the 'shredding deck'
    For example:
    Card on the empty deck = 8 of Spades
    The only card from a players hand which can be removed are any Spade or an Eight of any suit.
    Going back to the Deck.getSuitOfCardAtIndex(int index) , this method is needed because both the AI player and human player need to have the ability to take a look at the cards which have been added to the 'shredding deck'. Again this is because of the rules of the game. Therefore I need a method to take a look at the Suit and Value for any card in the 'shredding deck'.
    Taking all this into account, so far I have the following in my Deck class. Please comment on my design so far. As you can see I've tried to follow the Law Of Demter by creating many little wrapper methods. I understand totally wh getters and setters are bad but I cannot come up with a design solution to achieve what I need to based on the rules of the game without users getters. - Any tips on this would be great.
         public Card dealCard()
              Card cardToDeal = deck.remove(0);
              return cardToDeal;
         public void addCard(Card usedCard) //This method is used to add 'used' cards to the deck.
              deck.add(usedCard);
         public Card getFaceCard() //Returns the current face up playing card
              Card faceCard = deck.get(deck.size()-1);
              return faceCard;
         public int getFaceCardValue()
              int faceCardValue = deck.get(deck.size()-1).getValue();
              return faceCardValue;
         public int getFaceCardSuit()
              int faceCardSuit = deck.get(deck.size()-1).getSuit();
              return faceCardSuit;
         public String getFaceCardName()
              String faceCardName = deck.get(deck.size()-1).toString();
              return faceCardName;
         public Card getCardAt(int position) //Returns the current face up playing card
              Card card = deck.get(position);
              return card;
         public int getFaceCardValueAt(int position)
              int cardValue = deck.get(position).getValue();
              return cardValue;
         public int getFaceCardSuitAt(int position)
              int cardSuit = deck.get(position).getSuit();
              return cardSuit;
         public String getFaceCardNameAt(int position)
              String cardName = deck.get(position).toString();
              return cardName;
         public int getDeckSize() //When recycling cards, the size of the deck is needed to determine the best time to add more cards.
              return deck.size();
         }

  • Best practice for sharing html content on different group spaces?

    How can html content be shared between several group spaces?
    One way I have found is to add a html doc to ucm and then to add this doc as a iframe to a page.
    Are there other ways, like adding on one group space page a html layout element and then to view this content in a different space. How could this be done, with an expression language reference?
    Has someone experience in presenting the same html content on different spaces and can share how he does it. Any ideas are welcome.
    Thanks,
    Max

    Hey Max,
    Check out our technical whitepaper on Integrating ECM with Portal Technologies.
    Our "Fishbowl Portlets" allow you to share any content - HTML, WYSIWYG user generated content, documents etc - in multiple contexts (portlets, web apps, etc).
    This is one of the things that we showcased as the recent Collaborate conference in Vegas - WebCenter framework, UCM and the portlets surfacing the same items in different contexts - all personalization aware, configurable and end user/super user editable.
    The white paper can be found here:
    http://www.fishbowlsolutions.com/StellentSolutions/ContentManagementResources/index.htm
    A blog post on it can be found here:
    http://cfour.fishbowlsolutions.com/2010/03/10/fishbowl-portlets-followup-cis-and-content-consumption-options/
    warmly,
    Billy Cripe
    Fishbowl Solutions

  • Best practice for simply invoking a web service

    Hello,
    We have web services deployed and accessible as wsdl documents in the SOA service manager/UDDI product. What is the best practice for simply calling a web service method deployed without regard to whether it is deployed on Tomcat, WebSphere, Oracle, etc.
    I'd just like to create a java client to make a web service call and JAXRPC has me confused because you seem to have to have custody of the web service implementation code to call a service. Can someone point me in the right direction?
    Thanks,
    Sean

    Thanks. Here is my wsdl, how would you say this is encoded?
    <?xml version="1.0" encoding="UTF-8"?>
    <definitions
         name="OracleProcess"
         targetNamespace="http://xmlns.oracle.com/OracleProcess"
         xmlns="http://schemas.xmlsoap.org/wsdl/"
         xmlns:tns="http://xmlns.oracle.com/OracleProcess"
         xmlns:plnk="http://schemas.xmlsoap.org/ws/2003/05/partner-link/"
         xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
         xmlns:client="http://xmlns.oracle.com/OracleProcess"
        >
        <types>
            <schema attributeFormDefault="qualified" elementFormDefault="qualified" targetNamespace="http://xmlns.oracle.com/OracleProcess"
                 xmlns="http://www.w3.org/2001/XMLSchema">
                <element name="OracleProcessProcessRequest">
                    <complexType>
                        <sequence>
                            <element name="input" type="string"/>
                            <element name="input2" type="string"/>
                        </sequence>
                    </complexType>
                </element>
                <element name="OracleProcessProcessResponse">
                    <complexType>
                        <sequence>
                            <element name="result" type="string"/>
                        </sequence>
                    </complexType>
                </element>
            </schema>
        </types>
        <message name="OracleProcessRequestMessage">
            <part name="payload" element="tns:OracleProcessProcessRequest"/>
        </message>
        <message name="OracleProcessResponseMessage">
            <part name="payload" element="tns:OracleProcessProcessResponse"/>
        </message>
        <portType name="OracleProcess">
            <operation name="process">
                <input message="tns:OracleProcessRequestMessage"/>
                <output message="tns:OracleProcessResponseMessage"/>
            </operation>
        </portType>
        <binding name="OracleProcessBinding" type="tns:OracleProcess">
            <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
            <operation name="process">
                <soap:operation style="document" soapAction="process"/>
                <input>
                    <soap:body use="literal"/>
                </input>
                <output>
                    <soap:body use="literal"/>
                </output>
            </operation>
        </binding>
        <service name="OracleProcess">
            <port name="OracleProcessPort" binding="tns:OracleProcessBinding">
                <soap:address location="http://st4s:9700/orabpel/default/OracleProcess/1.0"/>
            </port>
        </service>
      <plnk:partnerLinkType name="OracleProcess">
        <plnk:role name="OracleProcessProvider">
          <plnk:portType name="tns:OracleProcess"/>
        </plnk:role>
      </plnk:partnerLinkType>
    </definitions>

  • Best Practice for module components based on API's

    Hi all,
    is there a white paper/other documents which outline best
    practice for using table/module component api's and best
    approaches to get around restrictions?
    I would also appreciate war stories about using this method of
    Forms development bearing in mind i would be using this as the
    foundation of a web deployed based application (intranet first -
    ultimately internet).
    Thanks
    Mark
    null

    You cannot add agents to skills dynamically; however, you can queue the caller into more than one CSQ based on statistics. You would use the Get Reporting Statistics and an If step within the Queued branch of your first Select Resource step. If the condition is met (e.g. Contacts Waiting >= 10) then exectue a second Select Resource step within the queued branch of the first. The contact would then be waiting in both CSQs waiting for an agent.

  • Best practices for deploying forms in a 'cluster'?

    Anyone know of any public docs that discuss typical best practices for
    - forms deployment;
    - forms apps management and version control; and/or
    - deploying (and keeping) the .frm/frx in sync when using multiple forms servers in a HA or load balancing envrionment?

    Hi adil,                      
    Based on your description, you want to know the best practices for search service in a SharePoint farm.
    Different farms have different search topologies, for the best search performance, I recommend that you follow the guidance for small, medium, and large farms.
    The article is about the guidance for different farms. 
    Search service can run with other services in the same server, if condition permits and you want to have better performance for search service and other services including BI performance, you can deploy search service in dedicated server.
    If condition permits, I recommend combining a query component with a front-end Web server to avoid putting crawl components and query components on the same serve.
    In your SharePoint farm, you can deploy the query components in a WFE server and the crawl components in an application server.
    The articles below describe the best practices for enterprise search.
    https://technet.microsoft.com/en-us/library/cc850696(v=office.14).aspx
    https://technet.microsoft.com/en-us/library/cc560988(v=office.14).aspx
    Best regards      
    Sara Fan
    TechNet Community Support

  • Best practices for search service in a sharepont farm

    Hi
    in a sharepoint web application there is many BI dashboards are deployed and also we have plan to
    configure enterprise search  for this application.
    in our sharepoint 2010 farm we have
    2  application server s
    2 WFE servers
    here one application server is running
    c.a + webanalytics service and itself is a domain controller
    second application server is for only running secure store service+ Performance point service only
    1 - here if we  run search server service in second application server can any issues to BI performance and
    2 - its best practice to run Performance point service and search service in one server
    3 -also is it  best practice to run search service in a such a application server where already other services running
    and where we have only one share point web application need to be crawled and indexed with  below crawl schedule.
    here we only run full crawl per week and incremental crawl at midnight daily
    adil

    Hi adil,                      
    Based on your description, you want to know the best practices for search service in a SharePoint farm.
    Different farms have different search topologies, for the best search performance, I recommend that you follow the guidance for small, medium, and large farms.
    The article is about the guidance for different farms. 
    Search service can run with other services in the same server, if condition permits and you want to have better performance for search service and other services including BI performance, you can deploy search service in dedicated server.
    If condition permits, I recommend combining a query component with a front-end Web server to avoid putting crawl components and query components on the same serve.
    In your SharePoint farm, you can deploy the query components in a WFE server and the crawl components in an application server.
    The articles below describe the best practices for enterprise search.
    https://technet.microsoft.com/en-us/library/cc850696(v=office.14).aspx
    https://technet.microsoft.com/en-us/library/cc560988(v=office.14).aspx
    Best regards      
    Sara Fan
    TechNet Community Support

  • Best Practices for BI, ADF and Oracle Forms installations on Weblogic

    Hi, I'm researching options on upgrading to Oracle 11g Middleware. My company currently has Oracle Forms 10g running on Oracle Application Server.
    We are interested in using Oracle Forms 11g, ADF and Jdeveloper, and Business Intelligence with Oracle's Weblogic 10.3.5.
    Is there any whitepapers or documentation on best practices for installing alll of these components together?
    For instance, can ADF ( with JSF 2.x ) be installed in the same domain as Oracle Forms 11g but use different managed servers?
    Will Business Intelligence need to be in a seperate Oracle Home with it's own weblogic installation? I spend a lot of time trying to get the JSF upgraded to 2.x in the Business Intelligence installation and could not get it to work.
    I know it's a pretty broad question but thank you for any direction on this.

    Thanx for the reply! I read through the documents and they are very good at explaining how to install the different components individually. I still can't find much on installing them together. I hope it's not just going to be a trial and error thing.
    So far I've installed done the following successfully:
    Installed 10.3.5 weblogic
    Forms and Reports 11g on top of 10.3.5
    I've created an additional managed server for our ADF applications.
    My next step is upgrading the JSF to 2.x. I would have to stage patches 12917525 and 12979653. I'm afraid it will break the forms and reports though. Any ideas?

  • What are the best practices for the RCU's schemas

    Hi,
    I was wondering if there is some best practices about the RCU's schemas created with BIEE.
    I already have discoverer (and application server), so I have a metadata repository for the Application Server. I will upgrade Discoverer 10g to 11, so I will create new schema with RCU in my metada repository (MR) of the Application Server. I'm wondering if I can put the BIEE's RCU schemas in the same database.
    Basically,
    1. is there a standard for the PREFIX ?
    2. If I have multiple components of Fusion in the same Database, I will have multiples PREFIX_MDS schema ? Can they have the same PREFIX ? Or They all need to have a different prefix ?
    For exemple: DISCO_MDS and BIEE_MDS or I can have DEV_MDS and this schema is valid for both Discoverer and BIEE.
    Thank you !

    What are the best practices for exception handling in n-tier applications?
    The application is a fat client based on MVVM pattern with
    .NET framework.
    That would be to catch all exceptions at a single point in the n-tier solution, log it and create user friendly messages displayed to the user. 

  • Best Practices for Implementing Cryptographic VPN

    With Marcin Latosiewicz
    Welcome to the Cisco Support Community Ask the Expert conversation.  This  is an opportunity to learn and ask questions about implementing cryptographic VPN and how to prepare it for the future with expert Marcin Latosiewicz. 
    Marcin will share his best practices for implementing cryptographic VPN as well as advise those customers who are looking to build a new or update their existing setups how to maximize their potential.  Additionally, Marcin will provide insight into which technologies could be applicable for new deployments and exciting new technologies that will be available in the next few months. 
    Marcin Latosiewicz is a customer support engineer at the Cisco®  Technical Assistance Center in Belgium, with more than 6 years of  experience with Cisco Security products and technologies including  IPsec, VPN, internetworking appliances, network and system security,  Internet services, and  Cisco networking equipment. Prior to joining Cisco, he operated, administered, and ran UNIX and Microsoft networks for 14 years. Latosiewicz holds bachelors and masters degrees in engineering from Warsaw University of Technology. He also holds CCIE® certification in Security (No. 25784) and CCDP® certification.
    Remember to use the rating system to let Marcin know if you've received an adequate response. 
    Because of the volume expected during this event, Marcin might not be able to answer every question. Remember that you can continue the conversation in the Security community, subcommunity, VPN, shortly after the event. This event lasts through September 20, 2013. Visit this forum often to view responses to your questions and those of other Cisco Support Community members.

    Jouni,
    Good question. And answer is complex, there is in depth and there is in depth.
    Most people would be satisfied by reading a summary of all the different components - encryption, hashing, signing, PKI, how IPsec and SSL/TLS work. This group also counts most of security CCIEs.
    To this extent CCIE Security Study Guide (by Henry Benjamin) was a good read, if a bit outdated today.
    Most people who are in depth will look first into specification.
    RFC 4301 (IPsec architecture)
    RFC 2246 (TLS 1.0)
    Are a good start and contain references to other documents worth reading.
    This is where the good folks will base their knowledge of off.
    The really in depth people will look into the math behind it and will conquer topics like
    Elliptic Curve Crypto ( http://en.wikipedia.org/wiki/Elliptic_curve_cryptography ) and difference between CCM, GCM and CCB, to which you have really good materials published by universities.
    There are relatively a few who know this.
    To start with I can suggest:
    - http://www.cl.cam.ac.uk/~rja14/book.html (Ross' Anderson book is free, informative and suprisngly entertaining, this is a definitely a must-read for security/VPN).
    - Have a look at books recommended by Richard Bejtlich or Bruce Scheiner - while they might not be VPN specific it's a good security read most of the time.
    I'll have a look at the books at home see which one can be interesting to read, and edit this post.
    M.

  • Best practice for multi-language content in common areas

    I've got a site with some text in header/footer/nav that needs to be translated between an English and Spanish site, which use the same design. My intention was to set up all the text as content to facilitate. However, if I use a standard dialog with the component's path set to a child of the current page node, I would need to re-enter the text on every page. If I use a design dialog, or a standard dialog with the component's path set absolutely, the Engilsh and Spanish sites will share the same text. If I use a standard dialog with the component's path set relatively (eg path="../../jcr:content/myPath"), the pages using the component would all need to be at the same level of the hierarchy.
    It appears that the Geometrixx demo doesn't address this situation, and leaves copy in English. Is there a best practice for this scenario?

    I'm finding that something to the effect of <cq:include path="<%= strCommonContentPath + "codeEntry" %>" resourceType ...
    works fine for most components, but not for parsys, or a component containing a parsys. When I attempt that, I get a JS error that says "design.path is null or not an object". Is there a way around this?

Maybe you are looking for