私のデザインには、box1、box2 などの名前の 9 つのテキストフィールドがあります。これらの 1 つを黄色にしたいと考えています。だから私はテキストフィールドの名前を配列に入れて、Random関数を使ってこれらの名前の1つを選んでみました。しかし、うまくいきません。
String[] boxes = new String[]{"box1", "box2", "box3", "box4", "box5", "box6",
"box7", "box8", "box9"};
Random rand = new Random();
int randomint = rand.nextInt(9);
String thatBox = boxes[randomint];
thatBox.setBackground(Color.yellow);