Vous êtes sur la page 1sur 2

import java.awt.BorderLayout; import java.awt.

EventQueue; import import import import import import import import import import import import import javax.swing.JFrame; javax.swing.JPanel; javax.swing.border.EmptyBorder; javax.swing.JLabel; javax.swing.JOptionPane; javax.swing.SwingConstants; javax.swing.JTextField; javax.swing.JButton; java.awt.event.ActionListener; java.awt.event.ActionEvent; java.awt.Dialog.ModalExclusionType; javax.swing.JComboBox; javax.swing.DefaultComboBoxModel;

public class principal extends JFrame { private JPanel contentPane; private JTextField txtnombre; /** * Launch the application. */ public static void main(String[] args) { EventQueue.invokeLater(new Runnable() { public void run() { try { principal frame = new principal(); frame.setVisible(true); } catch (Exception e) { e.printStackTrace(); } } }); } /** * Create the frame. */ public principal() { setTitle("Mi primer programa"); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setBounds(100, 100, 450, 300); contentPane = new JPanel(); contentPane.setBorder(new EmptyBorder(5, 5, 5, 5)); setContentPane(contentPane); contentPane.setLayout(null); JLabel lblIngresaTusNombres = new JLabel("Ingresa tus nombres:") ; lblIngresaTusNombres.setBounds(26, 50, 108, 24); contentPane.add(lblIngresaTusNombres); txtnombre = new JTextField();

txtnombre.setBounds(144, 52, 125, 20); contentPane.add(txtnombre); txtnombre.setColumns(10); JButton btnSaludo = new JButton("Saludo"); btnSaludo.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { // mostrar cuadro de dilogo JOptionPane.showMessageDialog(principal.this, "H ola " + txtnombre.getText(), "Mensaje", JOptionPane.INFORMATION_MESSAGE); } }); btnSaludo.setBounds(180, 196, 89, 23); contentPane.add(btnSaludo); JButton btnsalir = new JButton("Salir"); btnsalir.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { System.exit(0); } }); btnsalir.setBounds(309, 196, 89, 23); contentPane.add(btnsalir); JComboBox cbPasatiempo = new JComboBox(); cbPasatiempo.setModel(new DefaultComboBoxModel(new String[] {"De portes", "M\u00FAsica", "Programar", "Otros"})); cbPasatiempo.setBounds(144, 113, 108, 20); contentPane.add(cbPasatiempo); //JOptionPane.showMessageDialog(principal.this, "Soy un mensaje normal", "Mensaje", JOptionPane.INFORMATION_MESSAGE); }

Vous aimerez peut-être aussi