import java.awt.Color;
import java.awt.Rectangle;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JList;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.WindowConstants;
public class clasesita
{
private JFrame v;
private JButton b;
private JButton algo;
private JTextField t;
public static void main(String [] args)
{
new clasesita();
}
public clasesita()
{
v = new JFrame("Ventana Hola Mundo");
v.getContentPane().setLayout(null);
b = new JButton("Púlsame");
algo = new JButton("aceptar");
v.getContentPane().add (b);
String subject[] = {"cadena1", "cadena2", "cadena3", "cadena4"};
JPanel panel = new JPanel();
JList list = new JList(subject);
v.getContentPane().add(list);
list.setBounds(new Rectangle(350,10,100,40));
t = new JTextField(10);
v.getContentPane().add(t);
v.getContentPane().add (algo);
algo.setBounds(new Rectangle(120,10,100,23));
b.setBounds(new Rectangle(10,10,100,23));
t.setBounds(new Rectangle(240,10,100,23));
b.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
t.setText ("webada");
}
});
algo.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
String alg = null ;
alg = b.getText();
t.setText (alg);
b.setBackground(Color.blue);
JOptionPane.showMessageDialog(v, "mensajito xD",
"titulo de ventanita",
JOptionPane.INFORMATION_MESSAGE);
}
});
v.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
v.setSize(500, 500);
v.setVisible(true);
}
}
No hay comentarios:
Publicar un comentario