What is a good GUI code

Hi,
at time i writing a gui client for my application.
the problem is that i don't realy know what code for guicode will be better:
all code (everey button, label, bar etc.) inside one "open" method.
with this solution i can change the autput (such as text etc.) of Labels and buttons at runtime.
a another solution is
that every button label etc gets it own create method.
with this solution i have small simple methods, but i have to call them in the right order at the open method. I also have to create the buttons labels etc as fields so they can be changed during runtime.
(with runtime i mean changes of label texts etc. during userinteraction)
which solution will be better, for a OO Design/Model.
or is there a better solution you prefer?
thanks.
your sincerely Gideon

Since you are interested in good OO design, I would highly recommend some reading like "Design Patterns Explained" by Alan Shalloway. Some might push you into the GoF (Gang of Four) book but start easy.
One tenant of good OO is to encapsulate. So, in your GUI, I would recommend the getters and setters for each widget. Yes, this means a field for each widget on your panel. This is also great for maintenance. Nothing worse than scrolling through a huge method trying to figure out what is going on. So start off with getters/setters for each widget. Then have an initialize method (or something like that) that will add everything on your panel. Try to group like behavior/actions together.
Now, in my applications, I'm using a MDI application. That means my JFrame has JInternalFrames. My JInternalFrames in turn instantiate JPanels. In a couple of cases, I have multiple JInternalFrames calling the same JPanel. And because I like to have standardized behavior, I use mediators to handle enabling/disabling/clearing of fields, etc. But start off small and work your way into some design patterns.
I hope this helps.

Similar Messages

  • Hand made or generated GUI code, what do proffesional use?

    Hello!
    I am currious about what programs people that work as a programmer use? Is it common that they use programs that generats code like Netbeens for instance? I tryed that program in design mode to make a gui, but when I looked at the code it had generated I could not understand it. When I have seen simple example of gui code that has been hand written I have no trouble to understand the code.
    My opinion is that code is something that others than yourself can read and understand. Wich ofcource is not as simple as it sounds :) The reason I could not understand Netbeens generated code can ofcource be that I am a java beginner.
    So, what I am asking is that:
    1. Is it common that proffesional programmers use programs like Netbeens to generate GUI code ?
    2. The problem that others cant read or understand the code, is it more common that the programmer have used generated code or does the problem as easly occur when the code is hand written?
    Regards
    Martin
    Edited by: onslow77 on Nov 4, 2009 8:02 AM

    gimbal2 wrote:
    but I prefer hand made code; that generated crap is unreadable (all imho of course) and I don't understand it eitherSeconded. Code generation not only creates messy, undocumented code, but it also leads to hidden mistakes which are the worst kind. I'd rather spend a little more time writing the stuff by hand and not only having full control over the outcome, but also have full knowledge of its inner workings.Thirded. For my money, if you're building rich GUIs that are anything other than trivial, it's probably worth investing some effort in writing a layer of code to simplify building those GUIs. Working with vast amounts of raw Swing, for example, is a painful experience. For our Swing products, we've got a whole library of controls we built specific to our apps. We also wrote a layer of abstraction over the whole of Swing itself, but that's another story. Another alternative is to use a Rich Client Platform like Eclipse RCP, which provides a lot of common, rich components, and a framework for deploying them in, out of the box. Both the Eclipse and NetBeans IDEs are built upon their own respective RCP packages, which are available for you to use for your own apps. All those nice editors, drag-n-drop views, trees, menus, shortcuts and what-not, all just there for you to use without having to write any tiresome window-resizing code. Lovely. I don't know about IntelliJ, but I wouldn't be surprised if it, too, did so. Spring RCP is another such package.

  • What is better/easier  GUI Interface and Code

    I'm trying to write a GUI interface that will constantly update a bunch of variables with whatever the user inputs. Is it better to make a GUI and then try to pass the updates back to other underlying code which is in seperate Classes and methods or is it better to combine the two with the updates right in the GUI code itself.
    Right now I have made the basics of the GUI but I haven't really implemented any underlying code (I've made the robot but I don't have the servos to make it move -- as an analogy). Comments?

    Ideal system design has separation between the view and the underlying data model. Preferrably there is a 3rd intermediary, a controller. That's the MVC design pattern. However, how far you implement that pattern depends on the purpose of the program and the complexity of the data model. A simple program you can probably just implement it all right there in the GUI. It won't follow proper software development principles, but we have those so we can deal with large, complex systems. Another thing to consider is what the user input is used for. If it is not required beyond the GUI then I'd say put it in the GUI (since iot really is part of the GUI). But if it's to be used somewhere else, pass the data to the model.

  • What is the wrong in code while creating a container

    Hello all,
    what is the wrong in code while creating container.
    *& Report  ZTEST_TREE4
    REPORT  ztest_tree4.
    *       CLASS lcl_application DEFINITION
    CLASS lcl_application DEFINITION CREATE PRIVATE.
      PUBLIC SECTION.
        CLASS-METHODS: run_application.
        METHODS constructor.
      PRIVATE SECTION.
        CLASS-DATA: s_container TYPE REF TO cl_gui_simple_container.
        DATA: container TYPE REF TO cl_gui_simple_container.
    ENDCLASS.                    "lcl_application DEFINITION
    *       CLASS lcl_implementation DEFINITION
    CLASS lcl_application IMPLEMENTATION.
      METHOD run_application.
        IF lcl_application=>s_container IS INITIAL.
          CREATE OBJECT lcl_application=>s_container.
        ENDIF.
      ENDMETHOD.                    "run_application
      METHOD constructor.
        CREATE OBJECT container.
      ENDMETHOD.                    "constructor
    ENDCLASS.                    "lcl_implementation DEFINITION
    *&      Module  STATUS_0100  OUTPUT
    *       text
    MODULE status_0100 OUTPUT.
      CALL METHOD lcl_application=>run_application.
      SET PF-STATUS 'CO_100'.
      SET TITLEBAR 'CO_100'.
    ENDMODULE.                 " STATUS_0100  OUTPUT
    *&      Module  USER_COMMAND_0100  INPUT
    *       text
    MODULE user_command_0100 INPUT.
    ENDMODULE.                 " USER_COMMAND_0100  INPUT
    *&      Module  exit  INPUT
    *       text
    MODULE exit INPUT.
      LEAVE PROGRAM.
    ENDMODULE.                 " exit  INPUT
    START-OF-SELECTION.
      CALL SCREEN 100.
    regards,
    Lisa.
    Edited by: Lisa Roy on Mar 6, 2008 10:15 AM
    Edited by: Lisa Roy on Mar 6, 2008 10:29 AM

    Hi Lisa,
    a container must be placed in a respective screen area. Also the module calls must be implemented in your screen input and output sections. Finally you have to place something (a GUI control) in your container.
    I do not see anything like this in your program. So I don't know what you are asking about. Do you get any error message?
    Regards,
    Clemens

  • [b]Does anybody know what is wrong with my code[/b]

    I cannot see what is wrong with this code but i can't get it to compile. when i try to compile it i get the
    "Exception in thread "main" java.lang.NoClassDefFoundError:
    Is this a problem with compiling or is it a code error?
    Here is my code
    public class IntCalc{
         int value;
         public IntCalc(){
              value = 0;
         public void add(int number)     {
              value = value + number;
         public void subtract(int number){
              value = value - number;
         public int getValue()     {
              return value;
    Message was edited by:
    SHIFTER

    Youd don't have a class file. Compile it first then run it. If your compiler isnt making the .class file tell me and ill give you a link to a realy good java compiler.

  • JScrollPane, what is wrong with my code?

    Hi, I appreciated if you helped me(perhaps by trying it out yourself?)
    I wanted my JScrollPane to display what is drawn on my canvas (which may be large)by scrolling, but it says it doesn't need any vertical and horizontal scroll bars. Here is the code that has this effect
    import javax.swing.*;
    import java.awt.*;
    public class WhatsWrong extends JApplet{
    public void init(){
    Container appletCont = getContentPane();
    appletCont.setLayout(new BorderLayout());
    JPanel p = new JPanel();
    p.setLayout(new BorderLayout());
    p.add(new LargeCanvas(),BorderLayout.CENTER);
    int ver = ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED;
    int hor = ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED;
    JScrollPane jsp = new JScrollPane(p,ver,hor);
    appletCont.add(jsp,BorderLayout.CENTER);
    class LargeCanvas extends Canvas{
    public LargeCanvas(){
    super();
    setBackground(Color.white);
    public void paint(Graphics g){
    g.drawRect(50,50,700,700);
    and the html code:
    <html>
    <body>
    <applet code="WhatsWrong" width = 300 height = 250>
    </applet>
    </body>
    </html>
    What shall I do?
    Thanks in advance.

    What is wrong with your code is that your class, LargeCanvas must implement the Scrollable interface in order to be scrolled by a JScrollPane.
    A comment regarding your use of Canvas and Swing components: The Java Tutorial recommends that you extend JPanel to do custom painting. Canvas is what they call a "heavyweight" component and they recommend not to mix lightweight (Swing) components and heavyweight components.
    There is a lot more information on custom painting on the Java Tutorial in the Lesson "Creating a GUI with Swing.

  • What is a good way to load 80 million documents in DocumentDB?

    I am having problems loading a large set of data.  We want to load 80 million documents.  We are trying to do testing for an IOT solution that will end up having a lot of data in it.  I followed the instructions to use a stored procedure to
    do a bulk load provided by Ryan CrawCour on the Microsoft Site:
    https://code.msdn.microsoft.com/windowsazure/Azure-DocumentDB-NET-Code-6b3da8af
    But it throws exceptions when we load 2,000 - 5,000 documents.  Our documents are only about 80 characters.
    Error: One or more errors occurred., Message: Exception: Microsoft.Azure.Documen
    ts.RequestRateTooLargeException, message: {"Errors":["Request rate is large"]},
    What is a good way to load large datasets?  ( Load backups, migrate data, ... )  Or is DocumentDB just a wrong choice when you have millions of rows to load?
    Thanks

    Hi,
    I had been working on this from around one month and I am happy to say that my code works. Was able to upload around 0.5 million documents in 20 min. 
    The configuration was Document DB with S3 , I scaled out for 16 collection for sharding, I think you need to shard out more. This will depend on how much each document takes.
    So the Calculation goes like if each document is lets say on an average 2Kb of Size and you have 80 million documents that will come out to be 160GB
    That means you will need more than 16 collections to store as at Max 1 collection can have 10GB of Data. So to be on the safer side I would say lets go for 3 times the storage so 48 collections . If all of them are at S3 than you have 2500 RUs spread across
    48 collections and I am sure if you do insertion now you will not get Request Rate too large exception.
    I have come up with this code hopefully it will help you as well.
    https://social.msdn.microsoft.com/Forums/azure/en-US/d036afe2-78ec-45ee-8b0d-297f0f5320fe/azure-documentdb-bulk-insert-using-stored-procedure.
    For Sharding you can have look at
    https://msdn.microsoft.com/en-us/library/dn589797.aspx?f=255&MSPPError=-2147217396.

  • Red highlight next to code in dreamweaver. What is wrong with the code and is it affecting the websi

    What is wrong with the code and is it affecting the website?

    Line 107 looks dodgy to me and it won't have any effect on your code.  However, it is a good idea to post a complete link to your CSS for us to see it in full and to validate it using external tools.  In fact, you could validate the CSS (and HTML) yourself..
    <http://jigsaw.w3.org/css-validator/>
    Good luck.

  • What is reflection good for?

    i heard people use reflection with rmi, but what it is good for?
    if i use reflection to figure out what methods etc a class has, how do i know what they do?

    Oh cool, you just gave me an idea!
    Storing bean class names in a db and upon retrieval of any name, a single utility can construct an entire GUI editor panel for any variety of java bean conforming to the Java Bean specifications. This way, if ever I want to add a new Panel to an application for a new module or set of features, all I would hypothetically have to do is create the bean and add the name to the db and load up my app without even having to create the new GUI interface for editing it.
    thanks!
    Oh and one other additional thing reflection is good for, is interfacing with XML config files using the attribute names as identifiers for locating the setters (E.g., Spring Framework) as well as a bunch of other related XML things.
    Your imagination is your only limit. I would excercise caution in where and how you use it though. Usually best to use in initialization routines rather than runtime functions or during exhaustive processes.

  • What is the network unlock code for my HTC Thunderbolt?

    I want to unlock my husband and I's HTC Thunderbolts. Our contract is up and we bought our phones out right  before we signed a contract. What is the network unlock code for the HTC Thunderbolt phones? 

    Thanks. Apparently Verizon isn't really "sorry to see the customer go".  I'll simply buy an unlocked phone and be done with Verizon for good. Two years is to long to be treated like this by them.  I bought my phone and should be able to use it with whatever carrier I want. It is no longer Verizon's phone. Yes I understand they own some of the stuff they put on my phone but by all means they can remove it. I didn't want their crap on their in the first place. I wish the rest of America would quick kissing their rear.  End Rant
    >>Edited to remove profanity<<
    Message was edited by: Verizon Moderator

  • What is the best bar-code app

    what is the best bar-code scanning app?

    ohjay,
    First I am going to criticize the general practice on this forum of not posting one's "Location" and "Carrier". This information is important to almost any question that can be asked about an iPhone !!!
    That said; Give "Redlaser Bar Code and QR code scanner" a try. I believe e-Bay bought out the company that started it and is now the application owner/manufacturer.
    It will do bar codes and "QR" codes, kind of an all in one scanner and it is free. But like I said it depends a lot on were you live as to how well any scanner is going to perform searches and such in your location.
    PS - Just download all the free ones until you find one you like the best. Free is good and their are a gazillion free ones (well maybe not that many but a lot ).

  • What are some good, standard, help strategies?

    I'm learning JSP, coming from a Cold Fusion background.
    The biggest difficulty I've found in learning a new language is learning where to get help. This means:
    1) Which book(s) to buy (there's a bazillion of 'em)
    2) Where can I get help locally? Is there an IDE that is better for JSP? does any IDE provide in-depth help and docs on JSP? or code samples? Is there a detailed langauage reference I can download and use, or import into my IDE of choice (which is Homesite/Cold Fusion Studio)?
    3) Where can I get help online? What are the best web sites to provide answers using tutorials, articles, forums, and/or sample code? I'm sure this site here at Sun has great stuff, but is it 'real-world' information?
    I realize there are a ton of books and sites to help. The problem may be that, because there are so many, newbies have a hard time knowing which ones are the best for us. We don't have the time, money, or resources to evaualuate all the books and websites that are avaialable. I think I need a short list of the most popular and common sites and books.
    Also, For the above information, I need resources that can provide both newbie information ('cause I'm new to the language), intermediate information for people who have coding experience and catch on quickly, and advanced info for the nitty gritty occasions that inevitably pop up while coding.
    I have learned some of the best help strategies for Cold Fusion, but any time I start learning a different language, I struggle to develop a new and efficient help strategy. What are some good suggestions?

    Try professional JSP from Wrox Publication - a good book, but you will have to sit and read it, patiently - there is no shortcut to anything.
    Ironluca

  • What is wrong with this code? on(release) gotoAndPlay("2")'{'

    Please could someone tell me what is wrong with this code - on(release)
    gotoAndPlay("2")'{'
    this is the error that comes up and i have tried changing it but it is not working
    **Error** Scene=Scene 1, layer=Layer 2, frame=1:Line 2: '{' expected
         gotoAndPlay("2")'{'
    Total ActionScript Errors: 1 Reported Errors: 1
    Thanks

    If you have a frame labelled "2" then it should be:
    on (release) {
        this._parent.gotoAndPlay("2");
    or other wise just the following to go to frame 2:
    on (release) {
         this._parent.gotoAndPlay(2);
    You just had a missing curly bracket...

  • I can't figure out what's wrong with this code

    First i want this program to allow me to enter a number with the EasyReader class and depending on the number entered it will show that specific line of this peom:
    One two buckle your shoe
    Three four shut the door
    Five six pick up sticks
    Seven eight lay them straight
    Nine ten this is the end.
    The error message i got was an illegal start of expression. I can't figure out why it is giving me this error because i have if (n = 1) || (n = 2) statements. My code is:
    public class PoemSeventeen
    public static void main(String[] args)
    EasyReader console = new EasyReader();
    System.out.println("Enter a number for the poem (0 to quit): ");
    int n = console.readInt();
    if (n = 1) || (n = 2)
    System.out.println("One, two, buckle your shoe");
    else if (n = 3) || (n = 4)
    System.out.println("Three, four, shut the door");
    else if (n = 5) || (n = 6)
    System.out.println("Five, six, pick up sticks");
    else if (n = 7) || (n = 8)
    System.out.println("Seven, eight, lay them straight");
    else if (n = 9) || (n = 10)
    System.out.println("Nine, ten, this is the end");
    else if (n = 0)
    System.out.println("You may exit now");
    else
    System.out.println("Put in a number between 0 and 10");
    I messed around with a few other thing because i had some weird errors before but now i have narrowed it down to just this 1 error.
    The EasyReader class code:
    // package com.skylit.io;
    import java.io.*;
    * @author Gary Litvin
    * @version 1.2, 5/30/02
    * Written as part of
    * <i>Java Methods: An Introduction to Object-Oriented Programming</i>
    * (Skylight Publishing 2001, ISBN 0-9654853-7-4)
    * and
    * <i>Java Methods AB: Data Structures</i>
    * (Skylight Publishing 2003, ISBN 0-9654853-1-5)
    * EasyReader provides simple methods for reading the console and
    * for opening and reading text files. All exceptions are handled
    * inside the class and are hidden from the user.
    * <xmp>
    * Example:
    * =======
    * EasyReader console = new EasyReader();
    * System.out.print("Enter input file name: ");
    * String fileName = console.readLine();
    * EasyReader inFile = new EasyReader(fileName);
    * if (inFile.bad())
    * System.err.println("Can't open " + fileName);
    * System.exit(1);
    * String firstLine = inFile.readLine();
    * if (!inFile.eof()) // or: if (firstLine != null)
    * System.out.println("The first line is : " + firstLine);
    * System.out.print("Enter the maximum number of integers to read: ");
    * int maxCount = console.readInt();
    * int k, count = 0;
    * while (count < maxCount && !inFile.eof())
    * k = inFile.readInt();
    * if (!inFile.eof())
    * // process or store this number
    * count++;
    * inFile.close(); // optional
    * System.out.println(count + " numbers read");
    * </xmp>
    public class EasyReader
    protected String myFileName;
    protected BufferedReader myInFile;
    protected int myErrorFlags = 0;
    protected static final int OPENERROR = 0x0001;
    protected static final int CLOSEERROR = 0x0002;
    protected static final int READERROR = 0x0004;
    protected static final int EOF = 0x0100;
    * Constructor. Prepares console (System.in) for reading
    public EasyReader()
    myFileName = null;
    myErrorFlags = 0;
    myInFile = new BufferedReader(
    new InputStreamReader(System.in), 128);
    * Constructor. opens a file for reading
    * @param fileName the name or pathname of the file
    public EasyReader(String fileName)
    myFileName = fileName;
    myErrorFlags = 0;
    try
    myInFile = new BufferedReader(new FileReader(fileName), 1024);
    catch (FileNotFoundException e)
    myErrorFlags |= OPENERROR;
    myFileName = null;
    * Closes the file
    public void close()
    if (myFileName == null)
    return;
    try
    myInFile.close();
    catch (IOException e)
    System.err.println("Error closing " + myFileName + "\n");
    myErrorFlags |= CLOSEERROR;
    * Checks the status of the file
    * @return true if en error occurred opening or reading the file,
    * false otherwise
    public boolean bad()
    return myErrorFlags != 0;
    * Checks the EOF status of the file
    * @return true if EOF was encountered in the previous read
    * operation, false otherwise
    public boolean eof()
    return (myErrorFlags & EOF) != 0;
    private boolean ready() throws IOException
    return myFileName == null || myInFile.ready();
    * Reads the next character from a file (any character including
    * a space or a newline character).
    * @return character read or <code>null</code> character
    * (Unicode 0) if trying to read beyond the EOF
    public char readChar()
    char ch = '\u0000';
    try
    if (ready())
    ch = (char)myInFile.read();
    catch (IOException e)
    if (myFileName != null)
    System.err.println("Error reading " + myFileName + "\n");
    myErrorFlags |= READERROR;
    if (ch == '\u0000')
    myErrorFlags |= EOF;
    return ch;
    * Reads from the current position in the file up to and including
    * the next newline character. The newline character is thrown away
    * @return the read string (excluding the newline character) or
    * null if trying to read beyond the EOF
    public String readLine()
    String s = null;
    try
    s = myInFile.readLine();
    catch (IOException e)
    if (myFileName != null)
    System.err.println("Error reading " + myFileName + "\n");
    myErrorFlags |= READERROR;
    if (s == null)
    myErrorFlags |= EOF;
    return s;
    * Skips whitespace and reads the next word (a string of consecutive
    * non-whitespace characters (up to but excluding the next space,
    * newline, etc.)
    * @return the read string or null if trying to read beyond the EOF
    public String readWord()
    StringBuffer buffer = new StringBuffer(128);
    char ch = ' ';
    int count = 0;
    String s = null;
    try
    while (ready() && Character.isWhitespace(ch))
    ch = (char)myInFile.read();
    while (ready() && !Character.isWhitespace(ch))
    count++;
    buffer.append(ch);
    myInFile.mark(1);
    ch = (char)myInFile.read();
    if (count > 0)
    myInFile.reset();
    s = buffer.toString();
    else
    myErrorFlags |= EOF;
    catch (IOException e)
    if (myFileName != null)
    System.err.println("Error reading " + myFileName + "\n");
    myErrorFlags |= READERROR;
    return s;
    * Reads the next integer (without validating its format)
    * @return the integer read or 0 if trying to read beyond the EOF
    public int readInt()
    String s = readWord();
    if (s != null)
    return Integer.parseInt(s);
    else
    return 0;
    * Reads the next double (without validating its format)
    * @return the number read or 0 if trying to read beyond the EOF
    public double readDouble()
    String s = readWord();
    if (s != null)
    return Double.parseDouble(s);
    // in Java 1, use: return Double.valueOf(s).doubleValue();
    else
    return 0.0;
    Can anybody please tell me what's wrong with this code? Thanks

    String[] message = {
        "One, two, buckle your shoe",
        "One, two, buckle your shoe",
        "Three, four, shut the door",
        "Three, four, shut the door",
        "Five, six, pick up sticks",
        "Five, six, pick up sticks",
        "Seven, eight, lay them straight",
        "Seven, eight, lay them straight",
        "Nine, ten, this is the end",
        "Nine, ten, this is the end"
    if(n>0)
        System.out.println(message[n]);
    else
        System.exit(0);

  • Can anyone tell me what apple hardware test error code apple hardware 4MOT/4/40000002: Exhaust-1153 or 1209 means? I am running a MacBook Pro.

    Can anyone tell me what apple hardware test error code apple hardware 4MOT/4/40000002: Exhaust-1153 or 1209 means? I am running a MacBook Pro

    The motor on the exhaust fan has failed or is failing.

Maybe you are looking for