Dashboard

dashboardFrame = new JFrame();
Util.centeredFrame(dashboardFrame, windowWidth, windowHeight, "Security Management System");
dashboardFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
ImageIcon icon = new ImageIcon("ic_lock_black.png");
dashboardFrame.setIconImage(icon.getImage());
dashboardFrame.setResizable(false);
Container frameContainer = dashboardFrame.getContentPane();
frameContainer.setBackground(Color.orange);
// Changeable According to What size of screen You Want?
int containerWidth = windowWidth*94/100;
int containerHeight = windowHeight*90/100;
int panelWidth = containerWidth*98/100;
int panelHeight = containerHeight*96/100;
int posX = windowWidth / 2 - panelWidth / 2 ;
int posY = windowHeight / 2 - panelHeight / 2 - frameControllerSize / 2;
// frame without control options
JPanel panel = new JPanel();
panel.setLayout(null);//new BorderLayout());
panel.setBackground(Color.decode("#FFFFFF"));
panel.setSize(new Dimension(panelWidth,panelHeight));
panel.setLocation(posX, posY);
frameContainer.add(panel);
After creation of window, we will add a canvas background.
// for Rounded Background
posX = windowWidth / 2 - containerWidth / 2 ;
posY = windowHeight / 2 - containerHeight / 2 - frameControllerSize / 2;
JComponent jcomponent = new RoundedBackground(posX, posY, containerWidth, containerHeight);
jcomponent.setLayout(null);
frameContainer.add(jcomponent, BorderLayout.CENTER);
public class RoundedBackground extends JComponent {
/**
*
*/
private static final long serialVersionUID = 1L;
int width, height,setX,setY;
public RoundedBackground (int setX,int setY,int width, int height) {
this.width=width;
this.height=height;
this.setX=setX;
this.setY=setY;
setSize(width, height);
}
@Override
public void paint(Graphics g) {
Graphics2D g2 = (Graphics2D) g;
g2.setRenderingHint(
RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
g2.setPaint(Color.white);
double x = setX;
double y = setY;
double w = width;
double h = height;
RoundRectangle2D round=new RoundRectangle2D.Double(x, y, w, h, 80, 80);
g2.fill(round);
}
}
public static Connection ConnectDb() {
try
{
Class.forName("org.sqlite.JDBC");
Connection conn = DriverManager.getConnection("jdbc:sqlite:GateSecuritySystem.db");
return conn;
}
catch(Exception e) {
JOptionPane.showMessageDialog(null, e);
return null;
}
}
public static void main(String[] args) {
}
}
// for heading Layout
posY = panelHeight * 2/100;
Font headingFont = new Font("Serif", Font.PLAIN, 25);
// header
JLabel heading_text = new JLabel("Security Management System");
heading_text.setHorizontalAlignment(JLabel.CENTER);
heading_text.setVerticalAlignment(JLabel.CENTER);
heading_text.setBackground(Color.decode("#80c2b2"));
heading_text.setForeground(Color.black);
heading_text.setFont(headingFont);
heading_text.setBounds(0,0, panelWidth, panelHeight / 9);
panel.add(heading_text);
headingFont = new Font("Serif", Font.PLAIN, 15);
JLabel heading_text_minor = new JLabel("Dashboard");
heading_text_minor.setHorizontalAlignment(JLabel.CENTER);
heading_text_minor.setVerticalAlignment(JLabel.CENTER);
heading_text_minor.setBackground(Color.decode("#80c2b2"));
heading_text_minor.setForeground(Color.black);
heading_text_minor.setFont(headingFont);
heading_text_minor.setBounds(0,panelHeight*6/100, panelWidth, panelHeight / 9);
panel.add(heading_text_minor);
panel.add(Util.getSeparator(0, panelHeight / 7, panelWidth, 5,"000000"));
panel.add(Util.getSeparator(0, panelHeight*22/100, panelWidth, 5,"000000"));
headingFont = new Font("Serif", Font.PLAIN, 12);
JLabel admin_text = new JLabel("Hi "+"ADMIN001");
admin_text.setHorizontalAlignment(JLabel.LEFT);
admin_text.setVerticalAlignment(JLabel.CENTER);
admin_text.setBackground(Color.decode("#80c2b2"));
admin_text.setForeground(Color.black);
admin_text.setFont(headingFont);
admin_text.setBounds(panelWidth*2/100,panelHeight*13/100, panelWidth/2, panelHeight / 9);
panel.add(admin_text);
panel.add(getLogoutButton(panelWidth, panelHeight)); padx=32)
we create action layout and add "Add Flat" and "Add Visitor" buttons.
//Action Layout
JPanel actionPanel = new JPanel();
actionPanel.setLayout(null);
actionPanel.setBackground(Color.WHITE);
actionPanel.setBounds(panelWidth*3/4-(panelWidth*45/100)/2,panelHeight*45/100, panelWidth*45/100, panelHeight*35/100);
actionPanel.setBorder(Util.getTitledBorder(16, "Action"));
panel.add(actionPanel,BorderLayout.CENTER);
actionPanel.add(addFlatBtn(panelWidth*45/100, panelHeight));
actionPanel.add(addVisitorBtn(panelWidth*45/100, panelHeight));
Here is UI and logic of go to page add flat when click "Add Flat" Button.
private JButton addFlatBtn(int width, int height) {
JButton addFlatBtn = new JButton(new ImageIcon(((new ImageIcon("desk_bg_1.png")).getImage()).getScaledInstance( height*22/100, height*22/100, java.awt.Image.SCALE_SMOOTH)));
addFlatBtn.setContentAreaFilled(false);
addFlatBtn.setBorder(null);
addFlatBtn.setBounds(width*15/100,(int) height*6/100, height*22/100, height*26/100);
addFlatBtn.setForeground(Color.black);
addFlatBtn.setLayout(null);
addFlatBtn.setOpaque(false);
addFlatBtn.setContentAreaFilled(false);
JLabel text = new JLabel("Add Flat");
text.setHorizontalAlignment(JLabel.CENTER);
text.setVerticalAlignment(JLabel.CENTER);
text.setBackground(Color.decode("#80c2b2"));
text.setForeground(Color.white);
text.setFont(new java.awt.Font("Serif",0, 12));
text.setBounds(0,height*18/100, height*22/100, height*5/100);
addFlatBtn.add(text);
ImageIcon backround_img1 = new ImageIcon("home.png");
Image img1 = backround_img1.getImage();
Image temp_img1 = img1.getScaledInstance(height*12/100, height*12/100, Image.SCALE_SMOOTH);
backround_img1 = new ImageIcon(temp_img1);
JLabel background1 = new JLabel("", backround_img1, JLabel.CENTER);
background1.setBounds((int) (height*5/100),height*5/100, height*12/100, height*12/100);
addFlatBtn.add(background1);
addFlatBtn.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
new AddFlat(Dashboard.width, Dashboard.height,dashboardFrame);
}
});
return addFlatBtn;
}
Here is UI and logic of go to page add visitor when click "Add Visitor" Button.
private JButton addVisitorBtn(int width, int height) {
JButton addVisitor = new JButton(new ImageIcon(((new ImageIcon("desk_bg_1.png")).getImage()).getScaledInstance( height*22/100, height*22/100, java.awt.Image.SCALE_SMOOTH)));
addVisitor.setContentAreaFilled(false);
addVisitor.setBorder(null);
addVisitor.setBounds(width*58/100,(int) height*6/100, height*22/100, height*26/100);
addVisitor.setForeground(Color.black);
addVisitor.setLayout(null);
addVisitor.setOpaque(false);
addVisitor.setContentAreaFilled(false);
JLabel text = new JLabel("Add Visitor");
text.setHorizontalAlignment(JLabel.CENTER);
text.setVerticalAlignment(JLabel.CENTER);
text.setBackground(Color.decode("#80c2b2"));
text.setForeground(Color.white);
text.setFont(new java.awt.Font("Serif",0, 12));
text.setBounds(0,height*18/100, height*22/100, height*5/100);
addVisitor.add(text);
ImageIcon backround_img1 = new ImageIcon("add_student.png");
Image img1 = backround_img1.getImage();
Image temp_img1 = img1.getScaledInstance(height*12/100, height*12/100, Image.SCALE_SMOOTH);
backround_img1 = new ImageIcon(temp_img1);
JLabel background1 = new JLabel("", backround_img1, JLabel.CENTER);
background1.setBounds((int) (height*5/100),height*5/100, height*12/100, height*12/100);
addVisitor.add(background1);
addVisitor.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
new AddVisitor(Dashboard.width, Dashboard.height,dashboardFrame);
}
});
return addVisitor;
}
//
JPanel infoPanel = new JPanel();
infoPanel.setLayout(null);
infoPanel.setBackground(Color.WHITE);
infoPanel.setBounds(panelWidth/40,panelHeight*27/100, panelWidth*45/100, panelHeight*70/100);
infoPanel.setBorder(Util.getTitledBorder(16, "Details"));
panel.add(infoPanel,BorderLayout.CENTER);
infoPanel.add(getVisitorDetail(panelWidth*45/100, panelHeight));
infoPanel.add(getFlatDetail(panelWidth*45/100, panelHeight));
//get Details
getDashboardDetail();
dashboardFrame.setVisible(true);
Here logic for get details from database .
public void getDashboardDetail(){
ArrayList arrayC=new ArrayList<>();
ResultSet rs;
String O_query = "SELECT * FROM 'flat_detail' WHERE flat_status IS 'Occupied'" ;
String V_query = "SELECT * FROM 'flat_detail' WHERE flat_status IS 'Vacant'" ;
String inside_query = "SELECT * FROM 'visitor_detail' WHERE status IS 'IN'" ;
System.out.println(Util.getTodatDate());
String total_visit_query = "SELECT * FROM 'visitor_detail' WHERE entry_time LIKE '%" + Util.getTodatDate() + "%'" ;
Connection conn = MY_DB.ConnectDb();
int count=10;
Statement stat = null;
try {
arrayC.clear();
stat = conn.createStatement();
rs = stat.executeQuery(O_query);
while(rs.next()){
arrayC.add(rs.getString("flat_status"));
}
OccupiedCount.setText(String.valueOf(arrayC.size()));
arrayC.clear();
rs = stat.executeQuery(V_query);
while(rs.next()){
arrayC.add(rs.getString("flat_status"));
}
vacantCount.setText(String.valueOf(arrayC.size()));
arrayC.clear();
rs = stat.executeQuery(inside_query);
while(rs.next()){
arrayC.add(rs.getString("status"));
}
insideCount.setText(String.valueOf(arrayC.size()));
arrayC.clear();
rs = stat.executeQuery(total_visit_query);
while(rs.next()){
arrayC.add(rs.getString("entry_time"));
}
todayVisitCount.setText(String.valueOf(arrayC.size()));
} catch (SQLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
private JPanel getVisitorDetail(int width, int height) {
JPanel infoPanel = new JPanel();
infoPanel.setLayout(null);
infoPanel.setBackground(Color.WHITE);
infoPanel.setBounds( width*5/100,height*3/100,width*90/100, height*32/100);
JLabel headingTv = new JLabel("Visitor Details");
headingTv.setHorizontalAlignment(JLabel.CENTER);
headingTv.setBackground(Color.decode("#80c2b2"));
headingTv.setForeground(Color.black);
headingTv.setFont(new java.awt.Font("Serif",0, 25));
headingTv.setBounds(0,height*2/100, width*90/100, height*5/100);
infoPanel.add(headingTv);
int imgWidth= width*30/100;
int imgHeight=height*18/100;
JButton insideBtn = new JButton(new ImageIcon(((new ImageIcon("count_design_cyan.png")).getImage()).getScaledInstance(imgWidth, imgHeight, java.awt.Image.SCALE_SMOOTH)));
insideBtn.setContentAreaFilled(false);
insideBtn.setBorder(null);
insideBtn.setBounds(width*7/100,(int) height*10/100, imgWidth, imgHeight);
insideBtn.setForeground(Color.black);
insideBtn.setLayout(null);
insideBtn.setOpaque(false);
infoPanel.add(insideBtn,BorderLayout.CENTER);
insideCount = new JLabel("0");
insideCount.setHorizontalAlignment(JLabel.CENTER);
insideCount.setBackground(Color.decode("#80c2b2"));
insideCount.setForeground(Color.black);
insideCount.setFont(new java.awt.Font("Serif",0, 50));
insideCount.setBounds((int) width*6/100,height*1/100, height*12/100, height*12/100);
insideBtn.add(insideCount);
JLabel text = new JLabel("Visitors Inside");
text.setHorizontalAlignment(JLabel.CENTER);
text.setBackground(Color.decode("#80c2b2"));
text.setForeground(Color.black);
text.setFont(new java.awt.Font("Serif",0, 16));
text.setBounds(width*6/100,height*13/100, width*20/100, height*3/100);
insideBtn.add(text);
//// Todays visitors
JButton today = new JButton(new ImageIcon(((new ImageIcon("count_design_voilet.png")).getImage()).getScaledInstance( imgWidth, imgHeight, java.awt.Image.SCALE_SMOOTH)));
today.setContentAreaFilled(false);
today.setBorder(null);
today.setBounds(width*53/100,(int) height*10/100, imgWidth, imgHeight);
today.setForeground(Color.black);
today.setLayout(null);
today.setOpaque(false);
infoPanel.add(today,BorderLayout.CENTER);
todayVisitCount = new JLabel("0");
todayVisitCount.setHorizontalAlignment(JLabel.CENTER);
todayVisitCount.setBackground(Color.decode("#80c2b2"));
todayVisitCount.setForeground(Color.black);
todayVisitCount.setFont(new java.awt.Font("Serif",0, 50));
todayVisitCount.setBounds((int) width*6/100,height*1/100, height*12/100, height*12/100);
today.add(todayVisitCount);
text = new JLabel("Visitors Today");
text.setHorizontalAlignment(JLabel.CENTER);
text.setBackground(Color.decode("#80c2b2"));
text.setForeground(Color.black);
text.setFont(new java.awt.Font("Serif",0, 16));
text.setBounds(width*6/100,height*13/100, width*20/100, height*3/100);
today.add(text);
return infoPanel;
}
private JPanel getFlatDetail(int width, int height) {
JPanel infoPanel = new JPanel();
infoPanel.setLayout(null);
infoPanel.setBackground(Color.WHITE);
infoPanel.setBounds( width*5/100,height*36/100,width*90/100, height*32/100);
JLabel headingTv = new JLabel("Flat Details");
headingTv.setHorizontalAlignment(JLabel.CENTER);
headingTv.setBackground(Color.decode("#80c2b2"));
headingTv.setForeground(Color.black);
headingTv.setFont(new java.awt.Font("Serif",0, 25));
headingTv.setBounds(0,height*2/100, width*90/100, height*5/100);
infoPanel.add(headingTv);
int imgWidth= width*30/100;
int imgHeight=height*18/100;
JButton bookedFlightBtn = new JButton(new ImageIcon(((new ImageIcon("count_design_cream.png")).getImage()).getScaledInstance(imgWidth, imgHeight, java.awt.Image.SCALE_SMOOTH)));
bookedFlightBtn.setContentAreaFilled(false);
bookedFlightBtn.setBorder(null);
bookedFlightBtn.setBounds(width*7/100,(int) height*10/100, imgWidth, imgHeight);
bookedFlightBtn.setForeground(Color.black);
bookedFlightBtn.setLayout(null);
bookedFlightBtn.setOpaque(false);
infoPanel.add(bookedFlightBtn,BorderLayout.CENTER);
vacantCount = new JLabel();
vacantCount.setHorizontalAlignment(JLabel.CENTER);
vacantCount.setBackground(Color.decode("#80c2b2"));
vacantCount.setForeground(Color.black);
vacantCount.setFont(new java.awt.Font("Serif",0, 50));
vacantCount.setBounds((int) width*6/100,height*1/100, height*12/100, height*12/100);
bookedFlightBtn.add(vacantCount);
JLabel text = new JLabel("Flats Vacant");
text.setHorizontalAlignment(JLabel.CENTER);
text.setBackground(Color.decode("#80c2b2"));
text.setForeground(Color.black);
text.setFont(new java.awt.Font("Serif",0, 16));
text.setBounds(width*6/100,height*13/100, width*20/100, height*3/100);
bookedFlightBtn.add(text);
//// Todays visitors
JButton today = new JButton(new ImageIcon(((new ImageIcon("count_design_maroon.png")).getImage()).getScaledInstance( imgWidth, imgHeight, java.awt.Image.SCALE_SMOOTH)));
today.setContentAreaFilled(false);
today.setBorder(null);
today.setBounds(width*53/100,(int) height*10/100, imgWidth, imgHeight);
today.setForeground(Color.black);
today.setLayout(null);
today.setOpaque(false);
infoPanel.add(today,BorderLayout.CENTER);
text = new JLabel("Flats Occupied");
text.setHorizontalAlignment(JLabel.CENTER);
text.setBackground(Color.decode("#80c2b2"));
text.setForeground(Color.black);
text.setFont(new java.awt.Font("Serif",0, 16));
text.setBounds(width*6/100,height*13/100, width*20/100, height*3/100);
today.add(text);
OccupiedCount = new JLabel();
OccupiedCount.setHorizontalAlignment(JLabel.CENTER);
OccupiedCount.setBackground(Color.decode("#80c2b2"));
OccupiedCount.setForeground(Color.black);
OccupiedCount.setFont(new java.awt.Font("Serif",0, 50));
OccupiedCount.setBounds((int) width*6/100,height*1/100, height*12/100, height*12/100);
today.add(OccupiedCount);
return infoPanel;
}
Here is logic of logout when click "LOGOUT" Button and its UI.
private JButton getLogoutButton(int width, int height) {
logoutBtn = new JButton(new ImageIcon(((new ImageIcon("button3.png")).getImage()).getScaledInstance( width*12/100, height*5/100, java.awt.Image.SCALE_SMOOTH)));
logoutBtn.setContentAreaFilled(false);
logoutBtn.setBorder(null);
logoutBtn.setText("LOGOUT");
logoutBtn.setHorizontalTextPosition(JButton.CENTER);
logoutBtn.setVerticalTextPosition(JButton.CENTER);
logoutBtn.setBounds(width*83/100,(int) (height*15.9/100), width*12/100, height*5/100);
logoutBtn.setFont(new java.awt.Font("Serif",0, 10));
logoutBtn.setForeground(Color.white);
logoutBtn.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
moveToLogin();
}
});
return logoutBtn;
}
At last here is logic for move to login page
private void moveToLogin() {
dashboardFrame.dispose();
loginFrame.setVisible(true);
updateisLoginValue("0");
}
public void updateisLoginValue(String updatValue) {
Connection conn=SQLiteJDBCDriverConnection.connect1();
boolean issuccess=false;
Statement stmt = null;
int action;
String newValue = updatValue;
String idToMatch = "IS_LOGINED";
String sqlUpdate = "UPDATE system_setting SET value = ? WHERE key = ?";
PreparedStatement pst = null;
ResultSet rs = null;
try {
pst = conn.prepareStatement(sqlUpdate);
pst.setString(1, newValue);
pst.setString(2, idToMatch);
pst.executeUpdate();
action = pst.executeUpdate();
if(action>0){
issuccess= true;
}else{
issuccess= false;
}
} catch (Exception a) {
a.printStackTrace();
} finally {
if(rs != null){
try{
rs.close();
} catch(Exception e){
e.printStackTrace();
}
}
if(pst != null){
try{
pst.close();
} catch(Exception e){
e.printStackTrace();
}
}
}
}
Programmer Mirta is for learning and training. Projects might be simple to improve learning. Projects are constantly reviewed to avoid errors, but we cannot assure full correctness of all content. While using Programmer Mitra, you agree to have read and accepted our terms of use, cookie and privacy policy.
Copyright 2021 by Programmer Mitra. All Rights Reserved.