Rabu, 12 November 2008

Menu Cantik from Java J2ee

package components;

import javax.swing.JInternalFrame;
import javax.swing.JDesktopPane;
import javax.swing.JMenu;
import javax.swing.JMenuItem;
import javax.swing.JMenuBar;
import javax.swing.JFrame;
import javax.swing.KeyStroke;
import javax.swing.ImageIcon;
import javax.swing.JCheckBoxMenuItem;
import javax.swing.JRadioButtonMenuItem;
import java.awt.event.*;
import java.awt.*;

/*
* InternalFrameDemo.java requires:
* MyInternalFrame.java
*/
class InternalFrameDemo extends JFrame
implements ActionListener {
JDesktopPane desktop;

public InternalFrameDemo() {
super("Dental System");

//Make the big window be indented 50 pixels from each edge
//of the screen.
int inset = 50;
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
setBounds(inset,inset,screenSize.width - inset*2,
screenSize.height - inset*2);

//Set up the GUI.
desktop = new JDesktopPane(); //a specialized layered pane
//createFrame(); //create first "window"
setContentPane(desktop);
setJMenuBar(createMenuBar());

//Make dragging a little faster but perhaps uglier.
desktop.setDragMode(JDesktopPane.OUTLINE_DRAG_MODE);
}

protected JMenuBar createMenuBar() {
JMenuBar menuBar = new JMenuBar();

//Set up the lone menu.
JMenu menu1 = new JMenu("File");
JMenu menu2 = new JMenu("Basic");

menu1.setMnemonic(KeyEvent.VK_F);
menu2.setMnemonic(KeyEvent.VK_B);

menuBar.add(menu1);
menuBar.add(menu2);

//Set up the first menu item.
ImageIcon icon1 = createImageIcon("images/contac.png");
JMenuItem menuItem1 = new JMenuItem("Supplier",icon1);
menuItem1.setMnemonic(KeyEvent.VK_S);
menuItem1.setAccelerator(KeyStroke.getKeyStroke(
KeyEvent.VK_S, ActionEvent.ALT_MASK));
menuItem1.setActionCommand("sup");
menuItem1.addActionListener(this);

ImageIcon icon2 = createImageIcon("images/month.png");
JMenuItem menuItem2 = new JMenuItem("Customer",icon2);
menuItem2.setMnemonic(KeyEvent.VK_C);
menuItem2.setAccelerator(KeyStroke.getKeyStroke(
KeyEvent.VK_C, ActionEvent.ALT_MASK));
menuItem2.setActionCommand("cus");
menuItem2.addActionListener(this);

ImageIcon icon3 = createImageIcon("images/soft32.png");
JMenuItem menuItem3 = new JMenuItem("Quit",icon3);
menuItem3.setMnemonic(KeyEvent.VK_Q);
menuItem3.setAccelerator(KeyStroke.getKeyStroke(
KeyEvent.VK_Q, ActionEvent.ALT_MASK));
menuItem3.setActionCommand("quit");
menuItem3.addActionListener(this);

menu1.add(menuItem1);
menu1.add(menuItem2);
menu1.addSeparator();
menu1.add(menuItem3);

//Set up the second menu item.
ImageIcon icon21 = createImageIcon("images/email16.png");
JMenuItem menuItem21 = new JMenuItem("Data Pasien",icon21);
menuItem21.setMnemonic(KeyEvent.VK_P);
menuItem21.setAccelerator(KeyStroke.getKeyStroke(
KeyEvent.VK_P, ActionEvent.ALT_MASK));
menuItem21.setActionCommand("pas");
menuItem21.addActionListener(this);

menu2.add(menuItem21);

return menuBar;
}

//React to menu selections.
public void actionPerformed(ActionEvent e) {
if ("sup".equals(e.getActionCommand()))
{ // new
// createFrame();
//new MyFrame().setVisible(true);
MyFrame2 f=new MyFrame2();
f.setVisible(true);
desktop.add(f);
}

if ("cus".equals(e.getActionCommand()))
{ // new
MyFrame3 f=new MyFrame3();
f.setVisible(true);
desktop.add(f);
}
if ("pas".equals(e.getActionCommand()))
{ // new
MyFrame4 f=new MyFrame4();
f.setVisible(true);
desktop.add(f);
}

if ("quit".equals(e.getActionCommand()))
{ // new
quit();
}
}


//Create a new internal frame.
protected void createFrame() {
MyInternal frame = new MyInternal();
frame.setVisible(true); //necessary as of 1.3
desktop.add(frame);
try {
frame.setSelected(true);
}
catch (java.beans.PropertyVetoException e) {}
}

//Quit the application.
protected void quit() {
System.exit(0);
}

/** Returns an ImageIcon, or null if the path was invalid. */
protected static ImageIcon createImageIcon(String path) {
java.net.URL imgURL = MenuDemo.class.getResource(path);
if (imgURL != null) {
return new ImageIcon(imgURL);
} else {
System.err.println("Couldn't find file: " + path);
return null;
}
}

/**
* Create the GUI and show it. For thread safety,
* this method should be invoked from the
* event-dispatching thread.
*/
private static void createAndShowGUI() {
//Make sure we have nice window decorations.
JFrame.setDefaultLookAndFeelDecorated(true);

//Create and set up the window.
InternalFrameDemo frame = new InternalFrameDemo();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

//Display the window.
frame.setVisible(true);
}

public static void main(String[] args) {
//Schedule a job for the event-dispatching thread:
//creating and showing this application's GUI.
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
createAndShowGUI();
}
});
}
}

Mengenai Saya

Foto saya
Bekasi, Jawa Barat, Indonesia
eSoft Software product : - Dental Clinic system - General Ledger (Accounting System) - Manufacturing System - Trading system