CODE
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.border.*;
import java.awt.Color.*;
import java.util.*;
import java.text.*;
import java.net.URL;
import java.applet.*;
import java.util.Random;
import java.io.*;
import java.awt.geom.*;
import javax.swing.JOptionPane;
import java.lang.*;
class cafas3 extends JFrame implements ActionListener
{
public JLabel lbluser, lblpass, lbl_welcome, dummy1, dummy2;
public JTextField tfuser;
public JPasswordField tfpass;
public JButton btnlogin, btnexit;
public BorderLayout layout;
public Container c;
public JPanel pnlNorth, pnlLogo, pnlLogo1, pnlLogo2, pnlCenter,pnlCenterA, pnlCenter1, pnlCenter2, pnlSouth;
int set;
static AudioClip logoff, logon, reset, error, warning;
Date today = new Date();
SimpleDateFormat sdf = new SimpleDateFormat("hh:mm a, EEEE, dd MM yy");
public cafas3()
{
super ("CAFAS Online Reporting Tool");
set = 0;
c = getContentPane();
layout = new BorderLayout();
c.setLayout(layout);
setResizable(false);
lbluser = new JLabel("USER ID: ",SwingConstants.CENTER);
lblpass = new JLabel("PASSWORD: ",SwingConstants.CENTER);
tfuser = new JTextField(8);
tfpass = new JPasswordField(8);
btnlogin = new JButton("LOGIN");
btnexit = new JButton("EXIT");
btnlogin.addActionListener(this);
btnexit.addActionListener(this);
pnlNorth=new JPanel();
pnlNorth.setLayout(new FlowLayout());
pnlLogo = new JPanel();
pnlLogo.setLayout(new GridLayout(2,2));
pnlLogo1 = new JPanel();
pnlLogo1.setLayout(new FlowLayout());
pnlLogo2 = new JPanel();
pnlLogo2.setLayout(new GridLayout(4,1));
JLabel logo=new JLabel(new ImageIcon ("logo.gif"));
logo.setSize(96,96);
pnlLogo1.add(logo);
JLabel AA = new JLabel("WELCOME",SwingConstants.CENTER);
JLabel BB = new JLabel("TO",SwingConstants.CENTER);
JLabel CC = new JLabel("CAFAS ONLINE REPORTING TOOL ",SwingConstants.CENTER);
JLabel DD = new JLabel(""+sdf.format(today),SwingConstants.CENTER);
AA.setFont(new Font("Comic Sans MS", Font.BOLD,12));
BB.setFont(new Font("Comic Sans MS", Font.BOLD,12));
CC.setFont(new Font("Comic Sans MS", Font.BOLD,12));
AA.setForeground(Color.RED);
BB.setForeground(Color.RED);
CC.setForeground(Color.RED);
pnlLogo2.add(AA);
pnlLogo2.add(BB);
pnlLogo2.add(CC);
pnlLogo2.add(DD);
pnlLogo.add(pnlLogo1);
pnlLogo.add(pnlLogo2);
pnlNorth.add(pnlLogo);
pnlCenter=new JPanel();
pnlCenter.setLayout(new GridLayout(3,2));
pnlCenter.setBorder(new TitledBorder(new EtchedBorder(),""));
JLabel lblKosongC1=new JLabel(" ",SwingConstants.LEFT);
JLabel lblAdmin=new JLabel("* Admin Used Only ",SwingConstants.LEFT);
lblAdmin.setFont(new Font("Comic Sans MS", Font.PLAIN,9));
lblAdmin.setForeground(Color.RED);
pnlCenter.add(lbluser);
pnlCenter.add(tfuser);
pnlCenter.add(lblpass);
pnlCenter.add(tfpass);
pnlCenter.add(lblKosongC1);
pnlCenter.add(lblAdmin);
tfpass.setFont(new Font("Comic Sans MS", Font.BOLD,12));
tfuser.setForeground(Color.RED);
tfpass.setForeground(Color.RED);
pnlSouth=new JPanel();
pnlSouth.setLayout(new GridLayout(3,4));
JLabel lblKosongS1=new JLabel(" ",SwingConstants.LEFT);
JLabel lblKosongS2=new JLabel(" ",SwingConstants.LEFT);
JLabel lblKosongS3=new JLabel(" ",SwingConstants.LEFT);
JLabel lblKosongS4=new JLabel(" ",SwingConstants.LEFT);
JLabel lblKosongS5=new JLabel(" ",SwingConstants.LEFT);
JLabel lblKosongS6=new JLabel(" ",SwingConstants.LEFT);
JLabel lblKosongS7=new JLabel(" ",SwingConstants.LEFT);
JLabel lblKosongS8=new JLabel(" ",SwingConstants.LEFT);
JLabel lblKosongS9=new JLabel(" ",SwingConstants.LEFT);
pnlSouth.add(lblKosongS1);
pnlSouth.add(lblKosongS2);
pnlSouth.add(lblKosongS3);
pnlSouth.add(lblKosongS4);
pnlSouth.add(lblKosongS5);
pnlSouth.add(btnlogin);
pnlSouth.add(btnexit);
pnlSouth.add(lblKosongS6);
pnlSouth.add(lblKosongS7);
pnlSouth.add(lblKosongS8);
pnlLogo1.setBackground(Color.WHITE);
pnlLogo2.setBackground(Color.WHITE);
pnlNorth.setBackground(Color.WHITE);
pnlCenter.setBackground(Color.WHITE);
pnlSouth.setBackground(Color.WHITE);
c.add(pnlNorth,BorderLayout.NORTH);
c.add(pnlCenter,BorderLayout.CENTER);
c.add(pnlSouth,BorderLayout.SOUTH);
setBounds(350,125,300,400);
setVisible(true);
setDefaultCloseOperation(EXIT_ON_CLOSE);
}
public void actionPerformed(ActionEvent e)
{
if (e.getSource() == btnlogin)
{
String passmatch=String.valueOf(tfpass.getPassword());
if (tfuser.getText().equals(""))
{
error.play();
JOptionPane.showConfirmDialog(null, "Please enter USER ID!", "USER ID Error", JOptionPane.DEFAULT_OPTION, JOptionPane.INFORMATION_MESSAGE);
tfuser.requestFocus();
return;
}
else if (passmatch.equals(""))
{
error.play();
JOptionPane.showConfirmDialog(null, "Please enter the password.", "Password Error", JOptionPane.DEFAULT_OPTION, JOptionPane.INFORMATION_MESSAGE);
tfpass.requestFocus();
return;
}
else if (passmatch.equals("admin"))
{
logon.play();
JOptionPane.showMessageDialog(null,"\n\nAdministrator Log On Time: "+sdf.format(today));
Logon L = new Logon();
L.setVisible(true);
this.show(false);
setTitle("Authorized person - "+tfuser.getText());
tfuser.setEditable(false);
tfpass.setEditable(false);
btnlogin.setEnabled(false);
}
else
{
warning.play();
if(set<2)
{
JOptionPane.showConfirmDialog(null, "Unauthorized user - check your user id or password", "Unauthorized User", JOptionPane.DEFAULT_OPTION, JOptionPane.INFORMATION_MESSAGE);
tfuser.setText("");
tfpass.setText("");
tfuser.requestFocus();
set++;
}
else
{
JOptionPane.showConfirmDialog(null, "Unauthorized user - check your user id or password", "Unauthorized User", JOptionPane.DEFAULT_OPTION, JOptionPane.INFORMATION_MESSAGE);
System.exit(0);
}
}
}
if (e.getSource() == btnexit)
{
logoff.play();
if((tfuser.getText().equals("admin")) && (tfpass.getText().equals("admin")))
{
JOptionPane.showMessageDialog(null,"\n\n Administrator Log Off Time: "+sdf.format(today)+"\n\n CAFAS Online Reporting Tool Exit Permanently");
System.exit(0);
}
else
{
JOptionPane.showConfirmDialog(null, "CAFAS Online Reporting Tool Exit Permanently", "Cancel Request", JOptionPane.DEFAULT_OPTION, JOptionPane.INFORMATION_MESSAGE);
System.exit(0);
}
}
}
class Logon extends JFrame implements ActionListener
{
public JLabel lbluserId, lblpassword;
public JTextField tfuser2;
public JPasswordField tfpass2;
public JButton btnOk, btnReset;
public Container cont;
public JPanel pnlnorth, pnlLogo, pnlLogo1, pnlLogo2, pnlcenter, pnlsouth;
int set;
Date today = new Date();;
SimpleDateFormat sdf = new SimpleDateFormat("hh:mm a, EEEE, dd MM yy");
public Logon()
{
super("CAFAS Online Reporting Tool");
BorderLayout layout = new BorderLayout();
cont = getContentPane();
cont.setLayout(layout);
setResizable(false);
lbluserId = new JLabel("USER ID:", SwingConstants.CENTER);
lblpassword = new JLabel("PASSWORD:", SwingConstants.CENTER);
tfuser2 = new JTextField(8);
tfpass2 = new JPasswordField(8);
btnOk = new JButton("OK");
btnReset = new JButton("RESET");
btnOk.addActionListener(this);
btnReset.addActionListener(this);
pnlNorth = new JPanel();
pnlNorth.setLayout(new FlowLayout());
pnlLogo = new JPanel();
pnlLogo.setLayout(new GridLayout(2,2));
pnlLogo1 = new JPanel();
pnlLogo1.setLayout(new FlowLayout());
pnlLogo2 = new JPanel();
pnlLogo2.setLayout(new GridLayout(4,1));
JLabel logo=new JLabel(new ImageIcon ("logo.gif"));
logo.setSize(96,96);
pnlLogo1.add(logo);
JLabel AA = new JLabel("",SwingConstants.CENTER);
JLabel DD = new JLabel(""+sdf.format(today),SwingConstants.CENTER);
AA.setFont(new Font("Comic Sans MS", Font.BOLD,12));
AA.setForeground(Color.RED);
pnlLogo2.add(AA);
pnlLogo2.add(DD);
pnlLogo.add(pnlLogo1);
pnlLogo.add(pnlLogo2);
pnlNorth.add(pnlLogo);
pnlCenter=new JPanel();
pnlCenter.setLayout(new GridLayout(3,2));
pnlCenter.setBorder(new TitledBorder(new EtchedBorder(),""));
JLabel lblKosongC1=new JLabel(" ",SwingConstants.LEFT);
JLabel lblins=new JLabel("* USER ID not more than 8 characters ",SwingConstants.LEFT);
lblins.setFont(new Font("Comic Sans MS", Font.PLAIN,9));
lblins.setForeground(Color.RED);
pnlCenter.add(lbluserId);
pnlCenter.add(tfuser2);
pnlCenter.add(lblpassword);
pnlCenter.add(tfpass2);
pnlCenter.add(lblKosongC1);
pnlCenter.add(lblins);
tfpass.setFont(new Font("Comic Sans MS", Font.BOLD,12));
tfuser.setForeground(Color.RED);
tfpass.setForeground(Color.RED);
pnlSouth=new JPanel();
pnlSouth.setLayout(new GridLayout(3,4));
JLabel lblKosongS1=new JLabel(" ",SwingConstants.LEFT);
JLabel lblKosongS2=new JLabel(" ",SwingConstants.LEFT);
JLabel lblKosongS3=new JLabel(" ",SwingConstants.LEFT);
JLabel lblKosongS4=new JLabel(" ",SwingConstants.LEFT);
JLabel lblKosongS5=new JLabel(" ",SwingConstants.LEFT);
JLabel lblKosongS6=new JLabel(" ",SwingConstants.LEFT);
JLabel lblKosongS7=new JLabel(" ",SwingConstants.LEFT);
JLabel lblKosongS8=new JLabel(" ",SwingConstants.LEFT);
JLabel lblKosongS9=new JLabel(" ",SwingConstants.LEFT);
pnlSouth.add(lblKosongS1);
pnlSouth.add(lblKosongS2);
pnlSouth.add(lblKosongS3);
pnlSouth.add(lblKosongS4);
pnlSouth.add(lblKosongS5);
pnlSouth.add(btnOk);
pnlSouth.add(btnReset);
pnlSouth.add(lblKosongS6);
pnlSouth.add(lblKosongS7);
pnlSouth.add(lblKosongS8);
pnlLogo1.setBackground(Color.WHITE);
pnlLogo2.setBackground(Color.WHITE);
pnlNorth.setBackground(Color.WHITE);
pnlCenter.setBackground(Color.WHITE);
pnlSouth.setBackground(Color.WHITE);
cont.add(pnlNorth,BorderLayout.NORTH);
cont.add(pnlCenter,BorderLayout.CENTER);
cont.add(pnlSouth,BorderLayout.SOUTH);
setBounds(350,125,300,400);
setVisible(true);
setDefaultCloseOperation(EXIT_ON_CLOSE);
}
public void actionPerformed(ActionEvent e)
{
if (e.getSource()==btnOk)
{
String passmatch=String.valueOf(tfpass2.getPassword());
if (tfuser2.getText().equals(""))
{
JOptionPane.showConfirmDialog(null, "Please enter the user Id.", "User Id Error", JOptionPane.DEFAULT_OPTION, JOptionPane.INFORMATION_MESSAGE);
tfuser2.requestFocus();
return;
}
else if (passmatch.equals(""))
{
JOptionPane.showConfirmDialog(null, "Please enter the password.", "Password Error", JOptionPane.DEFAULT_OPTION, JOptionPane.INFORMATION_MESSAGE);
tfpass2.requestFocus();
return;
}
else if ((tfuser2.getText().equals("")) &&(passmatch.equals("")))
{
JOptionPane.showConfirmDialog(null, "Please enter the User Id and Password.","User Id Error", JOptionPane.DEFAULT_OPTION, JOptionPane.INFORMATION_MESSAGE);
tfpass2.requestFocus();
return;
}
else if (passmatch.equals("admin"))
{
JOptionPane.showMessageDialog(null,"\n\nYou Log in as an ADMINISTRATOR on time: "+sdf.format(today));
adminMenu a = new adminMenu();
a.setVisible(true);
this.show(false);
}
else if (passmatch.equals("user"))
{
JOptionPane.showMessageDialog(null,"\n\nYou Log in as USER on time: "+sdf.format(today));
userMenu u = new userMenu();
u.setVisible(true);
this.show(false);
}
else
{
if(set<2)
{
JOptionPane.showConfirmDialog(null, "Unauthorized user - check your login name or password", "Unauthorized User", JOptionPane.DEFAULT_OPTION, JOptionPane.INFORMATION_MESSAGE);
tfuser2.setText("");
tfpass2.setText("");
tfuser2.requestFocus();
set++;
}
else
{
JOptionPane.showConfirmDialog(null, "Unauthorized user - check your login name or password", "Unauthorized User", JOptionPane.DEFAULT_OPTION, JOptionPane.INFORMATION_MESSAGE);
System.exit(0);
}
}
}
if (e.getSource()==btnReset)
{
tfuser2.setText("");
tfpass2.setText("");
tfuser2.setBackground(Color.WHITE);
tfpass2.setBackground(Color.WHITE);
}
}
}
//--------------------------- User Menu ---------------------------------
class userMenu extends JFrame implements ActionListener
{
public JLabel dummy1,dummy2, dummy3, dummy4, lblwelcome;
public Container cont;
public JPanel north,n0,n1,
center,c0;
public BorderLayout layout;
public JButton btndaily, btnweekly, btnmonthly, btnyearly;
Date today = new Date();
SimpleDateFormat sdf = new SimpleDateFormat("hh:mm a, EEEE, dd MM yy");
public userMenu()
{
super("CAFAS Online Reporting Tool - User");
layout = new BorderLayout();
cont = getContentPane();
cont.setLayout(layout);
btndaily = new JButton ("DAILY REPORT");
btndaily.setToolTipText("Daily report section");
btndaily.addActionListener(this);
btnweekly = new JButton ("WEEKLY REPORT");
btnweekly.setToolTipText("Weekly report section");
btnweekly.addActionListener(this);
btnmonthly = new JButton ("MONTHLY REPORT");
btnmonthly.setToolTipText("Monthly report section");
btnmonthly.addActionListener(this);
btnyearly = new JButton ("YEARLY REPORT");
btnyearly.setToolTipText("Yearly report section");
btnyearly.addActionListener(this);
dummy1 = new JLabel();
dummy1.setText(" ");
dummy2 = new JLabel();
dummy2.setText(" ");
dummy3 = new JLabel();
dummy3.setText(" ");
dummy4 = new JLabel();
dummy4.setText(" ");
JLabel DD = new JLabel(""+sdf.format(today),SwingConstants.CENTER);
lblwelcome = new JLabel("PLEASE CHOOSE CATEGORY BELOW:",SwingConstants.CENTER);
//--------------------------- North region ---------------------------------
north = new JPanel();
north.setLayout(new GridLayout(2,1));
n0 = new JPanel();
n0.setLayout(new FlowLayout(FlowLayout.CENTER));
north.add(DD);
//north.add(dummy4);
north.add(lblwelcome);
//--------------------------- Center region ---------------------------------
center = new JPanel();
center.setLayout(new FlowLayout(FlowLayout.CENTER));
center.setBorder(new TitledBorder(new EtchedBorder(),"REPORT SELECTION"));
c0 = new JPanel();
c0.setLayout(new GridLayout(7,1));
c0.add(btndaily);
c0.add(dummy1);
c0.add(btnweekly);
c0.add(dummy2);
c0.add(btnmonthly);
c0.add(dummy3);
c0.add(btnyearly);
center.add(c0);
//------------------------------------------------------------------------------
cont.add(north, BorderLayout.NORTH);
cont.add(center, BorderLayout.CENTER);
setLocation(250,250);
setSize(475,300);
setVisible(true);
setDefaultCloseOperation(EXIT_ON_CLOSE);
}
public void actionPerformed(ActionEvent e)
{
if (e.getSource()==btndaily)
{
//daily d = new daily();
//d.setVisible(true);
//btndaily.setVisible(false);
//this.show(false);
c0.add(lblwelcome);
center.add(c0);
}
if (e.getSource()==btnweekly)
{
//weekly w = new weekly();
//w.setVisible(true);
//btnweekly.setVisible(false);
//this.show(false);
c0.add(lblwelcome);
center.add(c0);
}
if (e.getSource()==btnmonthly)
{
//monthly m = new monthly();
//m.setVisible(true);
//btnmonthly.setVisible(false);
//this.show(false);
c0.add(lblwelcome);
center.add(c0);
}
if (e.getSource()==btnyearly)
{
//yearly y = new yearly();
//y.setVisible(true);
//btnweekly.setVisible(false);
//this.show(false);
c0.add(lblwelcome);
center.add(c0);
}
}
}
//--------------------------- Admin Menu ---------------------------------
class adminMenu extends JFrame implements ActionListener
{
public JLabel dummy1,dummy2, dummy3, dummy4, lblwelcome;
public Container cont;
public JPanel north,n0,n1,
center,c0;
public BorderLayout layout;
public JButton btndaily, btnweekly, btnmonthly, btnyearly;
public JMenu Menudriven,Searchdriven,Helpdriven,Sizedriven;
Date today = new Date();
SimpleDateFormat sdf = new SimpleDateFormat("hh:mm a, EEEE, dd MM yy");
public adminMenu()
{
super("CAFAS Online Reporting Tool - Administrator");
layout = new BorderLayout();
cont = getContentPane();
cont.setLayout(layout);
btndaily = new JButton ("DAILY REPORT");
btndaily.setToolTipText("Daily report section");
btndaily.addActionListener(this);
btnweekly = new JButton ("WEEKLY REPORT");
btnweekly.setToolTipText("Weekly report section");
btnweekly.addActionListener(this);
btnmonthly = new JButton ("MONTHLY REPORT");
btnmonthly.setToolTipText("Monthly report section");
btnmonthly.addActionListener(this);
btnyearly = new JButton ("YEARLY REPORT");
btnyearly.setToolTipText("Yearly report section");
btnyearly.addActionListener(this);
dummy1 = new JLabel();
dummy1.setText(" ");
dummy2 = new JLabel();
dummy2.setText(" ");
dummy3 = new JLabel();
dummy3.setText(" ");
dummy4 = new JLabel();
dummy4.setText(" ");
JLabel DD = new JLabel(""+sdf.format(today),SwingConstants.CENTER);
lblwelcome = new JLabel("PLEASE CHOOSE CATEGORY BELOW:",SwingConstants.CENTER);
//--------------------------- ToolBar region -----------------------------------
createMenuDriven();
createSearchDriven();
createSizeDriven();
createHelpDriven();
JMenuBar menuBar = new JMenuBar();
setJMenuBar(menuBar);
menuBar.add(Menudriven);
menuBar.add(Searchdriven);
menuBar.add(Sizedriven);
menuBar.add(Helpdriven);
Menudriven.setToolTipText("Menu option");
Searchdriven.setToolTipText("Various searching type");
Sizedriven.setToolTipText("Change size of interface");
Helpdriven.setToolTipText("Help center");
//--------------------------- North region ---------------------------------
north = new JPanel();
north.setLayout(new GridLayout(2,1));
n0 = new JPanel();
n0.setLayout(new FlowLayout(FlowLayout.CENTER));
north.add(DD);
//north.add(dummy4);
north.add(lblwelcome);
//--------------------------- Center region ---------------------------------
center = new JPanel();
center.setLayout(new FlowLayout(FlowLayout.CENTER));
center.setBorder(new TitledBorder(new EtchedBorder(),"REPORT SELECTION"));
c0 = new JPanel();
c0.setLayout(new GridLayout(7,1));
c0.add(btndaily);
c0.add(dummy1);
c0.add(btnweekly);
c0.add(dummy2);
c0.add(btnmonthly);
c0.add(dummy3);
c0.add(btnyearly);
center.add(c0);
//------------------------------------------------------------------------------
cont.add(north, BorderLayout.NORTH);
cont.add(center, BorderLayout.CENTER);
setLocation(250,25