berikut coding tentang bagaimana caranya membuat menu drop down pada java seperti gambar di bawah ini..
code :
import java.awt.*;
import java.awt.event.*;
public class MainWindow extends Frame {
public MainWindow() {
super("Tugas Kelompok PBO class");
setSize(400, 300);
FileMenu fileMenu = new FileMenu(this);
HelpMenu helpMenu = new HelpMenu(this);
MenuBar mb = new MenuBar();
mb.add(fileMenu);
mb.add(helpMenu);
setMenuBar(mb);
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
exit();
}
});
}
public void exit() {
setVisible(false); // hide the Frame
dispose(); // tell windowing system to free resources
System.exit(0); // exit
}
public static void main(String args[]) {
MainWindow w = new MainWindow();
w.setVisible(true);
}
}
class FileMenu extends Menu implements ActionListener {
MainWindow mw; // who owns us?
public FileMenu(MainWindow m) {
super("Kategori Buku");
mw = m;
MenuItem mi;
add(mi = new MenuItem("Novel"));
mi.addActionListener(this);
add(mi = new MenuItem("Majalah"));
mi.addActionListener(this);
add(mi = new MenuItem("Komik"));
mi.addActionListener(this);
add(mi = new MenuItem("Tabloid"));
mi.addActionListener(this);
}
public void actionPerformed(ActionEvent e) {
String item = e.getActionCommand();
if (item.equals("Exit"))
mw.exit();
else
System.out.println("Selected FileMenu " + item);
}
}
class HelpMenu extends Menu implements ActionListener {
MainWindow mw; // who owns us?
public HelpMenu(MainWindow m) {
super("Anggota Kelompok");
mw = m;
MenuItem mi;
Menu subMenu1 = new Menu("Aritha Handrico");
subMenu1.add(mi = new MenuItem("NIM : 10851001718"));
mi.addActionListener(this);
add(subMenu1);
Menu subMenu2 = new Menu("Yandiko Saputra");
subMenu2.add(mi = new MenuItem("NIM : belum terdaftar"));
mi.addActionListener(this);
add(subMenu2);
Menu subMenu3 = new Menu("Ika Novrita");
subMenu3.add(mi = new MenuItem("NIM : belum terdaftar"));
mi.addActionListener(this);
add(subMenu3);
Menu subMenu4 = new Menu("Nur Alfi Laili");
subMenu4.add(mi = new MenuItem("NIM : belum terdaftar"));
mi.addActionListener(this);
add(subMenu4);
Menu subMenu5 = new Menu("Samsinar");
subMenu5.add(mi = new MenuItem("NIM : 10851001951"));
mi.addActionListener(this);
add(subMenu5);
Menu subMenu6 = new Menu("Tatra Rausyanfikar");
subMenu6.add(mi = new MenuItem("NIM : belum terdaftar"));
mi.addActionListener(this);
add(subMenu6);
add(mi = new MenuItem("Tugas TBO"));
mi.addActionListener(this);
addSeparator();
add(mi = new CheckboxMenuItem("Sangat Bagus"));
mi.addActionListener(this);
add(mi = new CheckboxMenuItem("Bagus"));
mi.addActionListener(this);
add(mi = new CheckboxMenuItem("Bagus Sekali"));
mi.addActionListener(this);
// make a Misc sub menu of Help menu
Menu subMenu = new Menu("Kelas");
subMenu.add(mi = new MenuItem("TIF IV D"));
mi.addActionListener(this);
subMenu.add(mi = new MenuItem("Teknik INformatika"));
mi.addActionListener(this);
add(subMenu);
}
}
0 comments:
Post a Comment