JPanel
import java.awt.Container;
import java.awt.FlowLayout;
import java.awt.GridLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JTextField;
/**
*
* @author admin
*/
public class MainNo1 extends JFrame {
private static final int FRAME_WIDTH = 500;
private static final int FRAME_HEIGHT = 400;
private static final int FRAME_X_ORIGIN = 150;
private static final int FRAME_Y_ORIGIN = 250;
private JMenu utama1;
private JMenu utama2;
private JMenuItem utama1a, utama1b, utama1c;
private JButton okButton;
private static final int BUTTON_WIDTH = 80;
private static final int BUTTON_HEIGHT = 30;
public MainNo1() {
setTitle("UTS Satu");
setSize(FRAME_WIDTH, FRAME_HEIGHT);
setResizable(false);
setLocation(FRAME_X_ORIGIN, FRAME_Y_ORIGIN);
Container contentPane = getContentPane();
contentPane.setLayout(new FlowLayout());
createpanel1();
createpanel2();
//and add them to the menubar
JLabel input = new JLabel();
input.setText("Input Password:");
JTextField input2 = new JTextField();
input2.setColumns(20);
okButton = new JButton("OK");
okButton.setSize(BUTTON_WIDTH, BUTTON_HEIGHT);
JMenuBar menuBar = new JMenuBar();
setJMenuBar(menuBar);
menuBar.add(utama1);
menuBar.add(utama2);
contentPane.add(input);
contentPane.add(input2);
contentPane.add(okButton);
setDefaultCloseOperation(EXIT_ON_CLOSE);
}
public void quitAction() {
System.exit(0);
}
private void createpanel1() {
utama1 = new JMenu("Utama 1");
utama1a = new JMenuItem("Utama1A");
utama1.add(utama1a);
utama1b = new JMenuItem("Utama1B");
utama1.add(utama1b);
utama1.addSeparator();
utama1c = new JMenuItem("Utama1C");
utama1.add(utama1c);
}
private void createpanel2() {
utama2 = new JMenu("Utama2");
}
}
kelas mainnya :
import java.awt.FlowLayout;
import java.awt.GridLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JTextField;
/**
*
* @author admin
*/
public class MainNo1 extends JFrame {
private static final int FRAME_WIDTH = 500;
private static final int FRAME_HEIGHT = 400;
private static final int FRAME_X_ORIGIN = 150;
private static final int FRAME_Y_ORIGIN = 250;
private JMenu utama1;
private JMenu utama2;
private JMenuItem utama1a, utama1b, utama1c;
private JButton okButton;
private static final int BUTTON_WIDTH = 80;
private static final int BUTTON_HEIGHT = 30;
public MainNo1() {
setTitle("UTS Satu");
setSize(FRAME_WIDTH, FRAME_HEIGHT);
setResizable(false);
setLocation(FRAME_X_ORIGIN, FRAME_Y_ORIGIN);
Container contentPane = getContentPane();
contentPane.setLayout(new FlowLayout());
createpanel1();
createpanel2();
//and add them to the menubar
JLabel input = new JLabel();
input.setText("Input Password:");
JTextField input2 = new JTextField();
input2.setColumns(20);
okButton = new JButton("OK");
okButton.setSize(BUTTON_WIDTH, BUTTON_HEIGHT);
JMenuBar menuBar = new JMenuBar();
setJMenuBar(menuBar);
menuBar.add(utama1);
menuBar.add(utama2);
contentPane.add(input);
contentPane.add(input2);
contentPane.add(okButton);
setDefaultCloseOperation(EXIT_ON_CLOSE);
}
public void quitAction() {
System.exit(0);
}
private void createpanel1() {
utama1 = new JMenu("Utama 1");
utama1a = new JMenuItem("Utama1A");
utama1.add(utama1a);
utama1b = new JMenuItem("Utama1B");
utama1.add(utama1b);
utama1.addSeparator();
utama1c = new JMenuItem("Utama1C");
utama1.add(utama1c);
}
private void createpanel2() {
utama2 = new JMenu("Utama2");
}
}
kelas mainnya :
public static void main(String[] args) {
MainNo1 no1 = new MainNo1();
no1.setVisible(true);
}
}
Komentar