import java.awt.Container; import javax.swing.JFrame; import javax.swing.JPanel; public class ContainerExample { public static void main(String[] args) { JFrame frame = new JFrame(); JPanel panel = new JPanel(); Container contentPane = frame.getContentPane(); contentPane.add(panel); frame.setVisible(true); System.out.println("Panel width: " + panel.getWidth()); } }
import java.awt.Container; public class ContainerExample { public static void main(String[] args) { Container container = new Container(); container.setSize(600, 400); System.out.println("Container width: " + container.getWidth()); } }Both examples use the java.awt package library.