gente olhem este codigo.... ele é basicamente , um botao , que quando apertado, é renomeado com o que tem escrito em uma caixa de texto....
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class SwingExemplo2 extends JFrame implements ActionListener
{
JButton botao1;
JPanel panel;
JTextField texto;
public SwingExemplo2()
{
super("blahblah oO'''");
}
public void criaJanela()
{
texto = new JTextField("Digite algo...");
panel = new JPanel();
panel.setLayout(new GridLayout(2,1));
botao1 = new JButton("Me clique");
botao1.addActionListener(this);
panel.add(texto);
panel.add(botao1);
getContentPane().add(panel,BorderLayout.CENTER);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
pack();
setVisible(true);
}
public void actionPerformed(ActionEvent event)
{
botao1.setText(texto.getText());
}
public static void main(String[] args)
{
SwingExemplo2 ex2 = new SwingExemplo2();
ex2.criaJanela();
}
}
o q o comango "pack()" faz , exatamente??