我只为这些标签添加了宽高比约束,但它告诉我标签的高度是不可变的。
public static void main(String[] args) {
Random ran = new Random(); // create instant object from class Random.
int array[] =new int[100]; //set an array variable with array size of 100
int maxNumber = 150; //set the limit of the random number to generate
for (int i = 0; i < array.length; i++) {
array[i] = ran.nextInt(maxNumber) + 1; //+1 means that the array number should not contain with 0 value. 1-150.
}
do {
int choosenIndex = 0;
String input = JOptionPane.showInputDialog(null, "Enter index"); //Get input from user
try {
Integer.parseInt(input); //change the string to int type.
if(choosenIndex >= 0 || choosenIndex <= array.length)
JOptionPane.showMessageDialog(null, "The value of choosen index in the array is : "
+ array[choosenIndex]); //display the choosen index value.
System.exit(0);
}catch (ArrayIndexOutOfBoundsException e){
if (choosenIndex < 0 || choosenIndex > array.length) {
JOptionPane.showMessageDialog(null,
"Index is out of bound. Enter from 0-99"); //display error for indexoutbound.
}
}catch(NumberFormatException e){
JOptionPane.showMessageDialog(null, "Only integer allowed.");//display other error occured.
}
} while (true);
}