JLabel label = new JLabel("Hello World!"); label.setName("Greeting Label");
JLabel label = new JLabel("This is a text"); String name = label.getName(); System.out.println(name);This code creates a new JLabel with the message "This is a text" and retrieves its name using the getName() method. It then prints the name to the console. Package library: javax.swing