Results 1 to 8 of 8
  1. #1
    goldsweg is offline Member
    Join Date
    Dec 2014
    Posts
    2
    Rep Power
    0

    Default Design Function in Java

    So recently I created a currency converter in Java. The GUI was completely done using the design function. I closed the design function and I am wondering if there's anyway to edit the GUI after this, because the code that the design function outputs is definitely odd. Here's the GUI code. I am using NetBeans 8.0 as well.
    Java Code:
    public HorizontalView() {
            
            initComponents();
        }
        @SuppressWarnings("unchecked")                      
        private void initComponents() {
        
            PBactionListener ButtonListener = new PBactionListener();       
            jTextField1 = new javax.swing.JTextField();
            jComboBox1 = new javax.swing.JComboBox();
            jLabel1 = new javax.swing.JLabel();
            jComboBox2 = new javax.swing.JComboBox();
            jButton1 = new javax.swing.JButton();
            jButton1.addActionListener(ButtonListener);
            jTextField2 = new javax.swing.JTextField();
            jTextField3 = new javax.swing.JTextField();
            setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
            jTextField1.setFont(new java.awt.Font("Arial", 0, 18));
            jTextField1.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
            jTextField1.setText("1");
            jTextField1.addActionListener(new java.awt.event.ActionListener()
            {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    jTextField1ActionPerformed(evt);
                }
            });
            jComboBox1.setFont(new java.awt.Font("Arial", 0, 18)); // NOI18N
                for (int x = 0; x<148; x++) {jComboBox1.addItem(StringArray[x]);}
            jLabel1.setFont(new java.awt.Font("Arial", 1, 18)); // NOI18N
            jLabel1.setText("Converts to:");
    
            
            jComboBox2.setFont(new java.awt.Font("Arial", 0, 18)); // NOI18N
                for (int x = 0; x<148; x++) {jComboBox2.addItem(String1Array[x]);}
            jButton1.setFont(new java.awt.Font("Arial", 1, 18)); // NOI18N
            jButton1.setText("Convert");
    
            jTextField2.setEditable(false);
            jTextField2.setFont(new java.awt.Font("Arial", 1, 24)); // NOI18N
            jTextField2.setText("Amount...");
            
            jTextField3.setEditable(false);
            jTextField3.setFont(new java.awt.Font("Arial", 1, 24)); // NOI18N
            jTextField3.setText("$$$p00nz!");
    
            javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
            getContentPane().setLayout(layout);
            layout.setHorizontalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                    .addContainerGap()
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                        .addGroup(layout.createSequentialGroup()
                            .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 164, javax.swing.GroupLayout.PREFERRED_SIZE)
                            
                            .addComponent(jComboBox1, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addGroup(layout.createSequentialGroup()
                            .addComponent(jLabel1)
                            
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addGroup(layout.createSequentialGroup()
                                    .addComponent(jComboBox2, javax.swing.GroupLayout.PREFERRED_SIZE, 298, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                    .addComponent(jButton1)
                                    .addGap(0, 0, Short.MAX_VALUE))
                                .addComponent(jTextField2))))
                    .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
            );
            layout.setVerticalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                    .addContainerGap()
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jComboBox2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jLabel1)
                        .addComponent(jButton1))
                   
                    .addComponent(jTextField2, javax.swing.GroupLayout.DEFAULT_SIZE, 89, Short.MAX_VALUE)
                    .addContainerGap())
            );
            pack();
        }        
    
        private void jTextField1ActionPerformed(java.awt.event.ActionEvent evt) {                                            
        }                                           
    
        public static void main(String args[]) {
            try {
                for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                    if ("Nimbus".equals(info.getName())) {
                        javax.swing.UIManager.setLookAndFeel(info.getClassName());
                        break;
                    }
                }
            } catch (ClassNotFoundException ex) {
                java.util.logging.Logger.getLogger(HorizontalView.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
            } catch (InstantiationException ex) {
                java.util.logging.Logger.getLogger(HorizontalView.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
            } catch (IllegalAccessException ex) {
                java.util.logging.Logger.getLogger(HorizontalView.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
            } catch (javax.swing.UnsupportedLookAndFeelException ex) {
                java.util.logging.Logger.getLogger(HorizontalView.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
            }
            java.awt.EventQueue.invokeLater(new Runnable() {
                public void run() {
                    new HorizontalView().setVisible(true);
                }
            });
        }
    
        private javax.swing.JButton jButton1;
        private javax.swing.JComboBox jComboBox1;
        private javax.swing.JComboBox jComboBox2;
        private javax.swing.JLabel jLabel1;
        private javax.swing.JLabel jLabel2;
        private javax.swing.JTextField jTextField1;
        private javax.swing.JTextField jTextField2;
        private javax.swing.JTextField jTextField3;
    Last edited by goldsweg; 12-05-2014 at 12:08 AM.

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,001
    Rep Power
    33

    Default Re: Design Function in Java

    Please edit your post and wrap your code with code tags:
    [code]
    YOUR CODE GOES HERE
    [/code]
    to get highlighting and preserve formatting.

    if there's anyway to edit the GUI after this,
    Not easily.
    If you don't understand my response, don't ignore it, ask a question.

  3. #3
    goldsweg is offline Member
    Join Date
    Dec 2014
    Posts
    2
    Rep Power
    0

    Default Re: Design Function in Java

    I understand it wouldn't be easy. Is it possible though? The only other option is redoing the entire GUI manually.

  4. #4
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    6,226
    Rep Power
    13

    Default Re: Design Function in Java

    Quote Originally Posted by goldsweg View Post
    I understand it wouldn't be easy. Is it possible though? The only other option is redoing the entire GUI manually.
    Yes, its possible. But I wouldn't want to do it. Doing manual layouts is the way to go and it would help you understand more about the generated code above. That is what most on this forum would have recommended if you said you were using a visual designer.

    Regards,
    Jim
    Last edited by jim829; 12-05-2014 at 03:42 PM. Reason: typo
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  5. #5
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,717
    Rep Power
    17

    Default Re: Design Function in Java

    the code that the design function outputs is definitely odd
    You are too polite!

    The good news is that the code is brief enough for you to digest a reasonable Swing tutorial and redo it by hand. There's plenty to be learnt, and plenty of knowledge people here to help you.

  6. #6
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    5,114
    Rep Power
    12

    Default Re: Design Function in Java

    Quote Originally Posted by goldsweg View Post
    The only other option is redoing the entire GUI manually.
    That is indeed the only true option. GUI designers are decent for prototyping / design document purposes, but the last thing you want is to have generated code in your project.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  7. #7
    SurfMan's Avatar
    SurfMan is offline Godlike
    Join Date
    Nov 2012
    Location
    The Netherlands
    Posts
    1,991
    Rep Power
    8

    Default Re: Design Function in Java

    +100 for coding layouts by hand. At first it seems cumbersome and complicated, but once you know how to work with different LayoutManagers, you'll be fine.

    Shameless plug: I have started using MigLayout a few years ago, and I have never looked back at any other LayoutManager, besides the occasional BorderLayout and GridLayout.
    "It's not fixed until you stop calling the problem weird and you understand what was wrong." - gimbal2 2013

  8. #8
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    5,114
    Rep Power
    12

    Default Re: Design Function in Java

    Better MigLayout than GridbagLayout, that's for sure.

    For form-like dialogs I tend to use SpringLayout combined with the SwingUtilities class you can find in the Swing tutorial to easily create a nice grid-form layout.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

Similar Threads

  1. Replies: 0
    Last Post: 12-31-2012, 03:24 PM
  2. Replies: 0
    Last Post: 04-06-2012, 08:24 PM
  3. Replies: 0
    Last Post: 03-24-2012, 04:22 AM
  4. Design :Java API
    By sm123 in forum New To Java
    Replies: 0
    Last Post: 06-18-2010, 02:13 PM
  5. Replies: 3
    Last Post: 12-04-2009, 03:08 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •