|
|
Исходный текст программы GridBag1.java
|
Оглавление |
Назад
// ==========================================
// GridBag1.java
//(C) Alexandr Frolov, 1998
// E-mail: frolov@glasnet.ru
// Web: http://www.glasnet.ru/~frolov
// ==========================================
import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;
public class GridBag1 extends Applet
implements ActionListener
{
TextField tf;
TextField tf2;
Button btnGetName;
Label lb;
// ============================================
// init
// ============================================
public void init()
{
tf = new TextField(30);
btnGetName = new Button("Enter name");
lb = new Label("Your name is: ");
tf2 = new TextField(30);
tf2.setEditable(false);
GridBagLayout gbl = new GridBagLayout();
GridBagConstraints c =
new GridBagConstraints();
setLayout(gbl);
c.anchor = GridBagConstraints.NORTH;
c.fill = GridBagConstraints.NONE;
c.gridheight = 1;
c.gridwidth = GridBagConstraints.REMAINDER;
c.gridx = GridBagConstraints.RELATIVE;
c.gridy = GridBagConstraints.RELATIVE;
c.insets = new Insets(40, 0, 0, 0);
c.ipadx = 0;
c.ipady = 0;
c.weightx = 0.0;
c.weighty = 0.0;
gbl.setConstraints(tf, c);
add(tf);
c.insets = new Insets(5, 0, 0, 0);
gbl.setConstraints(btnGetName, c);
add(btnGetName);
c.insets = new Insets(10, 0, 0, 0);
gbl.setConstraints(lb, c);
add(lb);
c.insets = new Insets(5, 0, 0, 0);
c.weightx = 0.0;
c.weighty = 1.0;
c.gridheight = GridBagConstraints.REMAINDER;
gbl.setConstraints(tf2, c);
add(tf2);
btnGetName.addActionListener(this);
}
// ============================================
// actionPerformed
// ============================================
public void actionPerformed(ActionEvent e)
{
if(e.getSource().equals(btnGetName))
{
tf2.setText(tf.getText());
}
}
// ============================================
// getAppletInfo
// ============================================
public String getAppletInfo()
{
return "Name: GridBag1";
}
}
|
|
|