Buttons and Labels


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 Frame
 import 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);     } } 


JavaT 2 Developer Exam CramT 2 (Exam CX-310-252A and CX-310-027)
JavaT 2 Developer Exam CramT 2 (Exam CX-310-252A and CX-310-027)
ISBN: N/A
EAN: N/A
Year: 2003
Pages: 187

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net