Payment

dashboardFrame = new JFrame();
Utils.centeredFrame(dashboardFrame, windowWidth, windowHeight, "Billig System");
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 -frameControllerSize/5 ;
int posY = windowHeight / 2 - panelHeight / 2 - frameControllerSize / 2;
// frame without control options
JPanel panel = new JPanel();
panel.setLayout(null);
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 -frameControllerSize/5 ;
posY = windowHeight / 2 - containerHeight / 2 - frameControllerSize / 2;
JComponent jcomponent = new Background(posX, posY, containerWidth, containerHeight);
jcomponent.setLayout(null);
frameContainer.add(jcomponent, BorderLayout.CENTER);
First we create label for our heading and a panel and its labels .
// for heading Layout
posY = panelHeight * 2/100;
Font headingFont = new Font("Serif", Font.PLAIN, 30);
// header
JLabel heading_text = new JLabel("Payment");
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);
panel.add(Utils.getSeparator(0, panelHeight / 7, panelWidth, 5,"000000"));
JPanel leftside = Utils.createPanel(panelWidth,panelHeight*83/100,new Point(0,panelHeight/6), true,"Attendance");
panel.add(leftside,BorderLayout.CENTER);
leftside.setLayout(null);
//shop name label
shopName=new JLabel();
shopName.setText("Neeraj Store");
shopName.setForeground(Color.black);
shopName.setFont(new Font("Lucida",Font.BOLD,22));
shopName.setHorizontalAlignment(JLabel.CENTER);
shopName.setSize(new Dimension(panelWidth,panelHeight/10));
shopName.setLocation(0, 0);
leftside.add(shopName);
//shop address label
shopAddress=new JLabel();
shopAddress.setText("#109, BTM 4th Stage, Vijaya Bank Layout, Bilekahalli, Bengaluru, Karnataka 560076");
shopAddress.setForeground(Color.black);
shopAddress.setFont(new Font("Lucida",Font.PLAIN,15));
shopAddress.setHorizontalAlignment(JLabel.CENTER);
shopAddress.setSize(new Dimension(panelWidth,panelHeight/10));
shopAddress.setLocation(0, panelHeight/30);
leftside.add(shopAddress);
//shop GST label
shopGst=new JLabel();
shopGst.setText("GSTIN :-GA123654789PA");
shopGst.setForeground(Color.black);
shopGst.setFont(new Font("Lucida",Font.PLAIN,15));
shopGst.setHorizontalAlignment(JLabel.CENTER);
shopGst.setSize(new Dimension(panelWidth,panelHeight/25));
shopGst.setLocation(0, panelHeight/10);
leftside.add(shopGst);
//Staff Id label
staffId=new JLabel();
staffId.setText("Staff Id : "+staffIdString);
staffId.setForeground(Color.black);
staffId.setFont(new Font("Lucida",Font.PLAIN,15));
staffId.setSize(new Dimension(panelWidth/3,panelHeight/10));
staffId.setLocation(30, panelHeight/10);
leftside.add(staffId);
// Contact No label
satffContactNo=new JLabel();
satffContactNo.setText("Contact No : "+getContactNo(staffIdString));
satffContactNo.setForeground(Color.black);
satffContactNo.setFont(new Font("Lucida",Font.PLAIN,15));
satffContactNo.setSize(new Dimension(panelWidth/3,panelHeight/10));
satffContactNo.setLocation(panelWidth*2/3, panelHeight/10);
leftside.add(satffContactNo);
// Staff Name label
staffName=new JLabel();
staffName.setText("Staff Name : "+getStaffName(staffIdString));
staffName.setForeground(Color.black);
staffName.setFont(new Font("Lucida",Font.PLAIN,15));
staffName.setSize(new Dimension(panelWidth/2,panelHeight/10));
staffName.setLocation(30, panelHeight/8);
leftside.add(staffName);
//Payment Mode label
paymentMode=new JLabel();
paymentMode.setText("Payment Mode : "+getPaymentMode(staffIdString));
paymentMode.setForeground(Color.black);
paymentMode.setFont(new Font("Lucida",Font.PLAIN,15));
paymentMode.setSize(new Dimension(panelWidth/2,panelHeight/10));
paymentMode.setLocation(panelWidth*2/3, panelHeight/8);
leftside.add(paymentMode);
leftside.add(Utils.getSeparator(30, panelHeight / 5, panelWidth-60, 5,"000000"));
//Advanvce label
advancelabel=new JLabel();
advancelabel.setText("Advance : -00");
advancelabel.setForeground(Color.black);
advancelabel.setFont(new Font("Lucida",Font.PLAIN,18));
advancelabel.setSize(new Dimension(panelWidth/4,panelHeight/10));
advancelabel.setLocation(panelWidth*3/4, panelHeight*6/10);
leftside.add(advancelabel);
//Pending label
pendinglebel=new JLabel();
pendinglebel.setText("Pending : +00");
pendinglebel.setForeground(Color.black);
pendinglebel.setFont(new Font("Lucida",Font.PLAIN,18));
pendinglebel.setSize(new Dimension(panelWidth/4,panelHeight/10));
pendinglebel.setLocation(panelWidth*3/4, panelHeight*65/100);
leftside.add(pendinglebel);
leftside.add(Utils.getSeparator(30, panelHeight*73/100, panelWidth-60, 5,"000000"));
//Total amount label
totalAmmountText=new JLabel();
totalAmmountText.setText("Total : "+Integer.parseInt(getWorkingHour(staffIdString))*100);
totalAmmountText.setForeground(Color.black);
totalAmmountText.setFont(new Font("Lucida",Font.PLAIN,18));
totalAmmountText.setSize(new Dimension(panelWidth/4,panelHeight/10));
totalAmmountText.setLocation(panelWidth*3/4, panelHeight*71/100);
leftside.add(totalAmmountText);
table = new JTable();
displaylistToTable(table,getTableListData(staffIdString));
table.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
JTableHeader tableHeader21 = table.getTableHeader();
tableHeader21.setDefaultRenderer(new KeepSortIconHeaderRenderer(tableHeader21.getDefaultRenderer()));
JScrollPane pane = new JScrollPane(table);
pane.setLocation(30, panelHeight/4);
pane.setSize(new Dimension(panelWidth-60,panelHeight*3/10));
leftside.add(pane);
dashboardFrame.setVisible(true);
panel.revalidate();
panel.repaint();
Here we retrieve data from database and display in the table. j
public ArrayList getTableListData(String data){
ArrayList staffList=new ArrayList();
ResultSet rs;
String query = "SELECT * FROM staff_data WHERE staff_id LIKE '%" + data + "%'" ;
Connection conn = SQLiteJDBCDriverConnection.connect1();
Statement stat = null;
try {
stat = conn.createStatement();
rs = stat.executeQuery(query);
AttendenceData staffdata;
while(rs.next()){
staffdata=new AttendenceData(rs.getString("staff_id"), rs.getString("staff_name"), rs.getString("staff_email_id"), rs.getString("staff_contact_no"), rs.getString("is_present"),rs.getString("present_date"));
staffList.add(staffdata);
}
} catch (SQLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
return staffList;
}
public void displaylistToTable(JTable table,ArrayList productList){
defaultdataModel=new DefaultTableModel();
Object []row=new Object[4];
defaultdataModel.setColumnIdentifiers(new Object[]{"S.No","Date","Working Hour","Salary",});
Date date = new Date();
SimpleDateFormat formatter = new SimpleDateFormat("dd/MM/yyyy");
String strDate = formatter.format(date);
// display formatted date
row[0]="1.";
row[1]=strDate;
row[2]=getWorkingHour(staffIdString);
row[3]=String.valueOf(100*Integer.parseInt(getWorkingHour(staffIdString)));
defaultdataModel.addRow(row);
defaultdataModel.isCellEditable(0, 0);
table.setModel(defaultdataModel);
DefaultTableCellRenderer centerRenderer = new DefaultTableCellRenderer();
centerRenderer.setHorizontalAlignment( JLabel.CENTER );
table.getColumnModel().getColumn(0).setCellRenderer( centerRenderer );
table.getColumnModel().getColumn(1).setCellRenderer( centerRenderer );
table.getColumnModel().getColumn(2).setCellRenderer( centerRenderer );
table.getColumnModel().getColumn(3).setCellRenderer( centerRenderer );
table.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
table.setRowHeight(30);
}
Some methods which is used to retrieve data.
public String getWorkingHour(String staffId){
String paymentMode="";
ResultSet rs;
String sql = "SELECT working_hour FROM staff_data WHERE staff_id = '"+staffId+"'";
Connection conn = SQLiteJDBCDriverConnection.connect1();
Statement stat = null;
try {
stat = conn.createStatement();
rs = stat.executeQuery(sql);
while(rs.next()){
paymentMode=rs.getString("working_hour");
}
stat.close();
conn.close();
} catch (SQLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
return paymentMode;
}
public String getStaffName(String staffId){
String paymentMode="";
ResultSet rs;
String sql = "SELECT staff_name FROM staff_data WHERE staff_id = '"+staffId+"'";
Connection conn = SQLiteJDBCDriverConnection.connect1();
Statement stat = null;
try {
stat = conn.createStatement();
rs = stat.executeQuery(sql);
while(rs.next()){
paymentMode=rs.getString("staff_name");
}
stat.close();
conn.close();
} catch (SQLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
return paymentMode;
}
public String getContactNo(String staffId){
String paymentMode="";
ResultSet rs;
String sql = "SELECT staff_contact_no FROM staff_data WHERE staff_id = '"+staffId+"'";
Connection conn = SQLiteJDBCDriverConnection.connect1();
Statement stat = null;
try {
stat = conn.createStatement();
rs = stat.executeQuery(sql);
while(rs.next()){
paymentMode=rs.getString("staff_contact_no");
}
stat.close();
conn.close();
} catch (SQLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
return paymentMode;
}
public String getPaymentMode(String staffId){
String paymentMode="";
ResultSet rs;
String sql = "SELECT payment_mode FROM staff_data WHERE staff_id = '"+staffId+"'";
Connection conn = SQLiteJDBCDriverConnection.connect1();
Statement stat = null;
try {
stat = conn.createStatement();
rs = stat.executeQuery(sql);
while(rs.next()){
paymentMode=rs.getString("payment_mode");
}
stat.close();
conn.close();
} catch (SQLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
return paymentMode;
}
At last we will manage closing of window
dashboardFrame.addWindowListener(new java.awt.event.WindowAdapter() {
@Override
public void windowClosing(java.awt.event.WindowEvent windowEvent) {
dashboardFrame.dispose();
staffFrame.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.