java - Array of JTextFields in a for loop that adds itself to the layout -
I have a problem in connecting this JTextFields on the layout only JTextField will appear which is 18 instead of either 1 or
My plan is 20 jettextfields in my layout, with 20 of these text fields, they will have random x + y values and there will be random conditions on the layout. These are my codes:
import java.util.Random; Import javax.swing.JFrame; Import javax.swing.JTextField; Public Square JetxArray JFram {JTextField [] allField = New JTextField [20]; Random rand = new random (); Int x = rand.nextInt (100); Int y = rand.nextInt (100); Int xpost = rand.nextInt (300); Int ypost = rand.nextInt (150); JtextArray () {Super ("DSD"); SetLayout (zero); For (int x = 0; x & lt; = 18; x ++) {System.out.println (x); AllField [x] = New JTextField (string format ("% s +% s", x, y)); AllField [x] .setbounds (Exops, Usports, 100, 30); Add (allField [x]); }}} My main square
import javax.swing.JFrame; Public category array editing JFrame {public static increases zero main (string [] algs) {JtextArray object = new Jetext array (); Object.setDefaultCloseOperation (EXIT_ON_CLOSE); Object.setSize (400,400); Object.setVisible (true); }}
Your text files have the same coordination!
Use rand.nextInt inside your loop.
Comments
Post a Comment