import java.awt.*;
import java.awt.event.*;
/*
<APPLET
CODE=gridbag.class
WIDTH=400
HEIGHT=80 >
</APPLET>
*/
public class gridbag extends Applet implements ActionListener
{
Button button1, button2, button3;
TextField text1;
public void init()
{
GridBagLayout gridbag = new GridBagLayout();
GridBagConstraints constraints = new GridBagConstraints();
setLayout(gridbag);
constraints.weighty = 1;
constraints.fill = GridBagConstraints.BOTH;
constraints.weightx = 1;
button1 = new Button("Botón 1");
gridbag.setConstraints(button1, constraints);
button1.setActionCommand("botón 1");
add(button1);
button1.addActionListener(this);
constraints.weightx = 2;
button2 = new Button("Botón 2");
gridbag.setConstraints(button2, constraints);
button2.setActionCommand("botón 2");
add(button2);
button2.addActionListener(this);
constraints.weightx = 1;
button3 = new Button("Botón 3");
constraints.gridwidth = GridBagConstraints.REMAINDER;
gridbag.setConstraints(button3, constraints);
button3.setActionCommand("botón 3");
add(button3);
button3.addActionListener(this);
text1 = new TextField();
constraints.gridwidth = GridBagConstraints.REMAINDER;
gridbag.setConstraints(text1, constraints);
add(text1);
}
public void actionPerformed(ActionEvent e)
{
text1.setText("Hizo clic sobre " + ((Button) e.getSource()).getActionCommand());
}
}
0 comentarios:
Publicar un comentario