Sei sulla pagina 1di 4

Rafael D.

Catain

Final Exam

BSIT III

04/02/16

Application Class
public class library {
public static void main(String[] args) {
log_Instance login = new log_Instance();
login.setVisible(true);
}
}
INSTANCE CLASS
/**
* @(#)log_Instance.java
*
*
* @author
* @version 1.00 2016/3/31
*/
import
import
import
import
import
import
import
import

javax.swing.ImageIcon;
java.awt.image.BufferedImage;
javax.swing.*;
java.awt.*;
java.awt.event.*;
java.awt.Color;
javax.swing.JComboBox;
javax.swing.border.TitledBorder;

public class log_Instance extends JFrame implements ActionListener {


private JFrame frame;
private JLabel lblUsername, lblPassword, lblImage;
private JTextField txtUsername;
private JPasswordField txtPassword;
private JButton btnLogin, btnCancel;
private static JComboBox comboBox;
final int WIDTH = 450;
final int LENGHT = 100;
int ctr= 1;
Color blue = new Color(0x4a, 0x5d, 0x4a);
String uName = "juan";
String pWord = "tamad";
String msg = "";
Font myFont = new Font("Arial", Font.BOLD, 14);

public log_Instance() {
//Set frame layout manager
super("System's Security");
setSize(WIDTH, LENGHT);
setLocation(250,250);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JPanel bg = new JPanel(new FlowLayout());
bg.setBackground(blue);
JPanel gui = new JPanel(new BorderLayout());
gui.setBackground(blue);
JPanel dummyPanel = new JPanel(new GridLayout(0,1,1,1));
dummyPanel.setBackground(blue);
JPanel dummyPanel2 = new JPanel(new GridLayout(0,1,1,1));
dummyPanel2.setBackground(blue);
JPanel labelFields = new JPanel(new BorderLayout(3,2));
labelFields.setBackground(blue);
JPanel labelFieldImage = new JPanel(new BorderLayout(2,2));
labelFieldImage.setBackground(blue);
JPanel labels=new JPanel(new GridLayout(0,1,1,1));
labels.setBackground(blue);
JPanel fields=new JPanel(new GridLayout(0,1,1,1));
fields.setBackground(blue);
JPanel button=new JPanel(new GridLayout(0,1,1,1));
button.setBackground(blue);
lblUsername=new JLabel("Username:");
lblUsername.setHorizontalTextPosition(JLabel.CENTER);
lblUsername.setFont(myFont);
lblUsername.setForeground(Color.white);
lblPassword=new JLabel("Password:");
lblPassword.setHorizontalTextPosition(JLabel.CENTER);
lblPassword.setFont(myFont);
lblPassword.setForeground(Color.white);
txtUsername=new JTextField(20);
txtPassword=new JPasswordField(20);
String[] options = { "Admin", "Librarian", "Student Assistant"};
comboBox = new JComboBox(options);
comboBox.addActionListener(new ActionListener() {
@Override

public void actionPerformed(ActionEvent e) {


// Do something when you select a value
}
});
btnLogin=new JButton("login");
btnLogin.addActionListener(this);
btnCancel=new JButton("Cancel");
btnCancel.addActionListener(this);
labels.add(lblUsername);
labels.add(lblPassword);
fields.add(txtUsername);
fields.add(txtPassword);
//fields.add(comboBox);
button.add(btnCancel);
button.add(btnLogin);
labelFields.add(labels, BorderLayout.WEST);
labelFields.add(fields, BorderLayout.CENTER);
labelFields.add(comboBox, BorderLayout.SOUTH);
labelFields.add(button, BorderLayout.EAST);
gui.add(labelFields, BorderLayout.CENTER);
bg.add(gui);
add(bg);
}
public void actionPerformed(ActionEvent event){
if(event.getSource()==btnLogin){
if(uName.equals(txtUsername.getText())&&pWord.equals(txtPassword.getText())){
JOptionPane.showMessageDialog(null,"Access Granted");
Librarysystem main = new Librarysystem();
main.setVisible(true);
dispose();
}
else{
if(ctr!=3){
JOptionPane.showMessageDialog(null,"Access Denied");
txtUsername.setText("");
txtPassword.setText("");
txtUsername.requestFocus();
ctr+=1;
}
else{

JOptionPane.showMessageDialog(null,"You've reached the


maximum login tries. Goodbye!");
dispose();
}
}
}
if(event.getSource()==btnCancel){
}
}
}

Potrebbero piacerti anche