java swing get frame size
Rectangle r = frame.getBounds(); int h = (int) r.getHeight(); int w = (int) r.getWidth();
Here is what the above code is Doing:
1. We’re getting the frame’s bounds.
2. We’re getting the height and width of the frame.
Rectangle r = frame.getBounds(); int h = (int) r.getHeight(); int w = (int) r.getWidth();
Here is what the above code is Doing:
1. We’re getting the frame’s bounds.
2. We’re getting the height and width of the frame.
Integer.valueOf(x).longValue() Here is what the above code is Doing: 1. We’re using the map function to apply the function to each element in the list. 2. The function we’re applying is a lambda function. 3. The lambda function takes a single argument x. 4. The lambda function returns the value of x converted to a…
import java.util.Random; public class RandomStringFromArray { public static void main(String[] args) { String[] arr={“1”, “2”, “3”, “4”, “5”}; Random r=new Random(); int randomNumber=r.nextInt(arr.length); System.out.println(arr[randomNumber]); } } Here is what the above code is Doing: 1. We have created an array of String type. 2. We have created an object of Random class. 3. We have…
import java.io.FileWriter; … FileWriter writer = new FileWriter(“output.txt”); for(String str: arr) { writer.write(str + System.lineSeparator()); } writer.close(); Here is what the above code is Doing: 1. Create a FileWriter object. 2. Loop through the array and write each element to the file. 3. Close the file.
Float and double Double is more precise than float and can store 64 bits, double of the number of bits float can store. … Float and double function in the same way in all programming languages. For example, in Java, both will throw NumberFormatException with operations where actual numbers are not involved Here is what…
String s = “Hello World! 3 + 3.0 = 6 “; // create a new scanner with the specified String Object Scanner scanner = new Scanner(s); // find the next token and print it System.out.println(“” + scanner.next()); // “Hello” // find the next token and print it System.out.println(“” + scanner.next()); // “World!” // close the…
// change this: import androidx.core.util.ArraySet; // to this: import androidx.collection.ArraySet; Here is what the above code is Doing: 1. It’s importing the ArraySet class from the androidx.collection package. 2. It’s replacing the import statement for the ArraySet class from the androidx.core.util package with the import statement for the ArraySet class from the androidx.collection package. 3….