package UI;
import DBConnect.Student_DBC;
import java.awt.Color;
import java.awt.FlowLayout;
import javax.swing.Icon ; // 框架底層圖片插入
import javax.swing.ImageIcon ; // 框架內容器中插入圖片和組件一個層面
import java.awt.Font ;
import java.awt.Dimension; //封裝了一個構件的高度和寬度
import java.awt.FlowLayout;
/*
import java.text.SimpleDateFormat ; // 時間
import java.util.Date ;
import javax.swing.Timer;
*/
import javax.swing.JFrame ;
import javax.swing.JPanel ;
import javax.swing.JLabel ;
import javax.swing.JTextField ;
import javax.swing.JPasswordField;
import javax.swing.JButton ;
//
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JOptionPane;
public class Login extends JFrame {
JFrame frame ;
JPanel panel ;
JLabel label1 , label2 , label3 , label4;
JTextField textfield ;
JPasswordField pf ;
JButton button1 , button2 , button3 ;
//Panel底層圖片插入
private Icon p = new ImageIcon("E:\\(2020(后)-2021) Sophomore\\JAVA Project\\ExMgSt_NIIT1_GN4\\src\\IMG_1\\科技\\13.jpg") ;
Login()
{
panel = new JPanel() ;
panel.setSize(2000 , 1500);
panel.setLayout(null); //new FlowLayout(FlowLayout.CENTER)
add(panel) ;
label3 = new JLabel(p) ; //Panel底層圖片插入
label3.setBounds(0, 0, 1000, 900);
label3.setIcon(p);
ImageIcon i = new ImageIcon("E://(2020(后)-2021) Sophomore//JAVA Project//ExMgSt_NIIT1_GN4//src//IMG_1//科技//14.jpg");
label4 = new JLabel(i) ;
label4.setBounds(700, 0, 300, 280);
panel.add(label4) ;
label1 = new JLabel("Login ID") ;
label1.setBounds(40, 250, 300, 60);
panel.add(label1);
Font f1 = new Font("Courier", Font.BOLD,30) ;
label1.setFont(f1);
textfield = new JTextField() ;
textfield.setBounds(200, 250, 400, 60);
Font f6 = new Font("Courier" , Font.BOLD , 18);
textfield.setFont(f6);
panel.add(textfield) ;
label2 = new JLabel("PassWord") ;
label2.setBounds(40, 350, 300, 60);
panel.add(label2) ;
Font f2 = new Font("Courier", Font.BOLD,30) ;
label2.setFont(f2);
pf = new JPasswordField() ;
pf.setBounds(200, 350, 400, 60);
Font f7 = new Font("Courier" , Font.BOLD , 18);
pf.setFont(f7);
panel.add(pf);
button1 = new JButton("Login") ;
button1.setBounds(200, 450, 400, 50);
button1.addActionListener(
new ActionListener()
{
@Override
public void actionPerformed(ActionEvent e) {
String u = textfield.getText();
String p = pf.getText();
//database connection
Student_DBC sd = new Student_DBC() ;
boolean ch = sd.check(u, p ) ;
if(u.equals("leader") && p.equals("leader@nxu"))
{
JOptionPane.showMessageDialog(null , "Login Success To Admin Page !");
// Display Admin Page
Admin ad = new Admin() ;
}
else if(u.equals("") && p.equals(""))
{
JOptionPane.showMessageDialog(null , "Login Success !");
// Display Student Page
Student_SP ss = new Student_SP() ;
}
else if(ch = false)
{
JOptionPane.showMessageDialog(null , "Login Fails ! " + u);
}
else
{
JOptionPane.showMessageDialog(null, "No account, please go to register!");
}
}
}
);
panel.add(button1);
Font f3 = new Font("Courier" , Font.BOLD , 30) ;
button1.setFont(f3);
button2 = new JButton("Student Registration");
button2.setBounds(200, 530, 400, 50);
button2.addActionListener(
new ActionListener()
{
@Override
public void actionPerformed(ActionEvent e)
{
StudentRegister sr = new StudentRegister() ;
dispose();
}
}
);
panel.add(button2) ;
Font f4 = new Font("Courier" , Font.BOLD , 30) ;
button2.setFont(f4);
button3 = new JButton("Exit") ;
button3.setBounds(200, 620, 400, 50);
button3.setBackground(Color.white); // 按鈕背景色
button3.setForeground(Color.orange); // 按鈕里字體顏色
button3.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
WelcomePage inf = new WelcomePage();
dispose();
}
}
);
panel.add(button3) ;
Font f5 = new Font("Courier" , Font.BOLD , 30) ;
button3.setFont(f5);
setTitle("Login Page") ;
setSize(1000 , 900) ;
//setLayout(new FlowLayout(FlowLayout.CENTER )) ;
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE) ;
setLocationRelativeTo(null);
setVisible(true) ;
panel.add(label3) ;
}
public static void main(String[] args) {
Login l = new Login() ;
}
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/232134.html
標籤:Java相關
上一篇:我用的是DBGRID,怎么能讓每次新增的資料,保存后在第一條呢?
下一篇:關于把圖片變成波形
