In: Computer Science
Write a class Twins that displays two identically sized windows, 200 * 100 each. The title bar of the first window is labelled “Australia” and the second window is labelled “Melbourne”
Java Programming language
Name the Java file as Twins.java
Code for the Java file Twins.java is as follows:
import java.awt.*;
import javax.swing.*;
public class Twins {
private static void createWindow(String p) {
//Create and set up the window.
JFrame frame = new JFrame(p);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
// set the jframe size and location, and make it visible
frame.setPreferredSize(new Dimension(200, 100));
frame.pack();
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}
public static void main(String[] args){
createWindow("Australia");
createWindow("Melbourne");
}
}
Output:
Since the window is small (200*100), the entire names Australia and Melbourne in the window titles are not visible properly
I am providing extended windows of the same above screenshot in which the entire names Australia and Melbourne are visible in the window titles just for your reference
Hope this answers your questions, please leave a upvote if you find this helpful.