Buttons and labels are the most commonly used components , and you will need them for your project. Listing 14.2 is a quick example demonstrating how to simply add a label to a frame. Listing 14.2 How to Add a Label to a Frameimport javax.swing.JLabel; import javax.swing.JFrame; public class MyLabelApplication { public static void main(String[] args) { //create label JLabel label = new JLabel("My Label Application"); //create frame JFrame frame = new JFrame("My Label Application"); //Notice that BorderLayout is the default frame.getContentPane().add(label); frame.pack(); frame.setVisible(true); } } |