Results 1 to 3 of 3
  1. #1
    turbowhat is offline Member
    Join Date
    Feb 2011
    Posts
    3
    Rep Power
    0

    Default look @ code and give ideas! Install new code....

    I apologize up front, I don't really know how to ask this question, I'm trying to add more cards to a CardGUI, they are all created and ready to use but the original code won't let me modify it so I can install my new cards..........I think I have the code right, but wow, I'm overwhelmed. Green at this Java stuff, this is my first semester.....and its kicking my butt..........Any help would be appreciated. Thank you in advance.

    ***oh the bold/italicized code is what I've tried to add............sorry its so dang long..........

    Java Code:
    /*
     * CardGUI.java
     */
    package cards;
    
    import javax.swing.JOptionPane;
    
    
    public class CardGUI extends javax.swing.JApplet {
    
           
        private GCard gCard = null;
    
        /** Initializes the applet CardGUI */
        public void init() {
            try {
                java.awt.EventQueue.invokeAndWait(new Runnable() {
    
                    public void run() {
                        initComponents();
                    }
                });
            } catch (Exception ex) {
                ex.printStackTrace();
            }
        }
    
    
    ////////////////////////////////PROBLEM////////////////////////////////////
    
        /** This method is called from within the init() method to
         * initialize the form.
         * WARNING: Do NOT modify this code. The content of this method is
         * always regenerated by the Form Editor.
         */
        @SuppressWarnings("unchecked")
        // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
        private void initComponents() {
    
            btgCards = new javax.swing.ButtonGroup();
            btnBirthday = new javax.swing.JRadioButton();
            btnGeneral = new javax.swing.JRadioButton();
            btnValentines = new javax.swing.JRadioButton();
            btnCreate = new javax.swing.JButton();
            jTextField1 = new javax.swing.JTextField();
            txtTo = new javax.swing.JTextField();
            txtFrom = new javax.swing.JTextField();
            jLabel1 = new javax.swing.JLabel();
            jLabel2 = new javax.swing.JLabel();
    
            btgCards.add(btnBirthday);
            btnBirthday.setText("Birthday");
    
            btgCards.add(btnGeneral);
            btnGeneral.setText("General Card (Enter Message)");
    
            btgCards.add(btnValentines);
            btnValentines.setText("Valentines");
    
            btnCreate.setText("Create a Card");
            btnCreate.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    btnCreateActionPerformed(evt);
                }
            });
    
            jTextField1.setBackground(new java.awt.Color(204, 204, 0));
            jTextField1.setEditable(false);
            jTextField1.setHorizontalAlignment(javax.swing.JTextField.CENTER);
            jTextField1.setText("Card Maker");
    
            jLabel1.setText("To:");
    
            jLabel2.setText("From:");
    
            org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
            getContentPane().setLayout(layout);
            layout.setHorizontalGroup(
                layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                .add(layout.createSequentialGroup()
                    .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                        .add(layout.createSequentialGroup()
                            .add(51, 51, 51)
                            .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                                .add(btnGeneral)
                                .add(layout.createSequentialGroup()
                                    .add(btnValentines)
                                    .add(61, 61, 61)
                                    .add(btnCreate))
                                .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
                                    .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                                        .add(layout.createSequentialGroup()
                                            .add(btnBirthday)
                                            .add(49, 49, 49)
                                            .add(jLabel2))
                                        .add(jLabel1))
                                    .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                                    .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                                        .add(txtFrom, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 93, Short.MAX_VALUE)
                                        .add(txtTo, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 93, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))))
                        .add(layout.createSequentialGroup()
                            .add(63, 63, 63)
                            .add(jTextField1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 221, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
                    .addContainerGap(80, Short.MAX_VALUE))
            );
            layout.setVerticalGroup(
                layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                .add(layout.createSequentialGroup()
                    .add(26, 26, 26)
                    .add(jTextField1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                    .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                        .add(layout.createSequentialGroup()
                            .add(jLabel1)
                            .add(3, 3, 3)
                            .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                                .add(layout.createSequentialGroup()
                                    .add(btnBirthday)
                                    .add(29, 29, 29))
                                .add(layout.createSequentialGroup()
                                    .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                                        .add(jLabel2)
                                        .add(txtFrom, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                                    .add(18, 18, 18))))
                        .add(txtTo, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                    .add(21, 21, 21)
                    .add(btnGeneral)
                    .add(32, 32, 32)
                    .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                        .add(btnValentines)
                        .add(btnCreate))
                    .addContainerGap(70, Short.MAX_VALUE))
            );
        }// </editor-fold>                        
    
    /////////////////////////////////////PROBLEM END//////////////////////////////
    
    ////////////////////////////////////////NEW CODE////////////////////////////////    
    [B][I] /**
     * New written code for button instantiation
     * 
     */
        /*
        private void initComp() {
         btnHalloween = new javax.swing.JRadioButton();
         btnChristmas = new javax.swing.JRadioButton();
         btnGraduation = new javax.swing.JRadioButton();
         btnBaby = new javax.swing.JRadioButton();
         btnMarriage = new javax.swing.JRadioButton();
         btnDivorce = new javax.swing.JRadioButton();
    
         btgCards.add(btnHalloween);
            btnHalloween.setText("Halloween");
            btgCards.add(btnChristmas);
            btnChristmas.setText("Christmas");
            btgCards.add(btnGraduation);
            btnGraduation.setText("Graduation");
            btgCards.add(btnBaby);
            btnBaby.setText("Baby");
            btgCards.add(btnMarriage);
            btnMarriage.setText("Marriage");
            btgCards.add(btnDivorce);
            btnDivorce.setText("Divorce");
        }
        
        
    add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                                .add(btnHalloween)
                                .add(layout.createSequentialGroup()
                                    .add(btnChristmas)
                                    .add(61, 61, 61)
                                    .add(btnGraduation)
                                    .add(btnBaby)
                                    .add(btnMarriage)
                                    .add(btnDivorce));
       */ [/I][/B]                            
    
    /////////////////////////////////////END NEW CODE///////////////////////                                
                                    
                                    
                                    
    
        private void btnCreateActionPerformed(java.awt.event.ActionEvent evt) {                                          
            if (btnBirthday.isSelected()) { //Look to see if the radio button selected
                gCard = new Birthday(txtTo.getText(), txtFrom.getText());
                //Create a birthday card. A  birthday Card is-a general card.
            } else if (btnGeneral.isSelected()) {
                gCard = new GCard(txtTo.getText(), txtFrom.getText());
                //Create a general card.
            } else if (btnValentines.isSelected()) {
                gCard = new Valentines(txtTo.getText(), txtFrom.getText());
                //Create a valentines card.
            } else if (btnHalloween.isSelected()) {
                gCard = new Halloween(txtTo.getText(), txtFrom.getText());
                //Create a Halloween card.
            } else if (btnChristmas.isSelected()) {
                gCard = new Christmas(txtTo.getText(), txtFrom.getText());
                //Create a Christmas card.
            } else if (btnGraduation.isSelected()) {
                gCard = new Graduation(txtTo.getText(), txtFrom.getText());
                //Create a Graduation card.
            } else if (btnBaby.isSelected()) {
                gCard = new Baby(txtTo.getText(), txtFrom.getText());
                //Create a Baby card.
            } else if (btnMarriage.isSelected()) {
                gCard = new Marriage(txtTo.getText(), txtFrom.getText());
                //Create a Marriage card.
            } else if (btnDivorce.isSelected()) {
                gCard = new Divorce(txtTo.getText(), txtFrom.getText());
                //Create a Divorce card.
            }
            if (gCard != null) { // done no matter what card is selected
                JOptionPane.showMessageDialog(this, gCard.makeCard());
            }
    
        }                               
    
    [B][I]//////////////////////////////////NEW CODE/////////////////////////////          
        // Variables declaration - do not modify                     
        private javax.swing.ButtonGroup btgCards;
        private javax.swing.JRadioButton btnBirthday;
        private javax.swing.JButton btnCreate;
        private javax.swing.JRadioButton btnGeneral;
        private javax.swing.JRadioButton btnValentines;
        private javax.swing.JLabel jLabel1;
        private javax.swing.JLabel jLabel2;
        private javax.swing.JTextField jTextField1;
        private javax.swing.JTextField txtFrom;
        private javax.swing.JTextField txtTo;
        // End of variables declaration                   
        private javax.swing.JRadioButton btnHalloween;
        private javax.swing.JRadioButton btnBaby;
        private javax.swing.JRadioButton btnMarriage;
        private javax.swing.JRadioButton btnDivorce;
        private javax.swing.JRadioButton btnGraduation;
        private javax.swing.JRadioButton btnChristmas;
    }
    ///////////////////////////////END NEW CODE////////////////////////////////[/I][/B]
    Last edited by turbowhat; 04-27-2011 at 02:26 AM.

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default

    I wouldn't use GroupLayout to add my own custom components but rather one of the other more easy to use layout managers. You can read more about them here: Visual Guide to Layout Managers

  3. #3
    turbowhat is offline Member
    Join Date
    Feb 2011
    Posts
    3
    Rep Power
    0

    Default

    Thanx for the reply, this is the starter code the instructor supplied us with, I'm uncertain how to install the coding into the locked part of the coding and make it work...........damn GUI crap.......

Similar Threads

  1. Replies: 0
    Last Post: 03-21-2011, 10:46 AM
  2. Plz give me the code of following simple problem..
    By juhiswt in forum New To Java
    Replies: 3
    Last Post: 03-07-2011, 04:54 AM
  3. Replies: 0
    Last Post: 02-21-2011, 12:50 PM
  4. pleae give me a code
    By Quezza in forum New To Java
    Replies: 3
    Last Post: 01-07-2011, 02:59 AM
  5. Replies: 1
    Last Post: 04-26-2007, 04:52 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
  •