import java.awt.Frame; public class Main { public static void main(String[] args) { Frame frame = new Frame(); frame.setSize(400, 400); // set frame size frame.setVisible(true); // set frame visibility int height = frame.getHeight(); // get frame height System.out.println("Frame height = " + height); } }
import java.awt.Frame; import java.awt.Panel; public class Main { public static void main(String[] args) { Frame frame = new Frame(); Panel panel = new Panel(); panel.setSize(300, 300); // set panel size frame.add(panel); // add panel to frame frame.setSize(400, 400); // set frame size frame.setVisible(true); // set frame visibility int height = panel.getHeight(); // get panel height System.out.println("Panel height = " + height); } }This example creates a frame and a panel, sets the panel size to 300px by 300px, adds the panel to the frame, and sets the frame size to 400px by 400px. Then it gets the height of the panel using the getHeight() method and prints it to the console.