JFrame frame = new JFrame(); JLabel label = new JLabel("Hello World!"); frame.add(label);
JFrame frame = new JFrame(); ImageIcon icon = new ImageIcon("image.jpg"); JLabel label = new JLabel(icon); frame.add(label);In this example, a new ImageIcon object is created with an image file called "image.jpg". Then, a new JLabel object is created with the icon and added it to the JFrame using the add() method. Overall, the javax.swing package library provides a wide range of GUI components that can be used to build desktop applications. The JLabel component is just one of many useful components in the library.