0% found this document useful (0 votes)
11 views

Bai 10 Java

This Java code creates a menu bar with File and Edit menus for a frame. The File menu contains Open, Save, and Exit options. The Edit menu contains Copy, Cut, Paste, and an Option submenu with First, Second, and Third menu items.

Uploaded by

aitran.le24
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views

Bai 10 Java

This Java code creates a menu bar with File and Edit menus for a frame. The File menu contains Open, Save, and Exit options. The Edit menu contains Copy, Cut, Paste, and an Option submenu with First, Second, and Third menu items.

Uploaded by

aitran.le24
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

import java.awt.

*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

public class Bai10 extends Frame implements ActionListener {


// Tao menubar
private MenuBar menuBar;

// 2 menu chinh
private Menu file, edit;

// Cac muc con cua cac menu chinh


private MenuItem exit, open, save
, copy, cut, paste, Protected, first, second, third;

// Ham khoi tao


public Bai10(String title) {
super(title);

// Tao thanh menu


menuBar = new MenuBar();

// Dat thanh menu vao giao dien


setMenuBar(menuBar);

// Tao va dat menu chinh View vao thanh menu


file = new Menu("File");
menuBar.add(file);
file.addActionListener(this);

// Tao cac menu con vao menu chinh View


open = new MenuItem("Open");
file.add(open);

save = new MenuItem("Save");


file.add(save);

// Ngan cach
file.addSeparator();

exit = new MenuItem("Exit");


file.add(exit);
exit.addActionListener(this);

// Tao menu chinh Help va dat vao thanh menu


edit = new Menu("Edit");
menuBar.add(edit);
edit.addActionListener(this);

// Tao cac menu con va dat vao menu chinh Help


copy = new MenuItem("Copy");
edit.add(copy);

cut = new MenuItem("Cut");


edit.add(cut);

paste = new MenuItem("Paste");


edit.add(paste);

// option = new MenuItem("Option");


// edit.add(option);

Menu optionSubMenu = new Menu("Option");

first = new MenuItem("First");


optionSubMenu.add(first);

second = new MenuItem("Second");


optionSubMenu.add(second);

third = new MenuItem("Third");


optionSubMenu.add(third);

edit.add(optionSubMenu);

Protected = new MenuItem("Protected");


edit.add(Protected);

// Thiet lap kich thuoc va hien thi Frame


setSize(400, 300);
setVisible(true);

// Khong cho phep thay doi kich thuoc giao dien


setResizable(false);

// Cho phep dung chuot de tat cua so


this.addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
}

@Override
public void actionPerformed(ActionEvent e) {
if (e.getActionCommand().equals("Exit")) {
System.exit(0);
}

public static void main(String[] args) {


new Bai10("Menu");
}
}

You might also like