Results 1 to 3 of 3
- 04-27-2011, 01:22 AM #1
Member
- Join Date
- Feb 2011
- Posts
- 3
- Rep Power
- 0
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 01:26 AM.
-
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
- 04-27-2011, 03:08 AM #3
Member
- Join Date
- Feb 2011
- Posts
- 3
- Rep Power
- 0
Similar Threads
-
hi can you give me some idea to move this code back to soabean (Presentation bean). c
By bharanik in forum JavaServer Pages (JSP) and JSTLReplies: 0Last Post: 03-21-2011, 09:46 AM -
Plz give me the code of following simple problem..
By juhiswt in forum New To JavaReplies: 3Last Post: 03-07-2011, 03:54 AM -
C server code - Java CLient Code _ TCP Connection Problem
By rmd22 in forum NetworkingReplies: 0Last Post: 02-21-2011, 11:50 AM -
pleae give me a code
By Quezza in forum New To JavaReplies: 3Last Post: 01-07-2011, 01:59 AM -
Generating Code Automatically Using Custom code Template In Eclipse
By JavaForums in forum EclipseReplies: 1Last Post: 04-26-2007, 03:52 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks