VietTuts

Tự Học Lập Trình Online

  • Home
  • Java
  • Servlet
  • JSP
  • Struts2
  • Hibernate
  • Spring
  • MyBatis
  • Java WS
  • C
  • C++
  • C#
  • Python
  • PHP
  • Excel
  • VBA
  • Web
    • JavaScript
    • JQUERY
    • JSON
    • AJAX
    • CSS
    • HTML
    • HTML5
    • Node.js
    • Angular 7
  • SQL
    • MySQL
    • SQL Server
  • Misc
    • Eclipse
    • Phần mềm tiện ích
    • Cấu trúc DL&GT
    • Selenium Test
Java Cơ Bản Các Khái Niệm Java OOPs Java String Xử Lý Ngoại Lệ Các Lớp Lồng Nhau

Java AWT

AWT trong java Xử lý sự kiện Java AWT Button trong Java AWT Label trong Java AWT TextField trong Java AWT TextArea trong Java AWT CheckBox trong Java AWT CheckBoxGroup trong Java AWT Choice trong Java AWT List trong Java AWT Canvas trong Java AWT Scrollbar trong Java AWT MenuItem và Menu trong Java AWT PopupMenu trong Java AWT Panel trong Java AWT Dialog trong Java AWT Toolkit trong Java AWT ActionListener trong Java AWT MouseListener trong Java AWT MouseMotionListener trong Java AWT ItemListener trong Java AWT KeyListener trong Java AWT WindowListener trong Java AWT Close Window trong Java AWT Các lớp Adapter trong Java AWT
Java Swing Java I/O Ví Dụ Java I/O Lập Trình Mạng Với Java Java Date Chuyển Đối Kiểu Dữ Liệu Java Collections Java JDBC Các Tính Năng Mới Trong Java Bài Tập Java Có Lời Giải Câu Hỏi Phỏng Vấn Java
1 / 3
❮ ❯

WindowListener trong Java AWT


KeyListener trong Java AWT
Close Window trong Java AWT

Java WindowListener được gọi bất cứ khi nào bạn thay đổi trạng thái của window. Interface WindowListener thuộc về package java.awt.event. Nó có 7 phương thức.

Các phương thức của interface WindowListener

Interface WindowListener có 7 phương thức được đưa ra như dưới đây.

public abstract void windowActivated(WindowEvent e);
public abstract void windowClosed(WindowEvent e);
public abstract void windowClosing(WindowEvent e);
public abstract void windowDeactivated(WindowEvent e);
public abstract void windowDeiconified(WindowEvent e);
public abstract void windowIconified(WindowEvent e);
public abstract void windowOpened(WindowEvent e);

Nội dung chính

  • Ví dụ về Java WindowListener trong Java AWT

Ví dụ về Java WindowListener trong Java AWT

package vn.viettuts.awt;

import java.awt.Frame;
import java.awt.Label;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;

public class WindowListenerExample1 extends Frame 
        implements WindowListener {
    private Label label;
    public WindowListenerExample1() {
        label = new Label();
        label.setBounds(20, 50, 200, 20);
        addWindowListener(this);
        add(label);
        setSize(400, 400);
        setLayout(null);
        setVisible(true);
    }

    public void windowActivated(WindowEvent arg0) {
        label.setText("activated");
    }

    public void windowClosed(WindowEvent arg0) {
        System.out.println("closed");
    }

    public void windowClosing(WindowEvent arg0) {
        System.out.println("closing");
        dispose();
    }

    public void windowDeactivated(WindowEvent arg0) {
        label.setText("deactivated");
    }

    public void windowDeiconified(WindowEvent arg0) {
        System.out.println("deiconified");
    }

    public void windowIconified(WindowEvent arg0) {
        System.out.println("iconified");
    }

    public void windowOpened(WindowEvent arg0) {
        System.out.println("opened");
    }

    public static void main(String[] args) {
        new WindowListenerExample1();
    }
}

Kết quả:

Ví dụ WindowListener trong Java AWT
KeyListener trong Java AWT
Close Window trong Java AWT

Recent Updates

Xuất dữ liệu ra màn hình console trong JavaCài đặt môi trường JavaJava Swing - Bài tập quản lý sinh viên trong javaLinkedList trong javaArrayList trong javaBài tập java có lời giảiSử dụng Javascript trong HTMLToán tử dấu 2 chấm (::) trong Java 8Lambda Expression - Biểu thức Lambda trong java 8Bài tập Java - Sắp xếp nhanh (Quick Sort) trong JavaBài tập Java - Sắp xếp chèn (Insertion Sort) trong JavaBài tập Java - Sắp xếp nổi bọt (Bubble Sort) trong JavaSắp Tết 2026 Rồi! - Còn bao nhiêu ngày nữa là đến tết 2026?

VietTuts on facebook

Học Lập Trình Online Miễn Phí - VietTuts.Vn
Danh Sách Bài Học

Học Java | Hibernate | Spring
Học Excel | Excel VBA
Học Servlet | JSP | Struts2
Học C | C++ | C#
Học Python
Học SQL

Bài Tập Có Lời Giải

Bài tập Java
Bài tập C
Bài tập C++
Bài tập C#
Bài tập Python
Ví dụ Excel VBA

Câu Hỏi Phỏng Vấn

201 câu hỏi phỏng vấn java
25 câu hỏi phỏng vấn servlet
75 câu hỏi phỏng vấn jsp
52 câu hỏi phỏng vấn Hibernate
70 câu hỏi phỏng vấn Spring
57 câu hỏi phỏng vấn SQL

Scroll back to top

Copyright © 2016 VietTuts.Vn all rights reserved. | Liên hệ | Chính sách - riêng tư | sitemap.html | sitemap_index.xml