Advertisement
makispaiktis

4. JFrame, JLabel Example (MyFrame)

May 16th, 2022 (edited)
873
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.92 KB | None | 0 0
  1. import java.awt.FlowLayout;
  2. import javax.swing.JFrame;
  3. import javax.swing.JLabel;
  4.  
  5. public class MyFrame extends JFrame{
  6.  
  7.     // Variables
  8.     private JLabel myLabel;                                              // Each frame must have a label to contain words, text, images
  9.  
  10.     // Constructor
  11.     public MyFrame(){
  12.         super("JFrame's title");                                    // JFrame's title
  13.         setLayout(new FlowLayout());                                    // JFrame must follow the rules of a layout
  14.         myLabel = new JLabel("JLabel's text container");           // The container
  15.         myLabel.setToolTipText("Text appearing while hovering");
  16.         add(myLabel);
  17.     }
  18.  
  19.     // Main
  20.     public static void main(String args[]){
  21.         MyFrame frame = new MyFrame();
  22.         frame.setDefaultCloseOperation(EXIT_ON_CLOSE);
  23.         frame.setSize(600, 600);
  24.         frame.setVisible(true);
  25.     }
  26.  
  27. }
  28.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement