Membuat menu di Netbeans 7.1

Posted on Updated on


Membuat menu menggunakan java Class di netbeans  …bersamaan dengan mata kuliah OOP ane mempelajri membuat menu dengan menggunakan java class .. sebenarnya dalam coding nya sangat mudah namun seseorang lebih sering menggunakan Menu pada Swing control dari pada dari class ,  namun kelebihan nya tentu saja ada ….hayooo apa…????? cari jha referensinya dari internet pasti ada …..okelah langsung saja kita ke coding nya ….langkah pertama siapkan dulu project nya lalu New class selanjutnya masukan Code berikut ….

package tugas;
import java.awt.*; //memanggil package yang diperlukan
import java.awt.event.*;
import javax.swing.JFrame;
import javax.swing.JMenuBar;
import javax.swing.JMenu;
import javax.swing.JMenuItem;
import javax.swing.ImageIcon;
import javax.swing.KeyStroke;
import javax.swing.JOptionPane;
import javax.swing.JDesktopPane;
import javax.swing.JToolBar;
import javax.swing.JButton;
import javax.swing.JPanel;
public class menu extends JFrame {
private JPanel contentPane; //deklarasi objeck yang diperlukan
private JDesktopPane desktop;
private JMenuBar menuBar;
private JMenu mnuFile,mnuReport;
private JMenuItem itemFklinik;
private JMenuItem itemFsakit;
private JMenuItem itemFpasien;
private JMenuItem itemExit;
private JToolBar toolBar;
private JButton btnpasien;
private JButton btnklinik;
private JButton btnsakit;
private void keluar(){
System.exit(0);
}
public menu() {
//setting panel
contentPane = new JPanel();
contentPane.setLayout(new BorderLayout());
//membuat menu bar
 
menuBar = new JMenuBar();
setJMenuBar(menuBar);
mnuFile = new JMenu("File");
mnuFile.setMnemonic('F');
menuBar.add(mnuFile);
mnuReport = new JMenu("Report");
mnuReport.setMnemonic('R');
menuBar.add(mnuReport);
itemFklinik = new JMenuItem("Tabel Klinik",new ImageIcon("image/menut.jpg"));
itemFklinik.setMnemonic(KeyEvent.VK_K);
itemFklinik.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_K,
ActionEvent.CTRL_MASK));
itemFklinik.setActionCommand("Aksiklinik");
mnuFile.add(itemFklinik);
mnuFile.addSeparator();
itemFsakit = new JMenuItem("Tabel Penyakit",new ImageIcon("image/menut.jpg"));
itemFsakit.setMnemonic(KeyEvent.VK_N);
itemFsakit.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_N,
ActionEvent.CTRL_MASK));
itemFsakit.setActionCommand("Aksisakit");
mnuFile.add(itemFsakit);
itemFsakit.addActionListener(new ActionListener() 
{
public void actionPerformed(ActionEvent e) {
    
new menu().setVisible(true);
}
});
itemFpasien = new JMenuItem("Tabel Pasien",new ImageIcon("image/menut.jpg"));
itemFpasien.setMnemonic(KeyEvent.VK_P);
itemFpasien.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_P,
ActionEvent.CTRL_MASK));
itemFpasien.setActionCommand("Aksipasien");
mnuFile.add(itemFpasien);
mnuFile.addSeparator();
itemExit = new JMenuItem("Exit",new ImageIcon("image/menut.jpg"));
itemExit.setMnemonic(KeyEvent.VK_E);
itemExit.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_E,
ActionEvent.CTRL_MASK));
itemExit.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if (JOptionPane.showConfirmDialog(null,"Apakah Anda yakin akan keluar?","Konfirmasi",JOptionPane.OK_CANCEL_OPTION,JOptionPane.QUESTION_MESSAGE)== JOptionPane.OK_OPTION) {
System.exit(0);}}}); mnuFile.add(itemExit);
//buat toolbar
toolBar = new JToolBar();
btnpasien = new JButton(new ImageIcon("image/office.jpg"));
btnpasien.setSize(20,20);
btnpasien.setToolTipText("Mater data Pasien");
btnpasien.setActionCommand("Aksipasien");
toolBar.add(btnpasien);
btnsakit = new JButton(new ImageIcon("image/furniture.jpg"));
btnsakit.setSize(20,20);
btnsakit.setToolTipText("Master data Penyakit");
btnsakit.setActionCommand("Aksisakit");
toolBar.add(btnsakit);
btnklinik = new JButton(new ImageIcon("image/pda.jpg"));
btnklinik.setSize(20,20);
btnklinik.setToolTipText("Master data Klinik");
btnklinik.setActionCommand("Aksiklinik");
toolBar.add(btnklinik);
//setting frame desktop
desktop = new JDesktopPane();
contentPane.add(toolBar, BorderLayout.NORTH);
contentPane.add(desktop, BorderLayout.CENTER);
setContentPane(contentPane);
// setExtendedState(Frame.NORMAL_BOTH);
 
}
private static void tampilGUI(){
JFrame.setDefaultLookAndFeelDecorated(true);
JFrame frame =new menu();
frame.setTitle("sistem Informasi Rumah Sakit");
frame.setSize(500,500);
frame.setVisible(true);
frame.setExtendedState(frame.MAXIMIZED_BOTH);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public static void main (String [] args){
javax.swing.SwingUtilities.invokeLater(new Runnable (){
public void run () {
tampilGUI();
}
});
}
}



run file









www.mazadie.wordpress.com

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s