Help on Gui(Swing) design

OK here is my situation:
Scenario:
I have a class i call mainwindow: it holds three other classes. TopPanel, midpanel, and bottompanel, all of which only hold your basic components(Jbuttons, JtextArea...so on). The main window just sets all these up and places them in the mainwindow. Also, i have another class called mainListener which implements an ActionListener which is its sole purpose is to react to actions. The important factor here is that whenever an item in the toppanel or midpanel performs an action, the action will put text on the bottom panels textArea.
My questions are:
1) Is this design practical? or is the overkill, too many class for one simple thing.
2) One problem i have been having is getting the class to talk to eachother, when i click on and item, the mainListener class does listen, but i can't return an action to the bottomPanel to write to its textarea. How do i make communication Happen.
3) One solution i thought about was to forget about the separate listener class, implement the listener directly on the mainWindow class, and finally use fully qualified names to reference to the separate object in the window.
Another solution i was thinking about is letting each of the individual class implement its own ActionListener interface, but how would i go about letting them communicate with each other?
If anyone has any suggestions, please share them with me. Any input to help in my design would be greatly appreaciated. Thanks in advanced.

In your bottom panel class, add a method which will receive the text and then add it to the JTextArea.
public void setBottomText(String s)
     myTextArea.setText(s);
}and call it from the listener class.
Mark

Similar Messages

  • Gui code design question ...

    Hi
    I need some designtip. Im doing a gui with tabs. Due to lots of lines of code when setting up each tab, the gui class rows is now heading towards infinity. Additionally the actionperformed method from all the buttons, jtexts and textareas on the tabs ... is also growing towards infinity.
    Simply put: I need design tips from the javamasters. Im quite bad at these kinds of design issues.
    A subquestion is also if there is any tutorials/books/howtos on how to come up with excellent designs, making the coding sweet.
    Thanks in advance !!!

    Hello,
    the topic of this thread is basically Gui code design. So, first of all, i recommend to understand the MVC-pattern, as it is the first step to get an understanding of reusable gui code. The Observer-pattern is no substitute for the MVC-pattern, but the MVC-pattern implies the Observer-pattern. Any MVC related topic will lead you in a second step to the Observer-pattern (see also The Core Java Technologies Tech Tip of January 13, 2006: http://java.sun.com/developer/JDCTechTips/2006/tt0113.html).
    Here are three classes (compiled with Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_10-b03)), which demonstrate the Observer-pattern in a very simplified way due to the shortness of code:
    The SubjectPanel which notifies the registered ObserverPanel:
    import java.awt.BorderLayout;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import javax.swing.JPanel;
    import javax.swing.JTextField;
    import javax.swing.event.ChangeEvent;
    import javax.swing.event.ChangeListener;
    public class SubjectPanel extends JPanel {
      private JTextField textfield = new JTextField("<Type some text>");
      private ChangeListener listener;
      public SubjectPanel(ChangeListener l) {
        listener = l;
        setLayout(new BorderLayout());
        add(textfield, BorderLayout.CENTER);
        textfield.setSelectionStart(0);
        textfield.setSelectionEnd(textfield.getText().length());
        textfield.addActionListener(new ActionListener() {
          public void actionPerformed(ActionEvent evt) {
            // notify the listener about the changed text
            listener.stateChanged(new ChangeEvent(textfield));
    }The ObserverPanel which wants to be notified when a change in SubjectPanel occures:
    import java.awt.BorderLayout;
    import javax.swing.BorderFactory;
    import javax.swing.JLabel;
    import javax.swing.JPanel;
    import javax.swing.JTextField;
    import javax.swing.event.ChangeEvent;
    import javax.swing.event.ChangeListener;
    public class ObserverPanel extends JPanel implements ChangeListener {
      private JLabel label = new JLabel();
      public ObserverPanel() {
        label.setBorder(BorderFactory.createEtchedBorder());
        setLayout(new BorderLayout());
        add(label, BorderLayout.CENTER);
      // Implementation of ChangeListener. This method is called by SubjectPanel
      // if the text has changed.
      public void stateChanged(ChangeEvent e) {
        label.setText(((JTextField)e.getSource()).getText());
    }The main class which contains SubjectPanel and ObserverPanel (Note, that this class doesn't know anything about the communication between the embedded panels):
    import java.awt.GridLayout;
    import javax.swing.JFrame;
    import javax.swing.WindowConstants;
    public class AppFrame extends JFrame {
      private SubjectPanel subjectPanel;
      private ObserverPanel observerPanel;
      public AppFrame() {
        setTitle("Observer");
        observerPanel = new ObserverPanel();
        // By passing the ObserverPanel to the SubjectPanel
        // a "one way communication line" is established
        subjectPanel = new SubjectPanel(observerPanel);
        getContentPane().setLayout(new GridLayout());
        getContentPane().add(subjectPanel);
        getContentPane().add(observerPanel);
      public static void main(String[] args) {
        AppFrame frame = new AppFrame();
        frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        frame.pack();
        frame.setVisible(true);
    }Please, be aware of the fact, that due to the simplification this example lacks the model which is part of the MVC-pattern. The SubjectPanel represents the Controller and the ObserverPanel the View.

  • Visual Swing Designer (for Eclipse)

    Hi there
    We've developed a client software with JBuilder. Now we want to move
    the whole project to eclipse.
    Is there a good plugin for Eclipse to design Swing applications? I haven't found one so far.
    JBuilder has a Swing designer, and it is very usable for us. Eclipse
    hasen't such a Swing designer...
    It could also be a external tool, to design our Swing Panels. But it
    has to be a visual Designer tool for swing, like the one for VisualStudio and co.
    Does anybody know a good Designer WORKING Tool? Maybee as plugin for eclipse?
    Greetings,
    Adrian

    Hi,
    It would be good to have some feedback about Swing GUI builders for Eclipse, are they usable and good. I heard much good things on Eclipse and am curious to try (althought NetBeans are still very good for me), but I develop Swing application and porting to SWT is unacceptable for me (it is not so advanced as Swing and I need many features that are in Swing only).

  • Help menu in Swing

    Hi all,
    can anyone tell me how to create an Help menu in Swing??
    i mean, like the Help menu options that you can see in Windows.
    I mean, again, by clicking on the Help option, you should see Contents etc..
    is it possible to do it in Swing? if so, how?
    thanx and regards
    marco

    There's no class called "HelpMenu" or anything like that, you'd have to create your own using tabbed panes and JTrees.

  • Help needed with a design!

    HELP! I need help with designing something!
    IMAGE on this link " http://i1072.photobucket.com/albums/w362/jjnilsson/DSC_0188.jpg "
    i need this patch on the picture to be "remade" in higher definition and the text should be MILF HUNTERS intstead of milf hunter... Anyone that might be able to help me out?
    reson for all this is that its gonna be made to a 30x40cm big patch fitting the back of our Team jackets!
    send me a pm or a mail ([email protected]) if you need any futher info or if you can help me out! I am really thankful for all the help i can get!
    With best regards J. Nilsson, Milf Hunters Mc

    I simply did as i got a tip on FB to do
    quote from adobe themselves on facebook "Adobe Illustrator You might also want to try asking on our forums as there are many people that can help there as well! http://forums.adobe.com/community/illustrator/illustrator_general"
    sry if it was wrong of me, simply thought there might be someone nice out there to give a helping hand
    Date: Tue, 5 Jun 2012 13:41:48 -0600
    From: [email protected]
    To: [email protected]
    Subject: Help needed with a design!
        Re: Help needed with a design!
        created by in Illustrator - View the full discussion
    This really isn't the place to ask for free services.
         Replies to this message go to everyone subscribed to this thread, not directly to the person who posted the message. To post a reply, either reply to this email or visit the message page: http://forums.adobe.com/message/4467790#4467790
         To unsubscribe from this thread, please visit the message page at http://forums.adobe.com/message/4467790#4467790. In the Actions box on the right, click the Stop Email Notifications link.
         Start a new discussion in Illustrator by email or at Adobe Forums
      For more information about maintaining your forum email notifications please go to http://forums.adobe.com/message/2936746#2936746.

  • Help with Print Layout Designer

    Hi all,
    I'm not sure if I should post this here or not, I already posted it in the Business One Forum.  Moderator(s)  if this is not the proper place please delete it and let me know that it is not the appropriate venue.
    I need some help with Print Layout Designer.  I am running 2005A SP01, and my customer wants a modification to the Sales Backorder Report.  They want to add the column "In Stock" to both the report as displayed on the screen and the printed document.  The report rendered to the screen has the In Stock, but it is not checked as visible.  I check it and In Stock shows up as designed.  The part I am having problems with is the printed document. I opened the PLD from the Backorder Report, and saved it under a different name.  I resized some of the columns in the repetitive area (header and data) to make room for the In Stock column.  I CAN add the text field Instock as free text and enter "In Stock" as the content.  I looked at the "backorder" column in the PLD, and it is a text field with the source System Variable and the variable is 109.  I would assume that all I need to do in my added column is to set the source to System Variable and enter the variable number.  That is the problem; I can't find the variable number for that column.  I looked on the report rendered to the screen with system information on and the variable is "3 #000027825,OnHand".  I looked at the Back Order column of the report rendered to the screen and the variable is "3 #000028725,OpenCreQty".  I found a spreadsheet that is supposed to contain a list of system variables for 2007A, but the document type for this report is BRDR and that document type does not appear in the list of document types in that spreadsheet.  I looked for a similar spreadsheet for 2005A SP01 but didn't find one.  I DID find a document "How To Customize Printing Templates with the Print Layout Designer".  According to that document, I should be able to get the system variable from the report rendered to the screen with System Information turned on.  Can anyone help?
    TIA,
    Steve

    I haven't dealt with this before so I can't be certain, but here are my thoughts.
    The Backordered Qty is probably a calculated field, so that's why it's a system variable. The In Stock is a defined field, so you probably can use the file and field number, OITM, OnHand. I would look at maybe the stock number or description to see how those are setup on the form instead of the backordered qty field.

  • Help needed with Report Design

    Hi All,
    Here is the requirement.
    Period Type(holds 2 values) : Payment and Vested.
    we have field 'Total Days' which is calculated based on "User Selected" Period Type.
    For example, When Period Type is Payment,
    If start date is less than or equal to grant date and end date is less than or equal to vest date, then calculation is (End Date - Grant Date)+1
    If start date is greater than grant date and end date is less than or equal to vest date, then calculation is (End Date - Mobility Start Date)+1 (similarly 2 more if conditions) ...we have similar calculation for Period Type - 'Vested'.
    This Period Type is a multiselect Prompt. How can this be achievable.
    Any thoughts will be greatly appreciated.
    Thanks.

    I simply did as i got a tip on FB to do
    quote from adobe themselves on facebook "Adobe Illustrator You might also want to try asking on our forums as there are many people that can help there as well! http://forums.adobe.com/community/illustrator/illustrator_general"
    sry if it was wrong of me, simply thought there might be someone nice out there to give a helping hand
    Date: Tue, 5 Jun 2012 13:41:48 -0600
    From: [email protected]
    To: [email protected]
    Subject: Help needed with a design!
        Re: Help needed with a design!
        created by in Illustrator - View the full discussion
    This really isn't the place to ask for free services.
         Replies to this message go to everyone subscribed to this thread, not directly to the person who posted the message. To post a reply, either reply to this email or visit the message page: http://forums.adobe.com/message/4467790#4467790
         To unsubscribe from this thread, please visit the message page at http://forums.adobe.com/message/4467790#4467790. In the Actions box on the right, click the Stop Email Notifications link.
         Start a new discussion in Illustrator by email or at Adobe Forums
      For more information about maintaining your forum email notifications please go to http://forums.adobe.com/message/2936746#2936746.

  • To intercept all exception of GUI Swing?

    Blank I tried a method in order to intercept all the exception that can be verified to the inside of a GUI Swing without necessarily to mapping all the code of blocks try & catch.
    I was just trying an interface of the class java.lang.Exception in order to try to make a override of the methods, if there is someone that has already experienced this technique.
    THANKS

    bah, you can throw every exception to the caller method,
    and that one can forward it, too
    I have never tried this, but maybe you can forward all exceptions to
    the main() method, and there should be enough only one try-catch block.
    but then you have declare most of your methods to throw something.
    I advise you to handle errors at least in a very primitive manner,
    only using System.err if you do not want to create some user-friendly,
    GUI-based error treatment.
    println is very good for debugging and development, use it, really.
    First, you can ignore all the exceptions in your code,
    and if something goes wrong, just read your console output
    for more debug info.

  • Help with implementing Swing GUI within jpg image

    Dear Java Experts,
    I have a question, is there a way to implement java swing objects (ie jbutton, jcombobox, etc) within an imageicon. Basically, i am trying to juggle between ways of getting JSwing GUI into a background jpg image. Please help me. I thank you all in advance.

    You've it back to front.
    Create an transparent extension of JPanel that paints an image on it's
    background before running it's super class paint method.
    You'll need to extend this example to stretch, center or tile the image
    but otheriwse it's complete.
    BTW - you have to pass an argument to this example that is the path of
    the image you want on the background of the panel, like:
    java -cp <whatever> MyJavaProject1 images/something.gif
    Enjoy.
    import java.awt.*;
    import javax.swing.*;
    import javax.swing.border.*;
    public class MyJavaProject1
         static class BackgroundPanel
              extends JPanel
              private ImageIcon mIcon;
              public BackgroundPanel(ImageIcon icon) {
                   mIcon= icon;
                   super.setOpaque(false);
              public void setOpaque(boolean flag) { }
              public void paint(Graphics g)
                   g.drawImage(mIcon.getImage(), 0, 0, null);
                   super.paint(g);
         public static void main(String[] argv)
              JFrame frame= new JFrame(argv[0]);
              BackgroundPanel panel= new BackgroundPanel(new ImageIcon(argv[0]));
              panel.setLayout(new GridLayout(0,2,4,4));
              panel.setBorder(new EmptyBorder(4,4,4,4));
              panel.add(new JLabel("Name"));
              panel.add(new JTextField());
              panel.add(new JLabel("Address"));
              panel.add(new JTextField());
              panel.add(new JLabel("Phone"));
              panel.add(new JTextField());
              frame.getContentPane().add(panel, BorderLayout.CENTER);
              frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              frame.pack();
              frame.setResizable(false);
              frame.setVisible(true);
    }

  • Designing a smart Swing GUI with design patterns

    Hi !
    I have to build a quite big Swing GUI from
    scratch. I would like to use smart design patterns to :
    * ensure reusability of some components
    * offer a framework-like set of solid classes
    to deal with generic problems
    * try to respect MVC pattern as close as possible
    from the real MVC spirit (not the half MVC
    pattern Swing is build upon)
    Could somebody give me any link towards ressources/docs/articles dealing with how
    to build such a smart Swing GUI ?
    Thanx a lot !

    Hi !
    I have to build a quite big Swing GUI from
    scratch. I would like to use smart design patterns to :
    * ensure reusability of some components
    * offer a framework-like set of solid classes
    to deal with generic problems
    * try to respect MVC pattern as close as possible
    from the real MVC spirit (not the half MVC
    pattern Swing is build upon)
    Could somebody give me any link towards ressources/docs/articles dealing with how
    to build such a smart Swing GUI ?
    Thanx a lot !

  • New help on java swing GUI.....

    k, im new to java. Just started learning a month ago. Anyway, I was wondering how one can link gui together using buttons. For example, when i press enter on a registration gui, it'll take me to the confirmation gui. What's the best way to do this? anyone has any idea or can point me to a website with info. Thanks A lots folks.

    Well, bascially you would add a Button (e.g. "Next" or "Submit") to your Window/Panel (whatever you prefer). This add has an ActionListener assigned which will open up the next Window/Panel.
    Then you define this button to be your default button on that window (check JRootPane.setDefaultButton() for this) so that Enter will fire the button.
    Check the Swing online tutorial for an introduction to Swing and how Buttons (and their associated ActionListener) work.
    Thomas

  • GUI swing class help needed

    hi, i just need some help to create a bar kind of object (like a bar of battery shown in mobile phones).
    the information i have is in percentage from 0-100%. and what i have planned is that:
    the bar will be split into four:
    from 0-25: one bar will be colored green.
    26-49 "
    50-74 "
    75-100
    the bar information will be from the battery left percentage as mentioned above.
    also if the battery is below 25% the GUI should give an alert (possible red screen with big "alert"..)
    I started doing the frame but got stuck on the bar. pls can you help.
    im looking for nothing complex like make it very accurate to each value of infor. thanks

    Hi,
    You can use a JProgressBar (min 0 max 4)...
    Or make a custom bar with some filled rectangles ...
    Olek
    Edited by: Olek on Oct 11, 2007 10:01 AM

  • Tools for Swing Design

    Hi,
    Kindly help me know the tools available to Design an application using Java Swing.
    I would be thankful if you can provide me the vendor information also.
    Thanks in advance
    Lakshmi

    It makes sense. The state of the art of GUI builders is not perfect.
    In particular the way Layout Managers are handled is often annoying.
    Some tools recommend just not using one, which is not a good idea IMO.
    In my experience, there's no real 2-way editing tool available. They all
    generate code and some (netbeans, don't know about all others) are
    honest enough to guard the generated code so you are not tempted to
    modify or change it.
    Having said that, try one of the free tools, it's not as bad as I may say it is! ;-)
    -Alexis

  • Is there a forum for Java GUI Application Design?

    Hi all,
    I've used this forum a lot and found a lot of help on it for Swing usage specifics. However, whenever I ask a question about broader design or architecture of a full Swing app I get little or no response. Sadly I'm no stranger to "view 50, replies 0" :o(
    Either I'm asking stupid questions or I'm asking the in the wrong forum - does anyone know of a good place to ask about design/best practices for Java, GUI applications? I've seen some of the "programmer"/"developer" groups on Google Groups.
    Many thanks.
    Yours, hoping for at least one reply,
    Chris

    You're right, I typed that wrong. The method signature should be addDataChangeListener(DataChangeListener lis, DataChangeType type)
    When a component registers itself as a change listener, say it wants to know whenever an object of type Foo is changed, it calls DataChangeType.addDataChangeListener(this, DataChangeType.FOO). (the Enum elements coorespond to the objects we want to listen for) Then it implements the dataChanged(DataChangeType type, Object obj) method that will be called by the controller when objects of type Foo are changed. (obviously this is an interface) Whenever a component updates an object of type Foo, it calls DataChangeControl.dataChanged(DataChangeType.FOO, theFooObject), and then the controller will notify all listeners who are interested in Foo objects changing.
    The DataChangeControl maintains a hashmap of <DataChangeType, List < DataChangeListener> >. So when a new listener is added, it checks the type to see if a list is already keyed to that object type in the hashmap. If so it adds the listener to that list, if not it creates a new list in the hashmap with the type as the key. That way when an object is changed, it notifies only those listeners who are registered to listen to that type of object being changed. Hopefully that makes sense.

  • Help whit GUI and code separeted files !

    Hi.. i have a problem...
    i wanna have two classes one that has the code.. and the other that as the GUI formating... so they have to comunicate..
    Example :
    Code Class
    public class EFClient   
        EFClientGUI gui;
        public EFClient(){ 
        public void dosomething(){
             gui = new EFClientGUI ();
             gui.Label1.getText(); ---> i get a nullpointexception here
    }GUI CLASS :
    public class EFClientGUI extends javax.swing.JFrame {
        public EFClient efClient;
        public EFClientGUI(String teste){      
            efClient=new EFClient();---> this will call the "code"
    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                        
         try{
            efClient.dologin("Duarte","Rui");---- calls code class
         }catch(Exception ex){
             System.out.println(ex);
    }here a littel explanation :
    I run EFClientGUI ..... it calls EFClient... and designs.... tem i click the button and i trie to do the login.... the te login writes something to GUI...
    can someone help ?

    problem solved

Maybe you are looking for