import javax.swing.*; import java.awt.*; import java.awt.event.*;
public class Inter {
private JFrame frame; private JButton botao;
private void Inter(){
frame = new JFrame();
frame.setTitle("Exemplo de Layout");
frame.setSize(200,200);
frame.setLocation(500, 260);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Container ct = frame.getContentPane();
ct.setLayout(null);
botao = new JButton("OK");
botao.setBounds(50,10,150,25); // objeto.setBounds(esquerda, topo, largura, altura)
ct.add(botao);
Image Icone = Toolkit.getDefaultToolkit().getImage("icone.gif");
frame.setIconImage(Icone);
frame.setVisible(true);
botao.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
JOptionPane.showMessageDialog(null, "Bem Vindo!");
}});
frame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}});
}
public static void main(String[] args) {
Inter jx = new Inter();
jx.Inter();
}
} |