java學(xué)生管理系統(tǒng)界面簡單實(shí)現(xiàn)(全)
學(xué)生管理系統(tǒng)簡單的實(shí)現(xiàn),供初學(xué)Java Swing同學(xué)學(xué)習(xí)使用。
import java.awt.Dimension;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
//主類,程序的入口
public class begin
{
public static void main(String[] args)
{
new begindemo("這是我的管理系統(tǒng)");
}
}
class begindemo extends JFrame
{
//登錄的用戶名和密碼
private final String userName = "123";
private final String password = "123";
//聲明屏幕的寬高,程序窗口的寬高
private int windowWidth;
private int windowHeight;
private int screenSizeWidth;
private int screenSizeHeight;
//構(gòu)造函數(shù),
public begindemo(String title)
{
super(title); //設(shè)置標(biāo)題
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //設(shè)置能關(guān)閉窗口
this.setSize(600, 600); //設(shè)置窗口的大小
this.setLayout(null); //設(shè)置程序默認(rèn)布局格式為空,以便于后期自己簡單的設(shè)置布局
this.setResizable(false); //設(shè)置不可縮放
init(); //執(zhí)行初始化函數(shù)(將用戶名密碼等組件加入到面板中)
this.setVisible(true); //使程序可見
}
public void init()
{
//給屏幕的寬度高度,程序窗口的寬度高度賦值
Dimension dimension = Toolkit.getDefaultToolkit().getScreenSize();
screenSizeWidth = (int) dimension.getWidth();
screenSizeHeight = (int) dimension.getHeight();
windowWidth = this.getWidth();
windowHeight = this.getHeight();
//設(shè)置程序窗口的位置為屏幕的正中央
this.setLocation(screenSizeWidth / 2 - windowWidth / 2,
screenSizeHeight / 2 - windowHeight / 2);
// 聲明姓名,密碼的標(biāo)簽
JLabel username_label = new JLabel("姓名");
JLabel password_label = new JLabel("密碼");
// 聲明姓名輸入框和密碼輸入框
final JTextField user_field = new JTextField();
final JPasswordField password_field = new JPasswordField();
//聲明登錄按鈕
JButton login_btn = new JButton("登錄");
//設(shè)置各個(gè)標(biāo)簽和輸入框的大小和位置
username_label.setBounds(150, 100, 100, 50);
password_label.setBounds(150, 200, 100, 50);
user_field.setBounds(200, 100, 300, 50);
password_field.setBounds(200, 200, 300, 50);
login_btn.setBounds(300, 300, 100, 50);
this.add(username_label);
this.add(password_label);
this.add(user_field);
this.add(password_field);
this.add(login_btn);
//登錄按鈕的監(jiān)聽器
login_btn.addActionListener(new ActionListener()
{
@SuppressWarnings("deprecation")
@Override
//當(dāng)按鈕被單擊時(shí)自動(dòng)調(diào)動(dòng)這個(gè)方法
public void actionPerformed(ActionEvent event)
{
//如果用戶名和密碼都是123,那么彈出對話框顯示登錄成功,并且開啟另一個(gè)主框架(主頁)
if (user_field.getText().equals(userName)
&& password_field.getText().equals(password))
{
JOptionPane.showMessageDialog(null, "登錄成功", "Login",
JOptionPane.INFORMATION_MESSAGE);
//聲明主頁
JFrame home_page = new JFrame("主頁");
//給主頁設(shè)置位置
home_page.setLocation(screenSizeWidth / 2 - windowWidth / 2
+ 50, screenSizeHeight / 2 - windowHeight / 2 + 50);
//給主頁設(shè)置大小
home_page.setSize(windowWidth, windowHeight);
//設(shè)置主頁能夠關(guān)閉,并且登錄成功后將登錄頁面隱藏
home_page.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
home_page.setVisible(true);
setVisible(false);//登錄頁面隱藏
} else //反之,登錄不成功,重新登錄
{
JOptionPane.showMessageDialog(null, "登錄失敗,請重新登錄", "Login",
JOptionPane.INFORMATION_MESSAGE);
//設(shè)置輸入框的內(nèi)容為空,讓用戶重新輸入
user_field.setText("");
password_field.setText("");
}
}
});
}
}
添加了一個(gè)學(xué)生的類,方便以后使用
package demo;
import java.awt.Dimension;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
//主類,程序的入口
public class begin
{
public static void main(String[] args)
{
new begindemo("這是我的管理系統(tǒng)");
new student();
}
}
class begindemo extends JFrame
{
//登錄的用戶名和密碼
private final String userName = "123";
private final String password = "123";
//聲明屏幕的寬高,程序窗口的寬高
private int windowWidth;
private int windowHeight;
private int screenSizeWidth;
private int screenSizeHeight;
//構(gòu)造函數(shù),
public begindemo(String title)
{
super(title); //設(shè)置標(biāo)題
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //設(shè)置能關(guān)閉窗口
this.setSize(600, 600); //設(shè)置窗口的大小
this.setLayout(null); //設(shè)置程序默認(rèn)布局格式為空,以便于后期自己簡單的設(shè)置布局
this.setResizable(false); //設(shè)置不可縮放
init(); //執(zhí)行初始化函數(shù)(將用戶名密碼等組件加入到面板中)
this.setVisible(true); //使程序可見
}
public void init()
{
//給屏幕的寬度高度,程序窗口的寬度高度賦值
Dimension dimension = Toolkit.getDefaultToolkit().getScreenSize();
screenSizeWidth = (int) dimension.getWidth();
screenSizeHeight = (int) dimension.getHeight();
windowWidth = this.getWidth();
windowHeight = this.getHeight();
//設(shè)置程序窗口的位置為屏幕的正中央
this.setLocation(screenSizeWidth / 2 - windowWidth / 2,
screenSizeHeight / 2 - windowHeight / 2);
// 聲明姓名,密碼的標(biāo)簽
JLabel username_label = new JLabel("姓名");
JLabel password_label = new JLabel("密碼");
// 聲明姓名輸入框和密碼輸入框
final JTextField user_field = new JTextField();
final JPasswordField password_field = new JPasswordField();
//聲明登錄按鈕
JButton login_btn = new JButton("登錄");
//設(shè)置各個(gè)標(biāo)簽和輸入框的大小和位置
username_label.setBounds(150, 100, 100, 50);
password_label.setBounds(150, 200, 100, 50);
user_field.setBounds(200, 100, 300, 50);
password_field.setBounds(200, 200, 300, 50);
login_btn.setBounds(300, 300, 100, 50);
this.add(username_label);
this.add(password_label);
this.add(user_field);
this.add(password_field);
this.add(login_btn);
//登錄按鈕的監(jiān)聽器
login_btn.addActionListener(new ActionListener()
{
@SuppressWarnings("deprecation")
@Override
//當(dāng)按鈕被單擊時(shí)自動(dòng)調(diào)動(dòng)這個(gè)方法
public void actionPerformed(ActionEvent event)
{
//如果用戶名和密碼都是123,那么彈出對話框顯示登錄成功,并且開啟另一個(gè)主框架(主頁)
if (user_field.getText().equals(userName)
&& password_field.getText().equals(password))
{
JOptionPane.showMessageDialog(null, "登錄成功", "Login",
JOptionPane.INFORMATION_MESSAGE);
//聲明主頁
JFrame home_page = new JFrame("主頁");
//給主頁設(shè)置位置
home_page.setLocation(screenSizeWidth / 2 - windowWidth / 2
+ 50, screenSizeHeight / 2 - windowHeight / 2 + 50);
//給主頁設(shè)置大小
home_page.setSize(windowWidth, windowHeight);
//設(shè)置主頁能夠關(guān)閉,并且登錄成功后將登錄頁面隱藏
home_page.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
home_page.setVisible(true);
setVisible(false);//登錄頁面隱藏
} else //反之,登錄不成功,重新登錄
{
JOptionPane.showMessageDialog(null, "登錄失敗,請重新登錄", "Login",
JOptionPane.INFORMATION_MESSAGE);
//設(shè)置輸入框的內(nèi)容為空,讓用戶重新輸入
user_field.setText("");
password_field.setText("");
}
}
});
}
}
//聲明一個(gè)學(xué)生類,方便以后添加學(xué)生信息用
class student
{
private String name;
private String sex;
private int number; //學(xué)號
private String class_; //班級
private double grade;
//默認(rèn)構(gòu)造函數(shù),new一個(gè)對象的時(shí)候會(huì)自動(dòng)調(diào)用
public student()
{
this.name = "";
this.number = 0;
this.class_ = "";
this.grade = 0;
System.out.println("這是一個(gè)學(xué)生");
}
//重載的構(gòu)造函數(shù)
public student(String name, int number, String class_, double grade)
{
this.name = name;
this.number = number;
this.class_ = class_;
this.grade = grade;
}
//下面是設(shè)置名字性別學(xué)號等的函數(shù),以后在輸入學(xué)生信息存儲(chǔ)的時(shí)候會(huì)調(diào)用,現(xiàn)在先寫出來方便以后調(diào)用
public void setName(String name)
{
this.name = name;
}
public void setSex(String sex)
{
this.sex = sex;
}
public void setNumber(int number)
{
this.number = number;
}
public void setClass(String class_)
{
this.class_ = class_;
}
public void setGrade(double grade)
{
this.grade = grade;
}
//下面是幾個(gè)得到學(xué)生姓名性別等的函數(shù),在以后顯示學(xué)生信息的時(shí)候調(diào)用它來顯示學(xué)生的信息到窗口上。
public String getName()
{
return this.name;
}
public String getSex()
{
return this.sex;
}
public int getNumber()
{
return this.number;
}
public String getClass_()
{
return this.class_;
}
public double getGrade()
{
return this.grade;
}
//和上面的函數(shù)差不多用來一下設(shè)置一個(gè)學(xué)生的所有個(gè)人信息
public void setAll(String name, String sex, int number, String class_,double grade)
{
this.name=name;
this.number=number;
this.sex=sex;
this.class_ = class_;
this.grade = grade;
}
//一下得到一個(gè)學(xué)生的所有信息,就不用一個(gè)一個(gè)getName或者getSex了
public String getAll()
{
String output="";
output+=getName()+" "+getSex()+" "+getNumber()+" "+getClass_()+" "+getGrade();
return output;
}
}
更多學(xué)習(xí)資料請關(guān)注專題《管理系統(tǒng)開發(fā)》。
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- Java+Mysql學(xué)生管理系統(tǒng)源碼
- javaWeb實(shí)現(xiàn)學(xué)生信息管理系統(tǒng)
- Java+MySQL實(shí)現(xiàn)學(xué)生信息管理系統(tǒng)源碼
- java學(xué)生信息管理系統(tǒng)源代碼
- Java?GUI實(shí)現(xiàn)學(xué)生成績管理系統(tǒng)
- java實(shí)現(xiàn)簡單的學(xué)生信息管理系統(tǒng)代碼實(shí)例
- java(swing)+ mysql實(shí)現(xiàn)學(xué)生信息管理系統(tǒng)源碼
- Java基于MySQL實(shí)現(xiàn)學(xué)生管理系統(tǒng)
- 簡單實(shí)現(xiàn)Java版學(xué)生管理系統(tǒng)
- Java實(shí)現(xiàn)簡易學(xué)生管理系統(tǒng)
相關(guān)文章
SpringBoot3整合MyBatis出現(xiàn)異常:Property?'sqlSessionFactory&a
這篇文章主要介紹了SpringBoot3整合MyBatis報(bào)錯(cuò):Property?‘sqlSessionFactory‘?or?‘sqlSessionTemplate‘?are?required,其實(shí)不是個(gè)大問題,只是自己編碼時(shí)遇到了,然后總結(jié)總結(jié)分享一下,如果有遇到類似問題的,可以參考一下2022-11-11
分析xxljob登入功能集成OIDC的統(tǒng)一認(rèn)證
這篇文章主要為大家介紹分析xxljob登入功能集成OIDC的統(tǒng)一認(rèn)證的詳解說明,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步2022-02-02
java使用Base64實(shí)現(xiàn)文件加密解密
這篇文章主要為大家詳細(xì)介紹了java實(shí)現(xiàn)Base64給文件加密、解密,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2019-03-03
Java修改eclipse中web項(xiàng)目的server部署路徑問題
這篇文章主要介紹了Java修改eclipse中web項(xiàng)目的server部署路徑,本文給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2020-11-11
Java基礎(chǔ)知識之CharArrayReader流的使用
這篇文章主要介紹了Java基礎(chǔ)知識之CharArrayReader流的使用,具有很好的參考價(jià)值,希望對大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2021-12-12
java實(shí)現(xiàn)文件斷點(diǎn)續(xù)傳下載功能
這篇文章主要為大家詳細(xì)介紹了java實(shí)現(xiàn)文件斷點(diǎn)續(xù)傳下載功能的具體代碼,感興趣的小伙伴們可以參考一下2016-05-05
druid多數(shù)據(jù)源配置+Datasurce動(dòng)態(tài)切換方式

