Create JFrame with label?

2

How to create a JFrame , which contains a JLabel with text, and can be positioned anywhere in the frame.

I need this label to stay anywhere in the frame area.

    
asked by anonymous 31.10.2016 / 01:31

1 answer

3
package teste02;

import javax.swing.JFrame;
import static javax.swing.JFrame.EXIT_ON_CLOSE;
import javax.swing.JLabel;
import javax.swing.JPanel;

public class TelaSistema extends JFrame 
{
    public TelaSistema() 
    {
        setSize(600, 400);       
        setTitle("Sistema "); 
        JPanel painel = new JPanel();
        painel.setLayout(null);        
        JLabel label = new JLabel();
        label = new JLabel("Olá mundo !");
        painel.add(label);
        label.setBounds(250, 150, 300, 50);
        add(painel);
        setDefaultCloseOperation(EXIT_ON_CLOSE);
        setLocationRelativeTo(null);
        setVisible(true);
    }      

    public static void main(String[] args) {
        TelaSistema teste = new TelaSistema();
    }
}
    
31.10.2016 / 01:32