Dashboard

//frame with control options
dashboardFrame = new JFrame();
Utils.centeredFrame(dashboardFrame, windowWidth, windowHeight, "Hostel 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.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 class SQLiteJDBCDriverConnection {
/**
* Connect to a sample database
*/
public String rate=null;
public String date=null;
public static Connection connect1() {
try {
// SQLite connection string
Class.forName("org.sqlite.JDBC");
} catch (ClassNotFoundException ex) {
Logger.getLogger(SQLiteJDBCDriverConnection.class.getName()).log(Level.SEVERE, null, ex);
}
String url = "jdbc:sqlite:hostelmanagement.db";
Connection conn = null;
try {
conn = DriverManager.getConnection(url);
} catch (SQLException e) {
System.out.println(e.getMessage());
}
return conn;
}
// for heading Layout
posY = panelHeight * 2/100;
Font headingFont = new Font("Serif", Font.PLAIN, 25);
// header
JLabel heading_text = new JLabel("Hostel 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)); padx=32)
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);
//----------- Total Rooms ------
Connection conn = SQLiteJDBCDriverConnection.connect1();
try {
PreparedStatement insert = conn.prepareStatement("select * from room");
ResultSet rs = insert.executeQuery();
int size =0;
while(rs.next())
{
size++; // get row id
}
total_rooms = String.valueOf(size);
conn.close();
} catch (SQLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
//----------- Total Student ------
conn = SQLiteJDBCDriverConnection.connect1();
try {
PreparedStatement insert = conn.prepareStatement("select * from student");
ResultSet rs = insert.executeQuery();
int size =0;
while(rs.next())
{
size++; // get row id
}
total_student = String.valueOf(size);
conn.close();
} catch (SQLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
//----------- Total Alloted ------
conn = SQLiteJDBCDriverConnection.connect1();
try {
PreparedStatement insert = conn.prepareStatement("select * from room where status IS ?");
insert.setString(1, ("alloted"));
ResultSet rs = insert.executeQuery();
int size =0;
while(rs.next())
{
size++; // get row id
}
total_alloted = String.valueOf(size);
insert = conn.prepareStatement("select * from room where status IS ?");
insert.setString(1, ("vacant"));
ResultSet rs2 = insert.executeQuery();
size =0;
while(rs2.next())
{
size++; // get row id
}
total_vacant = String.valueOf(size);
conn.close();
} catch (SQLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
deskPanel.add(totalRoomDesk(panelWidth, panelHeight, total_rooms));
deskPanel.add(totalStudent(panelWidth, panelHeight, total_student));
deskPanel.add(allotroomDesk(panelWidth, panelHeight, total_alloted));
deskPanel.add(vacantroomDesk(panelWidth, panelHeight, total_vacant));
private JButton totalRoomDesk(int width, int height, String total_rooms) {
int widthBase = height*35/100;
int heightBase = height*18/100;
JButton totalroomBtn = new JButton(new ImageIcon(((new ImageIcon("images/desk_blue.png")).getImage()).getScaledInstance( widthBase, heightBase, java.awt.Image.SCALE_SMOOTH)));
totalroomBtn.setContentAreaFilled(false);
totalroomBtn.setBorder(null);
totalroomBtn.setBounds(width*2/100,(int) height*6/100,widthBase, heightBase);
totalroomBtn.setForeground(Color.black);
totalroomBtn.setLayout(null);
totalroomBtn.setOpaque(false);
totalroomBtn.setContentAreaFilled(false);
JLabel text = new JLabel("Total Rooms");
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);
totalroomBtn.add(text);
roomLabel = new JLabel();
roomLabel.setText(total_rooms);
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);
totalroomBtn.add(roomLabel);
ImageIcon backround_img1 = new ImageIcon("images/hostel_room_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.setBounds((int) (widthBase-heightBase*78/100),height*5/100, heightBase*70/100, heightBase*70/100);
totalroomBtn.add(background1);
return totalroomBtn;
}
private JButton totalStudent(int width, int height, String total_student) {
int widthBase = height*35/100;
int heightBase = height*18/100;
JButton totalstudentBtn = new JButton(new ImageIcon(((new ImageIcon("images/desk_green.png")).getImage()).getScaledInstance( widthBase, heightBase, java.awt.Image.SCALE_SMOOTH)));
totalstudentBtn.setContentAreaFilled(false);
totalstudentBtn.setBorder(null);
totalstudentBtn.setBounds(width*25/100,(int) height*6/100,widthBase, heightBase);
totalstudentBtn.setForeground(Color.black);
totalstudentBtn.setLayout(null);
totalstudentBtn.setOpaque(false);
totalstudentBtn.setContentAreaFilled(false);
JLabel text = new JLabel("Total Students");
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);
totalstudentBtn.add(text);
studentLabel = new JLabel();
studentLabel.setText(total_student);
studentLabel.setBackground(Color.black);
studentLabel.setForeground(Color.white);
studentLabel.setFont(new java.awt.Font("Serif",0, 25));
studentLabel.setBounds(widthBase*10/100,heightBase*40/100, height*22/100, height*5/100);
totalstudentBtn.add(studentLabel);
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.setBounds((int) (widthBase-heightBase*78/100),height*5/100, heightBase*70/100, heightBase*70/100);
totalstudentBtn.add(background1);
return totalstudentBtn;
}
Here is UI for total alloted rooms .
private JButton allotroomDesk(int width, int height, String alloted_rooms) {
int widthBase = height*35/100;
int heightBase = height*18/100;
JButton alottroomBtn = new JButton(new ImageIcon(((new ImageIcon("images/desk_light_blue.png")).getImage()).getScaledInstance( widthBase, heightBase, java.awt.Image.SCALE_SMOOTH)));
alottroomBtn.setContentAreaFilled(false);
alottroomBtn.setBorder(null);
alottroomBtn.setBounds(width*48/100,(int) height*6/100,widthBase, heightBase);
alottroomBtn.setForeground(Color.black);
alottroomBtn.setLayout(null);
alottroomBtn.setOpaque(false);
alottroomBtn.setContentAreaFilled(false);
JLabel text = new JLabel("Total Alloted Rooms");
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);
alottroomBtn.add(text);
allotLabel = new JLabel();
allotLabel.setText(alloted_rooms);
allotLabel.setBackground(Color.black);
allotLabel.setForeground(Color.white);
allotLabel.setFont(new java.awt.Font("Serif",0, 25));
allotLabel.setBounds(widthBase*10/100,heightBase*40/100, height*22/100, height*5/100);
alottroomBtn.add(allotLabel);
ImageIcon backround_img1 = new ImageIcon("images/alloted_room_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.setBounds((int) (widthBase-heightBase*78/100),height*5/100, heightBase*70/100, heightBase*70/100);
alottroomBtn.add(background1);
return alottroomBtn;
}
private JButton vacantroomDesk(int width, int height, String vacant_rooms) {
int widthBase = height*35/100;
int heightBase = height*18/100;
JButton vacroomBtn = new JButton(new ImageIcon(((new ImageIcon("images/desk_orange.png")).getImage()).getScaledInstance( widthBase, heightBase, java.awt.Image.SCALE_SMOOTH)));
vacroomBtn.setContentAreaFilled(false);
vacroomBtn.setBorder(null);
vacroomBtn.setBounds(width*71/100,(int) height*6/100,widthBase, heightBase);
vacroomBtn.setForeground(Color.black);
vacroomBtn.setLayout(null);
vacroomBtn.setOpaque(false);
vacroomBtn.setContentAreaFilled(false);
JLabel text = new JLabel("Total Vacant Rooms");
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);
vacroomBtn.add(text);
vacantLabel = new JLabel();
vacantLabel.setText(vacant_rooms);
vacantLabel.setBackground(Color.black);
vacantLabel.setForeground(Color.white);
vacantLabel.setFont(new java.awt.Font("Serif",0, 25));
vacantLabel.setBounds(widthBase*10/100,heightBase*40/100, height*22/100, height*5/100);
vacroomBtn.add(vacantLabel);
ImageIcon backround_img1 = new ImageIcon("images/vacant_room_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.setBounds((int) (widthBase-heightBase*78/100),height*5/100, heightBase*70/100, heightBase*70/100);
vacroomBtn.add(background1);
return vacroomBtn;
}
Now we create action panel and add Actions UI for Admin. Also set window visibilty.
JPanel actionPanel = new JPanel();
actionPanel.setLayout(null);
actionPanel.setBounds(panelWidth*5/100,panelHeight*57/100, panelWidth*90/100, panelHeight*32/100);
actionPanel.setBorder(Utils.getTitledBorder(16, "Action"));
actionPanel.setBackground(Color.white);
panel.add(actionPanel);
actionPanel.add(addStudentBtn(panelWidth, panelHeight*85/100));
actionPanel.add(alloteRoomBtn(panelWidth, panelHeight*85/100));
actionPanel.add(vacantRoomBtn(panelWidth, panelHeight*85/100));
actionPanel.add(paymentBtn(panelWidth, panelHeight*85/100));
actionPanel.add(searchRoomBtn(panelWidth, panelHeight*85/100));
actionPanel.add(searchStudentBtn(panelWidth, panelHeight*85/100));
// set visible window
dashboardFrame.setVisible(true);
private JButton addStudentBtn(int width, int height) {
JButton addstudentBtn = new JButton(new ImageIcon(((new ImageIcon("images/desk_bg_11.png")).getImage()).getScaledInstance( height*22/100, height*22/100, java.awt.Image.SCALE_SMOOTH)));
addstudentBtn.setContentAreaFilled(false);
addstudentBtn.setBorder(null);
addstudentBtn.setBounds((width*3/100),(int) height*6/100, height*22/100, height*26/100);
addstudentBtn.setForeground(Color.black);
addstudentBtn.setLayout(null);
addstudentBtn.setOpaque(false);
addstudentBtn.setContentAreaFilled(false);
JLabel text = new JLabel("Add Student");
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);
addstudentBtn.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);
addstudentBtn.add(background1);
addstudentBtn.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
new Addstudent(dashboardFrame);
}
});
return addstudentBtn;
}
private JButton alloteRoomBtn(int width, int height) {
JButton allotBtn = new JButton(new ImageIcon(((new ImageIcon("images/desk_bg_11.png")).getImage()).getScaledInstance( height*22/100, height*22/100, java.awt.Image.SCALE_SMOOTH)));
allotBtn.setContentAreaFilled(false);
allotBtn.setBorder(null);
allotBtn.setBounds(((width*90/100)/6)+(width*3/100),(int) height*6/100, height*22/100, height*26/100);
allotBtn.setForeground(Color.black);
allotBtn.setLayout(null);
allotBtn.setOpaque(false);
allotBtn.setContentAreaFilled(false);
JLabel text = new JLabel("Allot Room");
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);
allotBtn.add(text);
ImageIcon backround_img1 = new ImageIcon("images/allote_room.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);
allotBtn.add(background1);
allotBtn.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
new Allotment(dashboardFrame);
}
});
return allotBtn;
}
private JButton vacantRoomBtn(int width, int height) {
JButton vacantBtn = new JButton(new ImageIcon(((new ImageIcon("images/desk_bg_11.png")).getImage()).getScaledInstance( height*22/100, height*22/100, java.awt.Image.SCALE_SMOOTH)));
vacantBtn.setContentAreaFilled(false);
vacantBtn.setBorder(null);
vacantBtn.setBounds(((width*90/100)/6)*2+(width*3/100),(int) height*6/100, height*22/100, height*26/100);
vacantBtn.setForeground(Color.black);
vacantBtn.setLayout(null);
vacantBtn.setOpaque(false);
vacantBtn.setContentAreaFilled(false);
JLabel text = new JLabel("Vacant Room");
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);
vacantBtn.add(text);
ImageIcon backround_img1 = new ImageIcon("images/vacant_room.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);
vacantBtn.add(background1);
vacantBtn.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
new Vacant(dashboardFrame);
}
});
return vacantBtn;
}
Here is UI for Payment Button.
private JButton paymentBtn(int width, int height) {
JButton paymentBtn = new JButton(new ImageIcon(((new ImageIcon("images/desk_bg_11.png")).getImage()).getScaledInstance( height*22/100, height*22/100, java.awt.Image.SCALE_SMOOTH)));
paymentBtn.setContentAreaFilled(false);
paymentBtn.setBorder(null);
paymentBtn.setBounds(((width*90/100)/6)*3+(width*3/100),(int) height*6/100, height*22/100, height*26/100);
paymentBtn.setForeground(Color.black);
paymentBtn.setLayout(null);
paymentBtn.setOpaque(false);
paymentBtn.setContentAreaFilled(false);
JLabel text = new JLabel("Payment");
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);
paymentBtn.add(text);
ImageIcon backround_img1 = new ImageIcon("images/payment.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);
paymentBtn.add(background1);
paymentBtn.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
new Payment(dashboardFrame);
}
});
return paymentBtn;
}
Here is UI of Search room button.
private JButton searchRoomBtn(int width, int height) {
JButton searchroomBtn = new JButton(new ImageIcon(((new ImageIcon("images/desk_bg_11.png")).getImage()).getScaledInstance( height*22/100, height*22/100, java.awt.Image.SCALE_SMOOTH)));
searchroomBtn.setContentAreaFilled(false);
searchroomBtn.setBorder(null);
searchroomBtn.setBounds(((width*90/100)/6)*4+(width*3/100),(int) height*6/100, height*22/100, height*26/100);
searchroomBtn.setForeground(Color.black);
searchroomBtn.setLayout(null);
searchroomBtn.setOpaque(false);
searchroomBtn.setContentAreaFilled(false);
JLabel text = new JLabel("Search Room");
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);
searchroomBtn.add(text);
ImageIcon backround_img1 = new ImageIcon("images/room_search.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);
searchroomBtn.add(background1);
searchroomBtn.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
new Searchroom(dashboardFrame);
}
});
return searchroomBtn;
}
Here is UI of Search Student button.
private JButton searchStudentBtn(int width, int height) {
JButton searchStdBtn = new JButton(new ImageIcon(((new ImageIcon("images/desk_bg_11.png")).getImage()).getScaledInstance( height*22/100, height*22/100, java.awt.Image.SCALE_SMOOTH)));
searchStdBtn.setContentAreaFilled(false);
searchStdBtn.setBorder(null);
searchStdBtn.setBounds(((width*90/100)/6)*5+(width*3/100),(int) height*6/100, height*22/100, height*26/100);
searchStdBtn.setForeground(Color.black);
searchStdBtn.setLayout(null);
searchStdBtn.setOpaque(false);
searchStdBtn.setContentAreaFilled(false);
JLabel text = new JLabel("Search Student");
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);
searchStdBtn.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*5f/100),height*5/100, height*12/100, height*12/100);
searchStdBtn.add(background1);
searchStdBtn.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
new Searchstudent(dashboardFrame);
}
});
return searchStdBtn;
}
At last 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("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
moveToLogin();
}
});
return logoutBtn;
}
private void moveToLogin() {
dashboardFrame.dispose();
loginFrame.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.