import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.ButtonGroup;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JRadioButtonMenuItem;
import javax.swing.text.*;
final class tesFrame extends JFrame {
private JLabel user, pass, welcome;
private JTextField tuser;
protected JPasswordField tpass;
private JButton b1;
public static void main(String[] args) {
tesFrame f = new tesFrame();
f.setSize(300, 300);
f.setTitle("Form Login");
f.setResizable(false);
f.setVisible(true);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.b1.setActionCommand(null);
f.setLocationRelativeTo(null);
}
tesFrame() {
JMenuBar bar = new JMenuBar();
JMenu menu = new JMenu("File ");
JMenu menu1 = new JMenu("Edit ");
JMenu menu2 = new JMenu("View ");
menu.setVisible(true);
menu1.setVisible(true);
menu2.setVisible(true);
JMenuItem menuItem = new JMenuItem("Save ");
menu.add(menuItem);
menuItem = new JMenuItem("Open");
menu.add(menuItem);
menuItem = new JMenuItem("Exit");
menu.add(menuItem);
menuItem = new JMenuItem("Edit ");
menu1.add(menuItem);
menuItem = new JMenuItem("View ");
menu2.add(menuItem);
welcome = new JLabel("WELCOME ");
welcome.setFont(new Font("Georgia", Font.BOLD, 14));
user = new JLabel("Username : ", JLabel.RIGHT);
user.setFont(new Font("Tahoma", Font.BOLD, 11));
pass = new JLabel("Password : ", JLabel.RIGHT);
pass.setFont(new Font("Tahoma", Font.BOLD, 11));
tuser = new JTextField();
tuser.setFont(new Font("Tahoma", Font.PLAIN, 11));
tpass = new JPasswordField();
tpass.setFont(new Font("Tahoma", Font.BOLD, 11));
tpass.setEchoChar('*');
b1 = new JButton("LOGIN");
welcome.setBounds(new Rectangle(100, 45, 250, 30));
user.setBounds(new Rectangle(0, 80, 100, 23));
pass.setBounds(new Rectangle(-5, 110, 100, 23));
tuser.setBounds(new Rectangle(105, 80, 160, 22));
tpass.setBounds(new Rectangle(105, 110, 160, 22));
b1.setBounds(new Rectangle(70, 150, 100, 30));
menu.setBounds(new Rectangle(0, 0, 80, 30));
menu1.setBounds(new Rectangle(50, 0, 50, 30));
menu2.setBounds(new Rectangle(100, 0, 50, 30));
bar.setBounds(new Rectangle(0, 0, 300, 30));
this.getContentPane().setLayout(null);
this.getContentPane().add(welcome, null);
this.getContentPane().add(user, null);
this.getContentPane().add(pass, null);
this.getContentPane().add(tpass, null);
this.getContentPane().add(tuser, null);
this.getContentPane().add(b1, null);
this.getContentPane().add(menu, null);
this.getContentPane().add(menu1,null);
this.getContentPane().add(menu2,null);
this.getContentPane().add(bar, null);
bar.add(menu);
b1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
String puname = tuser.getText();
String ppaswd = tpass.getText();
if (puname.equals("aan") && ppaswd.equals("aan")) {
JOptionPane.showMessageDialog(null, "Selamat Datang");
setTitle("AAN");
tuser.setText("");
tpass.setText("");
tuser.requestFocus();
} else {
JOptionPane.showMessageDialog(null,
"Username dan Password anda salah");
tuser.setText("");
tpass.setText("");
tuser.requestFocus();
}
}
});
bar.add(menu);
bar.add(menu1);
bar.add(menu2);
}
}
Hasilnya :
Tidak ada komentar:
Posting Komentar