package GUI;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
class PerpustakaanFrame extends JFrame implements ActionListener {
private static final int FRAME_WIDTH = 300;
private static final int FRAME_HEIGHT = 250;
private static final int FRAME_X_ORIGIN = 150;
private static final int FRAME_Y_ORIGIN = 250;
private JLabel response;
private JMenu fileMenu;
private JMenu editMenu;
private JMenu viewMenu;
private JMenu helpMenu;
public static void main(String[] args) {
PerpustakaanFrame frame = new PerpustakaanFrame();
frame.setVisible(true);
}
public PerpustakaanFrame() {
Container contentPane;
setTitle("PerpustakaanFrame");
setSize(FRAME_WIDTH, FRAME_HEIGHT);
setResizable(false);
setLocation(FRAME_X_ORIGIN, FRAME_Y_ORIGIN);
contentPane = getContentPane();
contentPane.setLayout(new FlowLayout());
createFileMenu();
createEditMenu();
createViewMenu();
createHelpMenu();
JMenuBar menuBar = new JMenuBar();
setJMenuBar(menuBar);
menuBar.add(fileMenu);
menuBar.add(editMenu);
menuBar.add(viewMenu);
menuBar.add(helpMenu);
setDefaultCloseOperation(EXIT_ON_CLOSE);
}
public void actionPerformed(ActionEvent event) {
String menuName;
menuName = event.getActionCommand();
if (menuName.equals("Quit")) {
System.exit(0);
} else {
response.setText("Menu Item '" + menuName + "' is selected.");
}
}
private void createFileMenu() {
JMenuItem item;
fileMenu = new JMenu("File");
item = new JMenuItem("New"); //Menu Item New
item.addActionListener(this);
fileMenu.add(item);
item = new JMenuItem("Open..."); //Menu Item Open...
item.addActionListener(this);
fileMenu.add(item);
item = new JMenuItem("Save"); //Menu Item Save
item.addActionListener(this);
fileMenu.add(item);
item = new JMenuItem("Save As..."); //Menu Item Save As...
item.addActionListener(this);
fileMenu.add(item);
fileMenu.addSeparator(); //Membuat garis separator
item = new JMenuItem("Quit"); //Menu Item Quit
item.addActionListener(this);
fileMenu.add(item);
}
/**
* Membuat Menu Edit dan Menu Item
*
*/
private void createEditMenu() {
JMenuItem item;
editMenu = new JMenu("Edit");
item = new JMenuItem("Cut"); //Menu Item Cut
item.addActionListener(this);
editMenu.add(item);
item = new JMenuItem("Copy"); //Menu Item Copy
item.addActionListener(this);
editMenu.add(item);
item = new JMenuItem("Paste"); //menu Item Paste
item.addActionListener(this);
editMenu.add(item);
}
private void createViewMenu() {
JMenuItem item;
viewMenu = new JMenu("View");
}
private void createHelpMenu() {
JMenuItem item;
helpMenu = new JMenu("Help");
}
}