Wer ist vertraut mit Java Gui - Swing-Paket ... und wissen, wie man mehrere Swing-Objekte wie "jlabels und jtextfields" in einer Art Schleife erstellt, so dass man sie nicht redundant einstellen muss? ...JEMAND???Mehrere Jlabels und JTextFields auf weniger redundante Weise erstellen?
Zum Beispiel - ich habe 60 Textfelder erstellen und 11 JLabels und etc. Ich möchte (wenn möglich) nicht jedes einzeln wie so erstellen müssen
JLabel jlblName = new JLabel("first one");
JLabel jlblName = new JLabel("first two");
JLabel jlblName = new JLabel("first three");
//etc...
Wenn möglich möchte ich auch gerne finden Sie eine Möglichkeit, die Grenzen festzulegen und die Beschriftungen auf kürzere Weise hinzuzufügen.
Ich habe verschiedene Wege versucht, dies zu erreichen - mit Arrays und Erstellen von Methoden zu bekommen und immer noch kein Glück .___.
BITTE HELFEN SIE MICH, WENN SIE KÖNNEN
Im Folgenden ein Beispiel für das, was ich bisher geschrieben ... aber auch wenn es funktioniert hat es, dass praktisch nicht für Serval Gründe scheinen. ..auch ich bin mir nie sicher, warum es nicht funktioniert.
public class prospectVer2
{
private static int l = 59; //, t = 20, c=11;
public static String getInfo(int b)
{
int a=b;
String [] lah = new String [prospectVer2.l];
lah [0]= "a";
lah [1]= "b";
lah [2]= "c";
lah [3]= "d";
lah [4]= "e";
lah [5]= "f";
lah [6]= "g";
lah [7]= "e";
lah [8]= "f";
lah [9]= "g";
lah [10]= "h";
lah [11]= "i";
lah [12]= "j";
lah [13]= "k";
lah [14]= "l";
lah [15]= "m";
lah [16]= "n";
lah [17]= "o";
lah [18]= "p";
lah [19]= "q";
lah [21]= "r";
lah [22]= "s";
lah [23]= "t";
lah [24]= "u";
lah [25]= "v";
lah [26]= "w";
lah [27]= "x";
lah [28]= "y";
lah [29]= "z";
lah [30]= "aa";
lah [31]= "bb";
lah [32]= "cc ";
lah [33]= " dd";
lah [34]= " ee";
lah [35]= " ff ";
lah [36]= " gg ";
lah [37]= " hh ";
lah [38]= " ii ";
lah [39]= "jj";
lah [40]= "kk";
lah [41]= "ll";
lah [42]= "mm";
lah [43]= "nn";
lah [44]= "oo";
lah [45]= "pp";
lah [46]= "qq";
lah [47]= "rr";
lah [48]= "ss";
lah [49]= "tt";
lah [50]= "uu";
lah [51]= "vv";
lah [52]= "ww";
lah [53]= "xx";
lah [54]= "yy";
lah [55]= "zz";
lah [55]= "aaa";
lah [56]= "bbb";
lah [57]= "ccc";
lah [58]= "ddd";
lah [59]= "eee";
String infos= lah[a];
return infos;
}
public static void main(String[] args)
{
// Declare variables - arrays
// Create Frame and Panel - set size -
JFrame frame = new JFrame("Prospect Assignment");
frame.setSize(700, 900);
JPanel mypanel = new JPanel();
JLabel[] labels = new JLabel[prospectVer2.l];
// Create labels (60) - for loop -
for (int i=0; i<labels.length; i++)
{
labels[i] = new JLabel(prospectVer2.getInfo(i));
mypanel.add(labels[i]);
labels[i].setBounds(i*10+245,i*10+210,120,20);
}
// extra functions for gui
frame.add(mypanel);
mypanel.setLayout(null);
frame.setVisible(true);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
BTW muss ich diese Seite replizieren mit javas Swing-Paket https://cunycitytech.askadmissions.net/emtinterestpage.aspx?ip=prospect DANKE!