memanggil Jframe dari menu dengan java

Posted on Updated on


web_designskali ini saya akan memposting bagaimana memanggil Jframe dari menu silahkan pelajari lebih lanjut .. ini adalah coding sederhana dalam pemanggilan jframe melalui menu menggunakan metode coder  berikut caranya :

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

itemFsakit.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent e) {

new JFSakit().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 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();

}

});

}

}

 

 

 

 

silahkan di coba semoga bermanfaat …..🙂 happy coding

 

 

 

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