Hey everyone,
I am attempting to add an array of JTextFields to one of my JPanels and for some reason i keep getting errors and the program crashes when i run it. I know i am prob making some noob mistake but this a project for my first Java class so please do not look down on me lol
A picture of the INTENDED end result is here if u want to see it
Any help would be greatly appreciated. Thank you!
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class ManyNumbers
{
public static void main(String [] args)
{
ManyNumbersWindow mn = new ManyNumbersWindow("Kreg Khemmoro - Program 6");
}
}
class ManyNumbersWindow extends JFrame
{
public static final int MAX_NUM = 10;
JTextField [] nums = new JTextField[MAX_NUM];
public ManyNumbersWindow(String s)
{
super(s);
//Begin JPanel for numbers textfields
JPanel topGrid = new JPanel();
topGrid.add(nums[0]);
JPanel botGrid = new JPanel();
JPanel gridContainer = new JPanel();
gridContainer.add(topGrid, BorderLayout.NORTH);
gridContainer.add(botGrid, BorderLayout.SOUTH);
//JPanel for buttons starts here
JPanel southPanel = new JPanel();
JButton btnGenNum = new JButton("New Numbers");
JCheckBox bigNum = new JCheckBox("Big numbers");
southPanel.setLayout(new FlowLayout());
southPanel.add(btnGenNum);
southPanel.add(bigNum);
//Ends JPanel for buttons
add(gridContainer, BorderLayout.NORTH);
add(southPanel, BorderLayout.SOUTH);
pack();
setVisible(true);
setResizable(true);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}