Dashboard

this.loginFrame = jframe;
loginFrame.setVisible(false);
screenSize = Toolkit.getDefaultToolkit().getScreenSize();
windowWidth = (int) (screenSize.getWidth() *95 /100);
windowHeight = (int) (windowWidth * 56 / 100);
frameControllerSize = (int) (windowHeight * 5.7 / 100);
//frame with control options
dashboardFrame = new JFrame();
Utils.centeredFrame(dashboardFrame, windowWidth, windowHeight, "Bank Management System");
dashboardFrame.setResizable(false);
Container frameContainer = dashboardFrame.getContentPane();
frameContainer.setBackground(Color.gray);
// 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.setOpaque(false);
panel.setBackground(Color.decode("#FFFFFF"));
panel.setSize(new Dimension(panelWidth,panelHeight));
panel.setLocation(posX, posY);
frameContainer.add(panel);
// 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);
Here is our class RoundedBackground:
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);
//g2.setStroke(new BasicStroke(2.0f));
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);
}
}
After creation of window, Here we create Labels and Text Fields.
// for heading Layout
posY = panelHeight * 2/100;
Font headingFont = new Font("Serif", Font.PLAIN, 25);
// header
//borderline = BorderFactory.createLineBorder(Color.black);
JLabel heading_text = new JLabel("Bank 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(Utils.getSeparator(0, panelHeight / 7, panelWidth, 5,"000000"));
panel.add(Utils.getSeparator(0, panelHeight*22/100, panelWidth, 5,"000000"));
headingFont = new Font("Serif", Font.PLAIN, 12);
JLabel admin_text = new JLabel("Hi "+AppConstant.STAFF_NAME);
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));
JPanel deskPanel = new JPanel();
deskPanel.setLayout(null);
deskPanel.setBounds(panelWidth*5/100,panelHeight*22/100, panelWidth*90/100, panelHeight*32/100);
deskPanel.setBorder(null);
deskPanel.setBackground(Color.white);
panel.add(deskPanel);
Here we Define Utils class separator method.
public static JSeparator getSeparator(int x, int y, int width, int height,String color) {
JSeparator jSeparator = new JSeparator();
jSeparator.setBackground(Color.decode("#"+color));
jSeparator.setBorder(null);
jSeparator.setOpaque(false);
jSeparator.setAlignmentX(JSeparator.CENTER_ALIGNMENT);
jSeparator.setBounds(x, y, width, height);
return jSeparator;
}
Here we Define "LOGOUT" Button and its click functionality.
private JButton getLogoutButton(int width, int height) {
logoutBtn = new JButton(new ImageIcon(((new ImageIcon("images/button32.png")).getImage()).getScaledInstance( width*16/100, height*6/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*14/100)+8, width*16/100, height*6/100);
logoutBtn.setFont(new java.awt.Font("Serif",1, 12));
logoutBtn.setForeground(Color.white);
logoutBtn.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
dashboardFrame.dispose();
loginFrame.setVisible(true);
updateisLoginValue("0");
}
});
return logoutBtn;
}
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();
}
}
}
}
So we are done with all frame and now draw Deskframe UI.
# Add Deskframe UI
deskPanel.add(totalbalanceDesk(panelWidth, panelHeight, total_balance));
deskPanel.add(totalCustomer(panelWidth, panelHeight, total_customer));
deskPanel.add(todaysCreditDesk(panelWidth, panelHeight, total_credit));
deskPanel.add(todaysDebitDesk(panelWidth, panelHeight, total_debit));
private JButton totalbalanceDesk(int width, int height, String total_bal) {
int widthBase = height*35/100;
int heightBase = height*18/100;
JButton totalBalanceBtn = new JButton(new ImageIcon(((new ImageIcon("images/desk_blue.png")).getImage()).getScaledInstance( widthBase, heightBase, java.awt.Image.SCALE_SMOOTH)));
totalBalanceBtn.setContentAreaFilled(false);
totalBalanceBtn.setBorder(null);
totalBalanceBtn.setBounds(width*2/100,(int) height*6/100,widthBase, heightBase);
totalBalanceBtn.setForeground(Color.black);
totalBalanceBtn.setLayout(null);
totalBalanceBtn.setOpaque(false);
totalBalanceBtn.setContentAreaFilled(false);
JLabel text = new JLabel("Total Balance");
text.setBackground(Color.black);
text.setForeground(Color.white);
text.setFont(new java.awt.Font("Serif",0, 14));
text.setBounds(widthBase*10/100,heightBase*10/100, height*22/100, height*5/100);
totalBalanceBtn.add(text);
roomLabel = new JLabel();
roomLabel.setText(total_bal);
roomLabel.setBackground(Color.black);
roomLabel.setForeground(Color.white);
roomLabel.setFont(new java.awt.Font("Serif",0, 25));
roomLabel.setBounds(widthBase*10/100,heightBase*40/100, height*22/100, height*5/100);
totalBalanceBtn.add(roomLabel);
ImageIcon backround_img1 = new ImageIcon("images/total_balance.png");
Image img1 = backround_img1.getImage();
Image temp_img1 = img1.getScaledInstance(heightBase*70/100, heightBase*70/100, Image.SCALE_SMOOTH);
backround_img1 = new ImageIcon(temp_img1);
JLabel background1 = new JLabel("", backround_img1, JLabel.CENTER);
// background1.setSize(new Dimension(heightBase*75/100, heightBase*75/100));
background1.setBounds((int) (widthBase-heightBase*78/100),height*5/100, heightBase*70/100, heightBase*70/100);
totalBalanceBtn.add(background1);
return totalBalanceBtn;
}
private JButton totalCustomer(int width, int height, String total_cust) {
int widthBase = height*35/100;
int heightBase = height*18/100;
JButton totalCust = new JButton(new ImageIcon(((new ImageIcon("images/desk_green.png")).getImage()).getScaledInstance( widthBase, heightBase, java.awt.Image.SCALE_SMOOTH)));
totalCust.setContentAreaFilled(false);
totalCust.setBorder(null);
totalCust.setBounds(width*25/100,(int) height*6/100,widthBase, heightBase);
totalCust.setForeground(Color.black);
totalCust.setLayout(null);
totalCust.setOpaque(false);
totalCust.setContentAreaFilled(false);
JLabel text = new JLabel("Total Customer");
text.setBackground(Color.black);
text.setForeground(Color.white);
text.setFont(new java.awt.Font("Serif",0, 14));
text.setBounds(widthBase*10/100,heightBase*10/100, height*22/100, height*5/100);
totalCust.add(text);
customerLabel = new JLabel();
customerLabel.setText(total_cust);
customerLabel.setBackground(Color.black);
customerLabel.setForeground(Color.white);
customerLabel.setFont(new java.awt.Font("Serif",0, 25));
customerLabel.setBounds(widthBase*10/100,heightBase*40/100, height*22/100, height*5/100);
totalCust.add(customerLabel);
ImageIcon backround_img1 = new ImageIcon("images/student_desk.png");
Image img1 = backround_img1.getImage();
Image temp_img1 = img1.getScaledInstance(heightBase*70/100, heightBase*70/100, Image.SCALE_SMOOTH);
backround_img1 = new ImageIcon(temp_img1);
JLabel background1 = new JLabel("", backround_img1, JLabel.CENTER);
// background1.setSize(new Dimension(heightBase*75/100, heightBase*75/100));
background1.setBounds((int) (widthBase-heightBase*78/100),height*5/100, heightBase*70/100, heightBase*70/100);
totalCust.add(background1);
return totalCust;
}
private JButton todaysCreditDesk(int width, int height, String credit) {
int widthBase = height*35/100;
int heightBase = height*18/100;
JButton creditBtn = new JButton(new ImageIcon(((new ImageIcon("images/desk_light_blue.png")).getImage()).getScaledInstance( widthBase, heightBase, java.awt.Image.SCALE_SMOOTH)));
creditBtn.setContentAreaFilled(false);
creditBtn.setBorder(null);
creditBtn.setBounds(width*48/100,(int) height*6/100,widthBase, heightBase);
creditBtn.setForeground(Color.black);
creditBtn.setLayout(null);
creditBtn.setOpaque(false);
creditBtn.setContentAreaFilled(false);
JLabel text = new JLabel("Today's Credit");
text.setBackground(Color.black);
text.setForeground(Color.white);
text.setFont(new java.awt.Font("Serif",0, 14));
text.setBounds(widthBase*10/100,heightBase*10/100, height*22/100, height*5/100);
creditBtn.add(text);
creditLabel = new JLabel();
creditLabel.setText(credit);
creditLabel.setBackground(Color.black);
creditLabel.setForeground(Color.white);
creditLabel.setFont(new java.awt.Font("Serif",0, 25));
creditLabel.setBounds(widthBase*10/100,heightBase*40/100, height*22/100, height*5/100);
creditBtn.add(creditLabel);
ImageIcon backround_img1 = new ImageIcon("images/todays_credit.png");
Image img1 = backround_img1.getImage();
Image temp_img1 = img1.getScaledInstance(heightBase*70/100, heightBase*70/100, Image.SCALE_SMOOTH);
backround_img1 = new ImageIcon(temp_img1);
JLabel background1 = new JLabel("", backround_img1, JLabel.CENTER);
// background1.setSize(new Dimension(heightBase*75/100, heightBase*75/100));
background1.setBounds((int) (widthBase-heightBase*78/100),height*5/100, heightBase*70/100, heightBase*70/100);
creditBtn.add(background1);
return creditBtn;
}
private JButton todaysDebitDesk(int width, int height, String debit) {
int widthBase = height*35/100;
int heightBase = height*18/100;
JButton debitBtn = new JButton(new ImageIcon(((new ImageIcon("images/desk_orange.png")).getImage()).getScaledInstance( widthBase, heightBase, java.awt.Image.SCALE_SMOOTH)));
debitBtn.setContentAreaFilled(false);
debitBtn.setBorder(null);
debitBtn.setBounds(width*71/100,(int) height*6/100,widthBase, heightBase);
debitBtn.setForeground(Color.black);
debitBtn.setLayout(null);
debitBtn.setOpaque(false);
debitBtn.setContentAreaFilled(false);
JLabel text = new JLabel("Today's Debit");
text.setBackground(Color.black);
text.setForeground(Color.white);
text.setFont(new java.awt.Font("Serif",0, 14));
text.setBounds(widthBase*10/100,heightBase*10/100, height*22/100, height*5/100);
debitBtn.add(text);
debitLabel = new JLabel();
debitLabel.setText(debit);
debitLabel.setBackground(Color.black);
debitLabel.setForeground(Color.white);
debitLabel.setFont(new java.awt.Font("Serif",0, 25));
debitLabel.setBounds(widthBase*10/100,heightBase*40/100, height*22/100, height*5/100);
debitBtn.add(debitLabel);
ImageIcon backround_img1 = new ImageIcon("images/todays_debit.png");
Image img1 = backround_img1.getImage();
Image temp_img1 = img1.getScaledInstance(heightBase*70/100, heightBase*70/100, Image.SCALE_SMOOTH);
backround_img1 = new ImageIcon(temp_img1);
JLabel background1 = new JLabel("", backround_img1, JLabel.CENTER);
// background1.setSize(new Dimension(heightBase*75/100, heightBase*75/100));
background1.setBounds((int) (widthBase-heightBase*78/100),height*5/100, heightBase*70/100, heightBase*70/100);
debitBtn.add(background1);
return debitBtn;
}
Here's logic for get data in Deskframe.
total_balance = "";
total_customer = "";
total_credit = "";
total_debit = "";
//----------- Total Balance ------
Connection conn = SQLiteJDBCDriverConnection.connect1();
try {
PreparedStatement insert = conn.prepareStatement("select account_number from customer where status = 'Active'");
ResultSet rs = insert.executeQuery();
int amount = 0;
int size = 0;
while(rs.next()) {
int balance = 0;
int old_credit = 0;
int old_debit = 0;
insert = conn.prepareStatement("SELECT credit FROM statement where account_number IS ?");
insert.setString(1, rs.getString("account_number"));
ResultSet rs2 = insert.executeQuery();
while(rs2.next())
{
old_credit = old_credit + (rs2.getInt("credit"));
}
insert = conn.prepareStatement("SELECT debit FROM statement where account_number IS ?");
insert.setString(1, rs.getString("account_number"));
ResultSet rs3 = insert.executeQuery();
while(rs3.next())
{
old_debit = old_debit + (rs3.getInt("debit"));
}
balance = (old_credit - old_debit);
amount = amount + balance;
// System.out.println(amount);
}
total_balance = String.valueOf(amount);
// System.out.println(total_balance);
// total_balance = String.valueOf(old_credit);
conn.close();
} catch (SQLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
//----------- Total Customer ------
conn = SQLiteJDBCDriverConnection.connect1();
try {
PreparedStatement insert = conn.prepareStatement("select * from customer where status = 'Active'");
ResultSet rs = insert.executeQuery();
int size =0;
while(rs.next())
{
size++; // get row id
}
total_customer = String.valueOf(size);
conn.close();
} catch (SQLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
//----------- Total Credit and debit ------
conn = SQLiteJDBCDriverConnection.connect1();
try {
int old_credit = 0;
int old_debit = 0;
PreparedStatement insert = conn.prepareStatement("select credit from statement where credit_date IS ?");
insert.setString(1, Utils.getDate("yyyy-MM-dd"));
ResultSet rs = insert.executeQuery();
while(rs.next())
{
old_credit = old_credit + (rs.getInt("credit"));
}
total_credit = String.valueOf(old_credit);
insert = conn.prepareStatement("select debit from statement where debit_date IS ?");
insert.setString(1, Utils.getDate("yyyy-MM-dd"));
ResultSet rs2 = insert.executeQuery();
while(rs2.next())
{
old_debit = old_debit + (rs2.getInt("debit"));
}
total_debit = String.valueOf(old_debit);
conn.close();
} catch (SQLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
Now create Actions UI and When Click Action UI to perform Tasks.
JPanel actionPanel = new JPanel();
actionPanel.setLayout(null);
// actionPanel.setAlignmentX();
actionPanel.setBounds(panelWidth*25/100,panelHeight*57/100, panelWidth*50/100, panelHeight*32/100);
actionPanel.setBorder(Utils.getTitledBorder(16, "Action"));
actionPanel.setBackground(Color.white);
panel.add(actionPanel);
actionPanel.add(addCustomerBtn(panelWidth, panelHeight*90/100));
actionPanel.add(transaction(panelWidth, panelHeight*90/100));
actionPanel.add(searchCustomerBtn(panelWidth, panelHeight*90/100));
private JButton addCustomerBtn(int width, int height) {
JButton addcustomerBtn = new JButton(new ImageIcon(((new ImageIcon("images/desk_bg_11.png")).getImage()).getScaledInstance( height*22/100, height*22/100, java.awt.Image.SCALE_SMOOTH)));
addcustomerBtn.setContentAreaFilled(false);
addcustomerBtn.setBorder(null);
addcustomerBtn.setBounds((width*5/100),(int) height*6/100, height*22/100, height*26/100);
addcustomerBtn.setForeground(Color.black);
addcustomerBtn.setLayout(null);
addcustomerBtn.setOpaque(false);
addcustomerBtn.setContentAreaFilled(false);
JLabel text = new JLabel("Create Account");
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);
addcustomerBtn.add(text);
ImageIcon backround_img1 = new ImageIcon("images/add_student.png");
Image img1 = backround_img1.getImage();
Image temp_img1 = img1.getScaledInstance(height*15/100, height*15/100, Image.SCALE_SMOOTH);
backround_img1 = new ImageIcon(temp_img1);
JLabel background1 = new JLabel("", backround_img1, JLabel.CENTER);
background1.setBounds((int) (height*3.8f/100),height*3/100, height*15/100, height*15/100);
addcustomerBtn.add(background1);
addcustomerBtn.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
new AddCustomer(dashboardFrame);
}
});
return addcustomerBtn;
}
private JButton transaction(int width, int height) {
JButton transactionBtn = new JButton(new ImageIcon(((new ImageIcon("images/desk_bg_11.png")).getImage()).getScaledInstance( height*22/100, height*22/100, java.awt.Image.SCALE_SMOOTH)));
transactionBtn.setContentAreaFilled(false);
transactionBtn.setBorder(null);
transactionBtn.setBounds((width*20/100),(int) height*6/100, height*22/100, height*26/100);
transactionBtn.setForeground(Color.black);
transactionBtn.setLayout(null);
transactionBtn.setOpaque(false);
transactionBtn.setContentAreaFilled(false);
JLabel text = new JLabel("Transaction");
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);
transactionBtn.add(text);
ImageIcon backround_img1 = new ImageIcon("images/transaction.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*5f/100),height*5/100, height*12/100, height*12/100);
transactionBtn.add(background1);
transactionBtn.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
new CreditDebit(dashboardFrame);
}
});
return transactionBtn;
}
private JButton searchCustomerBtn(int width, int height) {
JButton searchBtn = new JButton(new ImageIcon(((new ImageIcon("images/desk_bg_11.png")).getImage()).getScaledInstance( height*22/100, height*22/100, java.awt.Image.SCALE_SMOOTH)));
searchBtn.setContentAreaFilled(false);
searchBtn.setBorder(null);
searchBtn.setBounds((width*35/100),(int) height*6/100, height*22/100, height*26/100);
searchBtn.setForeground(Color.black);
searchBtn.setLayout(null);
searchBtn.setOpaque(false);
searchBtn.setContentAreaFilled(false);
JLabel text = new JLabel("Search Customer");
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);
searchBtn.add(text);
ImageIcon backround_img1 = new ImageIcon("images/search_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);
searchBtn.add(background1);
searchBtn.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
new SearchCustomer(dashboardFrame);
}
});
return searchBtn;
}
At last we will manage closing of window
// set visible window
dashboardFrame.setVisible(true);
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.