Belajar Menu dengan icon ( Java)

Posted on Updated on


theprofBelajar Menu dengan icon ( Java) , silahkan copy dan pastekan code berikut … pelajari code code nya ..ini bukan  untuk newbie ..langsung saja rek……..monggo di pelajari ya…seandainya ada kendala monggo di tanyakan ..nanti kita bahas bersama sama…

 

import java.awt.*; //memanggil package yang diperlukan

import java.awt.event.*;

import javax.swing.JFrame;<!--more--></pre>
<div>
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 Rumahsakit 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 Rumahsakit() {

//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);

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 Rumahsakit();

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();

}

});

}

}</div>
<pre>

3 thoughts on “Belajar Menu dengan icon ( Java)

    cahgaulblog said:
    May 30, 2013 at 2:56 pm

    keren gan..
    kebetulan ane jg lagi belajar pemrograman java😀

      mazadie responded:
      May 30, 2013 at 3:03 pm

      silahkah di sedot gan…semoga bermanfaat….

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