Best way to initialize a GUI

Let's say I want to construct a GUI that has over 120 components composed of JTextFields, JLabels and JCheckBoxes. Each component will have an event listener, aside from the JLabels. This GUI will be displaying and inserting data into a database. Should all of this code go into the same class, as opposed to whatever the alternative would be?
Just seems like alot of code for one class. Is this how GUI's are usually initialized, in one class?
Thanks everyone.

Consider whether subsections of the GUI are reusable.
If so, write separate classes for those. Otherwise put it all in the same class.
For example, a widget for entering a date may have 3 components, one each for day, month, year. This widget is likely to be reusable. You may even want to use it several times on the same form. Therefore I would create a DateGUI class which would extend JPanel.

Similar Messages

  • What is the best way to use Swing GUIs in an MVC design?

    I have a question on how to build an application using swing frames for the UI, but using an MVC architecture. I've checked the rest of the forum, but not found an answer to my question that meets my needs.
    My application at this stage presents a login screen to get the userid and password, or to allow the user to choose a new locale. If an Enter action is performed, the userid and password are checked against the DB. If not accepted, the screen is repainted with a "try-again" message. If the Cancel action is performed, the process stops. If a locale action is performed, the screen is repainted with different langauge labels. Once the login process is passed, a front screen (another swing frame) is presented.
    Implementation: I am using a session object (Session, represents the user logging in) that calls the Login screen (LoginGUI, a Swing JFrame object with various components). Session uses setters in LoginGUI to set the labels, initial field entries etc, before enabling the screen. From this point, the user will do something with the LoginGUI screen - could be closing the window, entering a mix of userid and password, or maybe specifying a locale. Once the user has taken the action, if required, the session object can use getters to retrieve the userid and password values entered in the fields.
    The crux of the problem is 1) how will Session know that an action has been taken on the LoginGUI, and 2) how to tell what action has been taken.
    This could be solved by getting LoginGUI to call back to Session, however, I am trying to buid the application with a good separation of business, logic and presentation (i.e MVC, but not using any specific model). Therefore, I do not want LoginGUI to contain any program flow logic - that should all be contained in Session.
    I am aware of two possible ways to do this:
    1. Make LoginGUI synchronised, so that Session waits for LoginGUI to send a NotifyAll(). LoginGUI could hold a variable indicating what has happened which Session could interrogate.
    2. Implement Window Listener on Session so that it gets informed of the Window Close action. For the other two actions I could use a PropertyChangeListener in Session, that is notified when some variable in LoginGUI is changed. This variable could contain the action performed.
    Has anyone got any comments on the merits of these methods, or perhaps a better method? This technique seems fundamental to any application that interfaces with end-users, so I would like to find the best way.
    Thanks in advance.

    Hi,
    I tried to avoid putting in specific code as my question was more on design, and I wanted to save people having to trawl through specific code. And if I had any school assignments outstanding they would be about 20 years too late :-). I'm not sure computers more sophisticated than an abacus were around then...
    Rather than putting the actual code (which is long and refers to other objects not relevant to the discussion), I have put together two demo classes to illustrate my query. Comments in the code indicate where I have left out non-relevant code.
    Sessiondemo has the main class. When run, it creates an instance of LoginGUIdemo, containing a userid field, password field, a ComboBox (which would normally have a list of available locales), an Enter and a Cancel box.
    When the Locale combo box is clicked, the LoginGUIdemo.userAction button is changed (using an ActionListener) and a property change is fired to Session (which could then perform some work). The same technique is used to detect Enter events (pressing return in password and userid, or clicking on Enter), and to detect Cancel events (clicking on the cancel button). Instead of putting in business code I have just put in System.out.printlns to print the userAction value.
    With this structure, LoginGUIdemo has no business logic, but just alerts Sessiondemo (the class with the business logic).
    Do you know any more elegant way to achieve this function? In my original post, I mentioned that I have also achieved this using thread synchronisation (Sessiondemo waits on LoginGUI to issue a NotifyAll() before it can retrieve the LoginGUI values). I can put together demo code if you would like. Can you post any other demo code to demonstrate a better technique?
    Cheers,
    Alan
    Here's Sessiondemo.class
    import java.io.*;
    import java.awt.event.*;
    import java.util.*;
    import java.beans.*;
    public class Sessiondemo implements PropertyChangeListener {
        private LoginGUIdemo lgui;   // Login screen
        private int localeIndex; // index referring to an array of available Locales
        public Sessiondemo () {
            lgui = new LoginGUIdemo();
            lgui.addPropertyChangeListener(this);
            lgui.show();
        public static void main(String[] args) {
            Sessiondemo sess = new Sessiondemo();
        public void propertyChange(java.beans.PropertyChangeEvent pce) {
            // Get the userAction value from LoginGUI
            String userAction = pce.getNewValue().toString();
            if (userAction == "Cancelled") {
                System.out.println(userAction);
                // close the screen down
                lgui.dispose();
                System.exit(0);
            } else if (userAction == "LocaleChange") {
                System.out.println(userAction);
                // Get the new locale setting from the LoginGUI
                // ...modify LoginGUI labels with new labels from ResourceBundle
    lgui.show();
    } else if (userAction == "Submitted") {
    System.out.println(userAction);
    // ...Get the userid and password values from LoginGUIdemo
                // run some business logic to decide whether to show the login screen again
                // or accept the login and present the application frontscreen
    }And here's LoginGUIdemo.class
    * LoginGUIdemox.java
    * Created on 29 November 2002, 18:59
    * @author  administrator
    import java.beans.*;
    public class LoginGUIdemo extends javax.swing.JFrame {
        private String userAction;
        private PropertyChangeSupport pcs;
        /** Creates new form LoginGUIdemox */
        // Note that in the full code there are setters and getters to allow access to the
        // components in the screen. For clarity they are not included here
        public LoginGUIdemo() {
            pcs = new PropertyChangeSupport(this);
            userAction = "";
            initComponents();
        public void setUserAction(String s) {
            userAction = s;
            pcs.firePropertyChange("userAction",null,userAction);
        public void addPropertyChangeListener(PropertyChangeListener l) {
            pcs.addPropertyChangeListener(l);
        public void removePropertyChangeListener(PropertyChangeListener l) {
            pcs.removePropertyChangeListener(l);
        /** This method is called from within the constructor to
         * initialize the form.
         * WARNING: Do NOT modify this code. The content of this method is
         * always regenerated by the Form Editor.
        private void initComponents() {
            jTextField1 = new javax.swing.JTextField();
            jTextField2 = new javax.swing.JTextField();
            jComboBox1 = new javax.swing.JComboBox();
            jButton1 = new javax.swing.JButton();
            jButton2 = new javax.swing.JButton();
            getContentPane().setLayout(new java.awt.FlowLayout());
            addWindowListener(new java.awt.event.WindowAdapter() {
                public void windowClosing(java.awt.event.WindowEvent evt) {
                    exitForm(evt);
            jTextField1.setText("userid");
            jTextField1.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    EnterActionPerformed(evt);
            getContentPane().add(jTextField1);
            jTextField2.setText("password");
            jTextField2.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    EnterActionPerformed(evt);
            getContentPane().add(jTextField2);
            jComboBox1.setToolTipText("Select Locale");
            jComboBox1.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    LocaleActionPerformed(evt);
            getContentPane().add(jComboBox1);
            jButton1.setText("Enter");
            jButton1.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    EnterActionPerformed(evt);
            getContentPane().add(jButton1);
            jButton2.setText("Cancel");
            jButton2.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    CancelActionPerformed(evt);
            getContentPane().add(jButton2);
            pack();
        private void LocaleActionPerformed(java.awt.event.ActionEvent evt) {
            setUserAction("LocaleChange");
        private void CancelActionPerformed(java.awt.event.ActionEvent evt) {
            setUserAction("Cancelled");
        private void EnterActionPerformed(java.awt.event.ActionEvent evt) {
            setUserAction("Submitted");
        /** Exit the Application */
        private void exitForm(java.awt.event.WindowEvent evt) {
            System.exit(0);
         * @param args the command line arguments
        public static void main(String args[]) {
            new LoginGUIdemo().show();
        // Variables declaration - do not modify
        private javax.swing.JTextField jTextField2;
        private javax.swing.JTextField jTextField1;
        private javax.swing.JComboBox jComboBox1;
        private javax.swing.JButton jButton2;
        private javax.swing.JButton jButton1;
        // End of variables declaration

  • Best way to create a GUI questionaire

    Hello everyone
    What is the best way to go about building a GUI based questionnaire? with questions and line for the answers.?
    Thanks for the answers.

    What a fantastically vague question.
    Have you considered handing out sheets of paper and ballpoint pens? :o)
    You could do a simple questionnaire in HTML.
    Form layouts in Java are probably best done in TableLayout (third party, free, see Google)
    But to answer your question directly, undoubtedly the best way to build it is to do so in a comfy chair with a nice view, listening to some Senser or perhaps Orbital, whilst consuming a decent bottle of Gigondas.

  • Best way to create a GUI (long)

    Really not sure what I should be doing as far as GUI's are concerned, and the more I research, the more confused I get.
    So far I have been using swing, with some awt thrown in, which doesn't seem too bad. Thing is that many people have mentioned better alternitatives, a few of which I have downloading right now. One concern I have is that if I learn a 3rd party api, it could stop being supported and could be hard to find docs; plus if I am going for a job, they probably wouln't care I have mastered Bob's leet toolkit, even if it really is the best thing out there.
    Then again I could not learn an api at all, really not against a visual editor but think netbeans is the only free one, and I have never done it, and netbeans 4 wouln't run on my comp. Eclipse only does swt which seems only useful for apps, and I want this almost as much for applets as applications. Could check out JBuilder but I'm not sure what language it's based on (guessing swing?) Always loved Borland as a company so could see that as a way to go but that starts to get into money.
    Then there's other weird things, like liveconnect and doing everything in html... and flash ???...
    I definatly have a lot of research to do but hoping you guys could fill me in on what you use, have used, liked, disliked, ect. Maybe give me some kind of starting point, as well as see what everyones using. Interested to in those coming from the business end, what are employers / teams wanting?
    Thanks,
    Tibberous

    So far I have been using swing, with some awt thrown
    in, which doesn't seem too bad.Swing and AWT don't mix. Evil.
    Thing is that many
    people have mentioned better alternitatives, a few of
    which I have downloading right now. One concern I
    have is that if I learn a 3rd party api, it could
    stop being supported and could be hard to find docs;Then don't, or at least go with the more common ones like SWT.
    plus if I am going for a job, they probably wouln't
    care I have mastered Bob's leet toolkit, even if it
    really is the best thing out there.1) A prorammer should be able to work his way through any good API
    2) Once again, stick with the few common APIs: Swing, AWT (if you have to) and SWT. I be that's what most companies use, and you're not limited to learning only one API.
    3) Knowing APIs is one thing, knowing ergonomy a completely different one. You can build crap GUIs with any API; if you want to use your GUI-creating skills for your resume, you better learn that, too.
    Then again I could not learn an api at all, really
    not against a visual editor but think netbeans is theVisual editors are crap. You'lkl never be able to maintain their clumsy autogenerated code.
    Then there's other weird things, like liveconnect and
    doing everything in html... and flash ???...Yes?
    I definatly have a lot of research to do but hoping
    you guys could fill me in on what you use, have used,
    liked, disliked, ect. I think no software project ever cared about what I like. I used GUIs according to their needs - if the customer wanted a web frontend, he got JSPs. If he wanted applets, he got Swing. Plus my apps have the GUI clearly separated from the business logic, so that any GUI is easily replacable by another one.
    Maybe give me some kind of
    starting point, as well as see what everyones using.
    Interested to in those coming from the business end,
    what are employers / teams wanting?They usually don't want anything. The customer wants.

  • Best way to update GUI

    Hi, I have a 'business model' class which holds all my variables that are displayed on my GUI which is a seperate class. As these variables change quite frequently while running the program I need some advise on the best way to update my GUI as need be. I'm using a controller with actionListeners to deal with changes going in the opposite direction. So can I manipulate this approach to suit my needs or should I implement Observable which I've read somewhere else?

    user8844058 wrote:
    Yea that sounds viable to me too DrClap I just can't seem to find any examples of it in action! Would you use events in a non GUI class to achieve this?A bit late - NY time here.
    Example:
    1. User enters data on a GUI;
    2. A button is hit on the GUI and some data is taken as user entries and sent to the contoller;
    3. The controller uses that data and acts as a dispatcher to act on what is requested by calling whatever business logic is required, and the model gets populated appropriately;
    4. Once the model is populated the relevant results are returned to the GUI;
    5. The GUI now represents the results of that population.
    I realize you marked your question as answered, but was, or is your question: "how does (or what is the best or most oftenly used way that) the GUI (view) gets, or knows to get the results of the request?"
    Edited by: abillconsl on Apr 13, 2011 12:42 PM

  • Best way to load messages - properties file or database?

    Hi Guys,
    I have a debate with my colleague about best way to load/keep GUI messages.
    As we known, all those messages are in properties file, web tier will handle the messages loading to GUI.
    However, my colleague suggested, we could save all the messages in a database table, when application starts up, it will load all the messages from database.
    Please help me figure out pros/cons for both ways? What's the best to deal with message loading?
    Thanks

    allemande wrote:
    Please help me figure out pros/cons for both ways?There is no big difference with regard to performance and memory use. Both are after all cached in memory at any way. I wouldn't worry about it.
    The biggest difference is in the maintainability and reusability. Propertiesfiles are just textbased files. You can just edit the messages using any text editor. It is only a bit harder to wrap it in a UI like thing, but you can achieve a lot using java.util.Properties API with its load() and store() methods. Another concern is that it cannot be used anymore if you switch from platform language (e.g. Java --> C# or so) without writing some custom tool to read Java style properties files at any way. Databases, on the other hand, require SQL knowledge or some UI tool to edit the contents. So you have to create a UI like thing at any way if you want to let someone with less knowledge edit the messages. This is more time consuming. But it can universally be used by any application/platform by just using SQL standard.

  • Best way to make a rusultset available for ...

    processing?
    If I have a method that returns a resultset and in my jsp I do this:
    String strSQL = "SELECT * FROM someTable WHERE field = '"+someValue+"'";
    methodsClass mc = new methodsClass();
    ResultSet objRS = getRS(strSQL);
    //If I know that the objRS will only return 1 record, what is the best
    //way to initialize the objRS?
    while(objRS.next()){.....}
    //OR
    if(!objRS.last()){....}
    //OR Some other way?
    //Or does it really matter??TIA!!

    if(objRS.first()) {
    ... // set to first element (if exists)

  • Displaying Multiple Values on GUI components - best way to implement

    Hi,
    my program needs to implement a basic function that most commercial programs use very widely: If the program requires that a GUI component (say a JTextField) needs to display multiple values it either goes <blank> or say something more meaningfull like "multiple values". What is the best way of implementing it?
    In particular:
    My data is a class called "Student" that among other things has a field for the student name, like: protected String name; and the usual accessor methods (getName, setName) for it.
    Assuming that the above data (i.e. Student objects) is stored in a ListModel and the user can select multiple "Students", if a JTextField is required to display the user selection (blank for multiple selections, or the student "name" for a single selection), what is the best (OO) way of implementing it? Is there any design pattern (best practice) for this basic piece of functionality? A crude way is to have the JTextField check and compare all the time the user selections one by one, but I'm sure there must be a more OO/better approach.
    Any ideas much appreciated.
    Kyri.

    Ok, I will focus on building a solution on 12c.
    right now I have used a USER_DATASTORE with a procedure to glue all the field together in one document.
    This works fine for the search.
    I have created a dummy table on which the index is created and also has an extra field which contains the key related to all the tables.
    So, I have the following tables:
    dummy_search
    contracts
    contract_ref
    person_data
    nac_data
    and some other tables...
    the current design is:
    the index is on dummy_search.
    When we update contracts table a trigger will update dummy_search.
    same configuration for the other tables.
    Now we see locking issues when having a lot of updates on these tables as the same time.
    What is you advice for this situation?
    Thanks,
    Edward

  • What is the best way to create shared variable for multiple PXI(Real-Time) to GUI PC?

    What is the best way to create shared variable for multiple Real time (PXI) to GUI PC? I have 16 Nos of PXI system in network and 1 nos of GUI PC. I want to send command to all the PXI system with using single variable from GUI PC(Like Start Data acquisition, Stop data Acquisition) and I also want data from each PXI system to GUI PC display purpose. Can anybody suggest me best performance system configuration. Where to create variable?(Host PC or at  individual PXI system).

    Dear Ravens,
    I want to control real-time application from host(Command from GUI PC to PXI).Host PC should have access to all 16 sets PXI's variable. During communication failure with PXI, Host will stop data display for particular station.
    Ravens Fan wrote:
    Either.  For the best performance, you need to determine what that means.  Is it more important for each PXI machine to have access to the shared variable, or for the host PC to have access to all 16 sets of variables?  If you have slowdown or issue with the network communication, what kinds of problems would it cause for each machine?
    You want to located the shared variable library on whatever machine is more critical.  That is probably each PXI machine, but only you know your application.
    Ravens Fan wrote:
    Either.  For the best performance, you need to determine what that means.  Is it more important for each PXI machine to have access to the shared variable, or for the host PC to have access to all 16 sets of variables?  If you have slowdown or issue with the network communication, what kinds of problems would it cause for each machine?
    You want to located the shared variable library on whatever machine is more critical.  That is probably each PXI machine, but only you know your application.

  • Best Way to Handle Dynamic Initialization of x number of Objects?

    I want to be able to take a x value(integer) that I get from another part of my program and initialize x number of Objects. Best way to handle that?

    myObject[] myObjArray = new myObject[x];
    for (int i=0; i<x; i++) myObjArray[i] = new myObject("obj#"+i);

  • What is the best way to get another object's method to update my GUI?

    package stuff;
    import java.awt.event.*;
    import javax.swing.*;
    import java.awt.*;
    public class Test extends JFrame{
      private static JButton ProcessButton = new JButton();
      private static JLabel jLabel2 = new JLabel();
      public static void main( String args []){
         Test f = new Test();
         f.setSize(500,500);
         Container c = f.getContentPane();
         ProcessButton.addActionListener( new ActionListener(){
                                     public void actionPerformed(ActionEvent e) {
                                        jLabel2.setText("Connecting to DB");
                                        //Connection connection = Tools.setUpConnectionToDB(url,userName,pwd);
         c.add(ProcessButton, BorderLayout.NORTH);
         jLabel2.setText("My Label");
         c.add(jLabel2, BorderLayout.SOUTH);
         f.setVisible(true);
    {\code]
    The method setUpConnectionToDB can take 1 - 10 mins to complete. By this time a user will prob have quit my app thinking
    it's crashed because it doesn't update the GUI with a progress status. :(
    What is the best way to get this method to update the GUI of the app which calls it?
    Something like  Connection connection = Tools.setUpConnectionToDB(url,userName,pwd, this);
    ie this being a reference to the GUI's JFrame is what I'm trying to use?

    A handy class to know about but not really what I'm after.
    I need the method call
    Tools.setUpConnectionToDB(url,userName,pwd);
    to be able to update a component ( The JLabel ) on the GUI
    Connection connection = Tools.setUpConnectionToDB(url,userName,pwd, this);
    [\code]
    method defn:public static Connection setUpConnectionToDB( String url, String user, String pwd, JFrame f ){
    //Why doesn't this code below modify the GUI on the calling App?
    f.jLabel2.setText("Setting UP DB Connection");
    f.repaint();
    Connection c = null;
    try{
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    c = DriverManager.getConnection(url,user,pwd);
    catch(ClassNotFoundException e){
    JOptionPane.showMessageDialog(null , "Error loading DB driver");
    System.exit(0);
    catch(Exception e){
    JOptionPane.showMessageDialog(null , "Error connecting to DB, check config file");
    System.exit(0);
    return c;
    }[\code]

  • Best way to implement tree like subcategory chooser in GUI on iphone

    I need to let user choose subcategory, from a tree like structure, 3-4 level deep.
    and the list is veeeery long. I was wondering what would be the best way to show it to user, and let him choose one.
    ideas ?

    The right solution here is probably a set of UITableViewController subclasses inside a UINavigationController that your application presents modally. If the lists are long even within a level, sort and group them alphabetically and present an index list along the side, the way Contacts does. You should be able to do all this with just a few UITableViewDelegate/DataSource methods.

  • Best way to keep a JList in gui and a list in domain synchronized ?

    Hi I would like to know what the best way would be to keep a JList displaying the exact sequence and contents of items contained in a list in the domain (an arrayList in this case)
    at the moment I have an adapter class wrapping around an ArrayList in order to make it into a ListModel which I use in the construction of my JList. ythe JList only knows this model trough the package interface. I was wondering is this the way to go or not ? if not do you have a good example of how to do it the right way ?
    thanks in advance.
    Boran.

    OMG I've wasted my life! :) Thanks man!
    Although, now I don't understand why there's no some kind of JavaBeanListProperty - when clearly there's a mechanism for handling this kind of stuff...

  • Best way to run open source/GNU programs on Mac

    Hi folks,
    I'm kind of new to Macs, coming from the linux/unix world.   I'm working on reinstalling the OS on my macbook (after finding out the hard way that it itsn't prudent to use a case-sensitive file system on a Mac), and thought this would be a good time to ask if anyone has an opinion on the best way to run linux-y programs on a Mac.   For instance, I find myself wanting to use "zim" and keep it synchronized with my linux computers, but I can't get it to install on my mac.   I can see a few options:
    1) run linux in a virtual machine, but this is a problem since I only have 4 GB of memory.
    2) use mac ports, but most of the ports I tried in the past didn't work, and my questions to the community were ignored (I tried to be friendly, but perhaps I came across wrong...?)
    3) use fink, but I gather it is out of date and not really used any more.
    So, I'm curious what other people use if they want to use open source programs?   Ideally I wouldn't have to compile each program myself, but maybe that is the best option?
    Thanks.

    I think Fink has install binaries (and if it has a ZIM port that works for you, what do you care if Fink is a bit out-of-date as a package manager?).
    From my observations of MacPorts.com, it compiles the ported package on your system (so you need to have XCode (free from Mac App Store) installed on your system.  If MacPorts has a binary option, I have not dug deep enough to find it (as I mostly use the minimum to get something I want installed).
    The other option is to download the Open Source package and build it yourself.  There are some that think this is the ONLY way to go about it (me I'm lazy and only do that for Vim which I desire specific options not always included in canned Vim packages).
    If you want OpenZIM on your Mac and you only use it once in a while, then a virtual machine might be the way to go.  However, if your use of OpenZIM is extensive, then a virtual machine can be a bit heavy weight, adn for that you might want to either find a working port or build it yourself.
    Whatever you do, DO NOT replace a standard Mac OS X installed Unix side program with your own.  Put your stuff in /usr/local/bin, or a personal local tree (Fink uses /sw/... and MacPorts uses /opt/local/...), then modify PATH in your shell initialization file.  Replacing standard Mac OS X Unix programs may break Mac OS X maintenance scripts, GUI programs that get an assist from a Unix command, etc...
    NOTE:  Chances are you Mac can go up to at least 8GB of RAM, and if you look at Crucial.com you might find it will not cost you much at all (for example, the MacBook Pro I just got was upgraded from 4GB to 8GB for only $43).  With 8GB of RAM you will not notice that you have a virtual machine locking down 2GB.  Also I'm not telling you to spend money, just pointing out possible options should you find your need for OpenZIM demands the use of a virtual machine.
    With respect to a case sensitive file syste, if you need one, then create a partition (or perhaps a disk image (.dmg) via Applications -> Utilities -> Disk Utility) for that purpose (an external disk is also an option).  But as you have discovered Mac OS X and many of its GUI applications have assumptions based on a case-insensitive file system.

  • Best way to access variables from actionCommand

    Say I have a method which reads some data from a file, then stores it in a string. I have a button in this method with an ActionListener defined as follows:
                    btnOk.addActionListener(new ActionListener() {
                       public void actionPerformed(ActionEvent e) {
                           otherMethod();
                    });Now I need to pass the value of my string to this other method. What's the best way of doing this? Currently I have it declared at the top of the class but it seems a bit messy. I know I could declare the string final, but I need to set it conditionally depending on another variable, so I'd need to declare it before I initialize it's value. If it's declared final this won't work. Is the method I'm using now the usual way of doing this?

    Echilon wrote:
    Say I have a method which reads some data from a file, then stores it in a string. I have a button in this method with an ActionListener defined as follows:It's not great practice for a GUI event listener to call something that does file I/O. It'll lead to a sluggish interface, since I/O is slow.
    A better solution is to invoke code that will cause the I/O to happen in a different thread. I think that Swing actually has built-in support for that, but I don't use Swing much so I don't know.
    Now I need to pass the value of my string to this other method. What's the best way of doing this? Currently I have it declared at the top of the class but it seems a bit messy. I know I could declare the string final, but I need to set it conditionally depending on another variable, so I'd need to declare it before I initialize it's value.That doesn't necessarily mean that you can't declare it final. Final just means that once you assign it, you can't change it. You can still set its initial value conditionally.
    I agree that it's messy to use fields for no other purpose than to pass values between methods.

Maybe you are looking for

  • Residual items configuration

    In partial clearing (F-32) we have an original invoice, a part payment and a residual clearing. How can I set the system up, to copy text line (sgtxt) from original item to residual item and document date (bldat) to its header? regards, Piot

  • How to resolve this errors.

    hello, I'm new to use mac os x server. then following error message repeats, but I dont know hou to resolve. com.apple.launchd[1] (com.apple.NotificationServer[738]): Exited with code: 1 com.apple.launchd[1] (com.apple.NotificationServer): Throttling

  • Differences between Production Processes

    Dear All, I am new to this community and i want to know configuration differences between repetitive production process and Discreet Production Process with reference to Product Costing. It is highley appreciated, if any document explains the above i

  • ThinkVanta​ge system not working

    Hi. I have problem with my Thinkvantage sytem. When the computer is started and i press blue boton before booting the lenovo system is not working. I can't see R&R software, however in Win xp R&R is working. I try update the thinkvantage system but s

  • Why is there no Set-AzureStorageFile?

    Hi, I want to upload files from my PC to an Azure VM using Azure PowerShell. I have found the Get-AzureStorageFile command, but there's no Set-AzureStorageFile. It is not clear to me, how to upload a local file to an Azure VM. Is this possible or are