Alright I'll put it all in the main class. Ill let you know how it goes.
And thanks for all the help so far.
Welcome to the Java Programming Forums
The professional, friendly Java community. 21,500 members and growing!
The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.
>> REGISTER NOW TO START POSTING
Members have full access to the forums. Advertisements are removed for registered users.
Alright I'll put it all in the main class. Ill let you know how it goes.
And thanks for all the help so far.
You don't have to move the code.
You do need to pass a reference to JFramePlayArea to the CreatePlayField class and save it in the jFrameMain variable.
I moved everything to the main class and still nothing.
import java.awt.*; import javax.swing.*; /* * To change this template, choose Tools | Templates * and open the template in the editor. */ /* * jFramePlayArea.java * * Created on Aug 7, 2011, 5:07:11 PM */ /** * * @author Cameron */ public class jFramePlayArea extends javax.swing.JFrame { JLabel[] horizontalLines; //Declaring the horizontal lines array. JLabel[] verticalLines; //Declaring the vertical lines array. Point[] boxes; //Declaring the boxes array /** Creates new form jFramePlayArea */ public jFramePlayArea() { initComponents(); } /** 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. */ @SuppressWarnings("unchecked") // <editor-fold defaultstate="collapsed" desc="Generated Code"> private void initComponents() { jButton1 = new javax.swing.JButton(); jLabel1 = new javax.swing.JLabel(); setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); jButton1.setText("jButton1"); jButton1.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton1ActionPerformed(evt); } }); jLabel1.setText("jLabel1"); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addContainerGap() .addComponent(jButton1)) .addGroup(layout.createSequentialGroup() .addGap(421, 421, 421) .addComponent(jLabel1))) .addContainerGap(613, Short.MAX_VALUE)) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() .addGap(138, 138, 138) .addComponent(jLabel1) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 604, Short.MAX_VALUE) .addComponent(jButton1) .addContainerGap()) ); pack(); }// </editor-fold> private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) { createBoxes(); } public void createBoxes() { /* * In this section we set the arrays up. */ //Giving the arrays their size and initializing them. horizontalLines = new JLabel[272]; verticalLines = new JLabel[272]; boxes = new Point[272]; //Variables used for creating the Box Points int XX; int YY; int B = 0; int boxY = 0; //Creating 272 JLabels for all of the vert and horiz lines for (int lineX = 1; lineX < 272; lineX++) { horizontalLines[lineX] = new JLabel(); verticalLines[lineX] = new JLabel(); } //Creating 256 Point variables used to draw and fill the boxes when needed. while (boxY < 272) { for (int A = 0; A <= 16; A++) { //Calculating the variables used to set the points X and Y XX = (A * 30) + 1; YY = B * 30; //creating the new point and setting its X and Y. boxes[boxY] = new Point(XX, YY); boxY++; if (A == 16) { B++; } } } /* * In this section we will define all of the objects */ for (int X = 1; X < 272; X++) { //Define horizontal line X horizontalLines[X].setBackground(new java.awt.Color(0, 0, 0)); horizontalLines[X].setOpaque(true); horizontalLines[X].setLocation(boxes[X]); horizontalLines[X].setPreferredSize(new Dimension(28, 2)); horizontalLines[X].setText(""); horizontalLines[X].setVisible(true); getContentPane().add(horizontalLines[X]); //Define vertical line X } } /** * @param args the command line arguments */ public static void main(String args[]) { /* Set the Nimbus look and feel */ //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) "> /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel. * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html */ 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(jFramePlayArea.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (InstantiationException ex) { java.util.logging.Logger.getLogger(jFramePlayArea.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (IllegalAccessException ex) { java.util.logging.Logger.getLogger(jFramePlayArea.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (javax.swing.UnsupportedLookAndFeelException ex) { java.util.logging.Logger.getLogger(jFramePlayArea.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } //</editor-fold> /* Create and display the form */ java.awt.EventQueue.invokeLater(new Runnable() { public void run() { new jFramePlayArea().setVisible(true); } }); } // Variables declaration - do not modify private javax.swing.JButton jButton1; private javax.swing.JLabel jLabel1; // End of variables declaration }
Am I not adding it correctly? Do I have to do it like the IDE automatically does in initComponents()?
Now you have gotten into a conflict with the layout manager. You have already added some components to the frame and shown it. Where should the layout manager put the new ones you want to add?
The IDE has generated lots of code to position the two components that are being shown. The new ones don't fit in with them.
I don't normally do weird GUI. Removing components and resetting layout in a container is not something that makes sense to me.
I really have no recommendations for you if want to do this kind of stuff.
Alright I'll repost in a more suitable board. Thanks for all of the help.