With respect to an array of string types, the array element does not need to be added ""
Today, in writing swing, for a quick layout, you need to create a string layout array as shown:
Careful readers may find that the array elements in this border array are not in "", and we know in the learning array that when we define a String array, the elements of the array need to be included in "", for example, we define an array string[]car={"BMW", "Mercedes", " Audi "}; So we have no problem traversing the array.
But if we define STRING[]CAR={BMW, Mercedes, Audi, like the String[]border array above, the program will give an error. To figure this out, you have to understand that string[]car={"BMW", "Mercedes", "Audi"} defines what the "" in the array means. It is equivalent to first defining the array elements as string types, and then adding the array elements to the array. For example if we do not string bmw= "BMW"; BMW it is not a string type, it will naturally complain. In fact, we can also write this:
As you can see, we first define the elements as string, and then we can not add "".
Then we look at the String[]border array above, and the readers of Swing should know that the array element inside is the direction of the boundary layout, and that it belongs to the static String type, as we can see from the code hints. Please see the following code:
As we can see from the output, the Java developer has been string boederlayout.north= "North" at the time of development, so we do not need to add "" in the definition of the string[] array. In the same vein, we can define an array of colors:
This article is the first Blogger blog, I hope to help everyone, if there is a mistake, but also hope that we can correct.