I don't figure out where's the bug on this code.
It doesn't show anything at all.
It doesn't show anything at all.
Code:
import java.awt.*;
import java.awt.event.*;
public class ventana extends Frame {
Label texto1 = new Label("texto-1",Label.CENTER);
Label texto2 = new Label("texto-2",Label.CENTER);
Label texto3 = new Label("texto-3",Label.CENTER);
TextField t1 = new TextField();
TextField t2 = new TextField();
TextField t3 = new TextField();
Button b1 = new Button("añadir");
Button b2 = new Button("borrar");
TextArea area = new TextArea();
public ventana() {
super("Interfaz gráfico de usuario");
Panel panel1 = new Panel();
Panel panel2 = new Panel();
add(panel1);
add(panel2);
panel1.setLayout(new GridLayout(3,2));
panel1.add(t1);
panel1.add(texto1);
panel1.add(t2);
panel1.add(texto2);
panel1.add(t3);
panel1.add(texto3);
add(area);
panel2.setLayout(new GridLayout(2,1));
panel2.add(b1); b1.addActionListener(new GestionaComponentes());
panel2.add(b2); b2.addActionListener(new GestionaComponentes());
addWindowListener(new GestionaVentana());
}
class GestionaVentana extends WindowAdapter {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
}
class GestionaComponentes implements ActionListener {
public void actionPerformed(ActionEvent e) {
Object fuente = e.getSource();
if (fuente == b1) {
//El botón b1 causó el evento
}
else {
//El botón b2 causó el evento
}
}
}
public static void main(String args[]) {
new ventana().show();
}
}