This code snippet demonstrates how to show a JFrame with a JLabel.

Listing 1

  1. 1import  javax.swing.JFrame;
  2. 2import  javax.swing.JPanel;
  3. 3import  javax.swing.JLabel;
  4. 4
  5. 5class  Main{
  6. 6        
  7. 7        public  static  void  main(String  args[]){
  8. 8                
  9. 9                JFrame  frame  =  new  JFrame();
  10. 10                JPanel  panel  =  new  JPanel();
  11. 11                
  12. 12                JLabel  label  =  new  JLabel();
  13. 13                label.setText("Hello World");
  14. 14                
  15. 15                panel.add(label);
  16. 16                
  17. 17                frame.add(panel);
  18. 18                
  19. 19                frame.setSize(200,200);
  20. 20                frame.setVisible(true);
  21. 21        }
  22. 22}