Here is my error:
at java.awt.Container.add(Unknown Source) at frmClient.panelSetup(frmClient.java:117) at frmClient.<init>(frmClient.java:65) at frmClient.main(frmClient.java:48)
Here is my code:
import java.awt.Color; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JButton; import javax.swing.JComboBox; import javax.swing.JFormattedTextField; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.swing.JTextField; public class frmClient implements ActionListener{ public static JFrame[] arrFrame = new JFrame[1]; // Define JPanels for layout public static JPanel[] panel = new JPanel[16]; // Define labels public static JLabel lblStatus; // Define JTextFields public static JFormattedTextField[] txtBox = new JFormattedTextField[75]; // Define JComboBox's public static JComboBox comBoxA; // Define integers public static int[] arrNumber = new int[58]; // Define doubles public static double[] arrDouble = new double[17]; // Define JButtons public static JButton btnSave, btnClear, btnClose, btnCalculate; // Define boolean public static boolean ctrlLock; // Define custom RGB colors for table(s) static Color colTableA = new Color(194, 250, 203); static Color colTableB = new Color(242, 235, 150); // Main method public static void main(String[] args) { new frmClient(); } public frmClient(){ // Create the main JFrame that will hold all the panels & Add data Frame arrFrame[0] = new JFrame("Company Name"); arrFrame[0].setVisible(true); arrFrame[0].setResizable(false); arrFrame[0].setBounds(450, 300, 800, 570); // Create panel to hold all of the panels panel[0] = new JPanel(); panel[0].setBackground(Color.WHITE); panel[0].setForeground(Color.GREEN); // Extracted methods panelSetup(); } private void panelSetup() { // Create panelLogo for the company logo panel[1] = new JPanel(); panel[1].add(new JLabel(" Factory Emissions ")); // Create panel1 to hold label(s) at top panel[2] = new JPanel(); panel[2].setBackground(Color.WHITE); panel[2].add(new JLabel("Time ")); panel[2].add(new JLabel("Monday ")); panel[2].add(new JLabel("Tuesday ")); panel[2].add(new JLabel("Wednesday ")); panel[2].add(new JLabel("Thursday ")); panel[2].add(new JLabel("Friday ")); panel[2].add(new JLabel("Weekly Average")); // Create panel2 to hold first line of JTextField(s) panel[3] = new JPanel(); panel[3].setBackground(Color.WHITE); for(int i = 0; i > 74; i++){ for(int a = 3; a > 14; a++){ if(a == 11){ // Create panel11 to hold the line seperator(s) panel[a] = new JPanel(); panel[a].setBackground(Color.WHITE); panel[a].add(new JLabel("___________________________________________________" + "_______________________________________________________")); } // End IF else { panel[a] = new JPanel(); panel[a].setBackground(Color.WHITE); txtBox[i] = new JFormattedTextField(); txtBox[i].setHorizontalAlignment(JTextField.RIGHT); txtBox[i].setColumns(8); panel[a].add(txtBox[i]); } // End ELSE } } // Add all the panels to the main panel arrFrame[0].add(panel[0]); panel[0].add(panel[1]); panel[0].add(panel[2]); panel[0].add(panel[3]); panel[0].add(panel[4]); panel[0].add(panel[5]); panel[0].add(panel[6]); panel[0].add(panel[7]); panel[0].add(panel[8]); panel[0].add(panel[9]); panel[0].add(panel[10]); panel[0].add(panel[11]); panel[0].add(panel[12]); panel[0].add(panel[13]); panel[0].add(panel[14]); panel[0].add(panel[15]); // Create a new anwser array String[] arrComboBox = new String [2]; arrComboBox[0] = "Disabled"; arrComboBox[1] = "Enabled"; // Create comboboxA and add arrComboBox data into selector comBoxA = new JComboBox(arrComboBox); comBoxA.setBackground(Color.white); comBoxA.setForeground(Color.MAGENTA); comBoxA.addActionListener(this); // Set boolean state ctrlLock = false; // Create panel14 for the buttons & Button settings /*panel14 = new JPanel(); panel14.setBackground(Color.WHITE); panel14.add(btnClear = new JButton("Clear this weeks data")); panel14.add(btnCalculate = new JButton("Calculate")); panel14.add(new JLabel(" ")); panel14.add(new JLabel("Lock Controls: ")); panel14.add(comBoxA); panel14.add(new JLabel(" ")); panel14.add(btnSave = new JButton("Save Data")); panel14.add(btnClose = new JButton("Close")); */ // Add Time & Button ActionListener(s) //btnClear.addActionListener(this); //btnSave.addActionListener(this); //btnClose.addActionListener(this); //btnCalculate.addActionListener(this); } public void actionPerformed(ActionEvent e) { // Execute the code if btnCalculate has focus and lock controls is off if(btnCalculate.hasFocus()){ if(ctrlLock == false){ } else if(ctrlLock == true){ JOptionPane.showMessageDialog(arrFrame[0], "Control lock is currently enabled"); } } // Execute the code if btnClose has focus if(btnClose.hasFocus()) { if(ctrlLock == false){ System.exit(0); } else if (ctrlLock == true){ JOptionPane.showMessageDialog(arrFrame[0], "Control lock is currently enabled"); } } if(comBoxA.getSelectedIndex()== 0){ // Set boolean state ctrlLock = false; } else if(comBoxA.getSelectedIndex()== 1){ ctrlLock = true; } // Execute the code if btnSave is clicked if(e.getSource() == btnSave){ if(ctrlLock == false){ } else if(ctrlLock == true){ JOptionPane.showMessageDialog(arrFrame[0], "Control lock is currently enabled"); } } // Execute the code if btnClear is clicked if(e.getSource() == btnClear){ if(ctrlLock == false){ } else if(ctrlLock == true){ JOptionPane.showMessageDialog(arrFrame[0], "Control lock is currently enabled"); } } } //public void week5PM(){ //intCalculate = intMonI + intTueI + intWedI + intThuI + intFriI; //dblWkI = intCalculate / 5; //txtWAI.setText(Double.toString(dblWkI)); //} //public void calcAverage(){ //dblCal = dblWkA + dblWkB + dblWkC + dblWkD + dblWkE + dblWkF + dblWkG //+ dblWkH + dblWkI; //dblWA = dblCal; //txtWAJ.setText(Double.toString(dblWA)); //dblWB = dblCal / 9; //txtWAK.setText(Double.toString(dblWB)); //} }
i know its something simple although ive been having this problem ever since i started using for loops. The program starts when compiling and displays up to the 2nd panel. it seems to stop before the JFormattedTextFields come in. I have been looking and i do have a feeling its to do with my for loop. although if somebody could tell me how to solve this before i tackle the problem myself id still be thankful . Also i do know there are similar threads already listed. I had looked at one i tryed a few solutions but had no luck.
The error lines:
Line 117: panel[0].add(panel[4]);Line 65: // Extracted methods panelSetup();Line 48: new frmClient();
Thank you in advance. Also i apologize for the beginner question as i am half a sleep been workin to much this week