Pls help:) I want to make a crossword puzzle in java. I need to create a grid in GUI. How do i do it netbeans manually.
@ganeshie8
@e.mccormick @eSpeX
You will need to use some kind of UI library. I think Swing could be a good one it is not particularly difficult and it is fairly powerful.
Are you just going to use the basic text field entry inside a box? As c0decracter pointed out, swing would work and it has that: http://docs.oracle.com/javase/tutorial/uiswing/components/textfield.html
and perhaps you could at JTextFields to a program that uses a GridLayout layout manager (so they appear in a grid). ``` import javax.swing.*; import java.awt.r*; public class CrossWord { private JTextField[] jta; private JFrame jf; private JPanel jp; public static void main(String[] args){ new CrossWord(); } public CrossWord(){ jta = new JTextField[100]; jf = new JFrame("Crossword Puzzle Layout"); jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); jp = new JPanel(); jp.setLayout(new GridLayout(10, 10, 8, 8)); //a 10x10 grid with 8 pixels separating the grid horizontally and vertically for(int i = 0; i < 100; i++) { jta[i] = new JTextField(2); jp.add(jta[i]); //with gridlayout, components are added to the grid in a top left to //bottom right format } jf.add(jp); jf.pack(); //jf.setLocationRelativeTo(null); - to center of screen //jf.setResizable(false); - disables resizing jf.setVisible(true); } } ``` You can also use a layout manager on the JFrame to add multiple JPanels -- perhaps another JPanel with a submit button & make an actionlistener for it.
*import java.awt.*; and I don't think I used awt..
GridLayout is in the java.awt package.
a - ha
Join our real-time social learning platform and learn together with your friends!