Bài 98: Dialog trong Java AWT

Ngày đăng: 1/2/2023 4:21:44 PM

Khai báo lớp AWT Dialog

1     

public class Dialog extends Window


Ví dụ Dialog trong Java AWT

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23     

24

25

26

27

28

29

30

31

32

33

package vn.viettuts.awt;

 

import java.awt.Button;

import java.awt.Dialog;

import java.awt.FlowLayout;

import java.awt.Frame;

import java.awt.Label;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

 

public class DialogExample {

    private static Dialog dialog;

 

    public DialogExample() {

        Frame frame = new Frame();

        dialog = new Dialog(frame, "Ví dụ Dialog trong Java AWT", true);

        dialog.setLayout(new FlowLayout());

        Button button = new Button("Close");

        button.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent e) {

                DialogExample.dialog.setVisible(false);

            }

        });

        dialog.add(new Label("Click button to close dialog."));

        dialog.add(button);

        dialog.setSize(300, 300);

        dialog.setVisible(true);

    }

 

    public static void main(String args[]) {

        new DialogExample();

    }

}

Kết quả:

Ví dụ Dialog trong Java AWT

Nguồn tin:  viettuts