Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.*;
- import java.awt.event.*;
- public class De2 extends Frame implements ActionListener {
- private Label lbForm, lbNguon, lbDich;
- private TextField tfNguon, tfDich;
- private Button btCopy, btHuy;
- private GridBagLayout gb;
- private GridBagConstraints gbc;
- public De2(String title) {
- super(title);
- this.addWindowListener(new WindowAdapter() {
- public void windowClosing(WindowEvent we) {
- System.exit(0);
- }
- });
- lbForm = new Label("Form Test");
- lbNguon = new Label("Source:");
- lbDich = new Label("Destination:");
- tfNguon = new TextField(20);
- tfDich = new TextField(20);
- btCopy = new Button("Copy to");
- btHuy = new Button("Cancel");
- gb = new GridBagLayout();
- this.setLayout(gb);
- this.Them(lbForm, 0, 0, 2, 1);
- this.Them(lbNguon, 0, 1, 1, 1);
- this.Them(lbDich, 0, 2, 1, 1);
- this.Them(tfNguon, 1, 1, 1, 1);
- this.Them(tfDich, 1, 2, 1, 1);
- this.Them(btCopy, 0, 3, 1, 1);
- this.Them(btHuy, 1, 3, 1, 1);
- btCopy.addActionListener(this);
- btHuy.addActionListener(this);
- }
- public void Them(Component comp, int x, int y, int rong, int cao) {
- gbc = new GridBagConstraints();
- gbc.gridx = x;
- gbc.gridy = y;
- gbc.gridwidth = rong;
- gbc.gridheight = cao;
- gb.setConstraints(comp, gbc);
- this.add(comp);
- }
- public void actionPerformed(ActionEvent ae) {
- if (ae.getSource() == btCopy ) {
- String str = tfNguon.getText();
- if (str.isEmpty()) {
- System.out.println ("Loi roi");
- } else {
- tfDich.setText(str);
- }
- }
- if (ae.getSource() == btHuy) {
- tfNguon.getText();
- tfDich.getText();
- tfNguon.setText("");
- tfDich.setText("");
- }
- }
- public static void main(String[] args) {
- De2 fr = new De2("De 2 - Form Test");
- fr.setSize(300, 200);
- fr.setVisible(true);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment