學(xué)生登錄界面java代碼 java設(shè)置學(xué)生管理登陸界面

JAVA編程如何實現(xiàn)一個學(xué)生信息管理系統(tǒng)登錄界面?

import java.awt.*;

創(chuàng)新互聯(lián)建站長期為數(shù)千家客戶提供的網(wǎng)站建設(shè)服務(wù),團(tuán)隊從業(yè)經(jīng)驗10年,關(guān)注不同地域、不同群體,并針對不同對象提供差異化的產(chǎn)品和服務(wù);打造開放共贏平臺,與合作伙伴共同營造健康的互聯(lián)網(wǎng)生態(tài)環(huán)境。為洪湖企業(yè)提供專業(yè)的成都網(wǎng)站設(shè)計、成都網(wǎng)站制作,洪湖網(wǎng)站改版等技術(shù)服務(wù)。擁有10年豐富建站經(jīng)驗和眾多成功案例,為您定制開發(fā)。

import java.awt.event.*;

import java.applet.*;

import java.applet.Applet;

import java.io.*;

import javax.xml.parsers.DoumentBuilderFactory;

public class UserPanel extends Applet implents ActionListener

{

Label lblName,lblNumber,lblSex,lblJob,lblText;

TextFiele tfName.tfNumber;

checkbox chMale,chFemale;

TextArea taText;

choice chJob;

Button btnOk,btnDisply;

Panel p1,p2,p3,p4,p5,p6,p7,p8,p9;

String strName,strNumber,strSex,strJob,strText;

public void init()

{

lblName=new Label("姓名");

lblNumber=new Label("身份證號");

lblSex=new Label(" 性別");

lblJob=new Label(" 職業(yè)");

lblText=new Label("個性化宣言 ");

tfName=new TextField(23);

tfNumber =new TextFidle(20);

taText=new TextArea(10,20);

c=new checkboxGroup();

chMale =new checkbox("男",c,true);

chFemale =new checkbox("女",c,false);

chJob =new choice();

chJob.add("學(xué)生");

btnOk=new Button("確定");

btnDisplay=new Button("顯示 ");

p1=new panel();

p2=new panel();

p3=new panel();

p4=new panel();

p5=new panel();

p6=new panel();

p7=new panel(new BorderLayout());

p8=new panel();

p9=new panel(new BorderLayout());

//

p1.add(lblName);

p1.add(tfName);

p2.add(lblNumber);

p2.add(lblNumber);

p3.add(lblSex);

p3.add(chMale);

p3.add(chFemale);

p4.add(lblJob);

p4.add(chJob);

p5.add(p3);

p5.add(p4);

p6.setLayout(new BorderLayout());

p6.add(p1,BorderLayout.NORTH);

p6.add(p2,BorderLayout.CENTER);

p6.add(p5,BorderLayout.SOUTH);

p7.add(lblText,BorderLayout.NORTH);

p7.add(lblText,BorderLayout.CENTER);

p8.setLayout(new FlowLayout(FlowLayout.CENTER,30,10));

p8.add(btnOK);

p8.add(btnDisplay);

p9.add(p6,BorderLayout.NORTH);

p9.add(p7,BorderLayout.CENTER);

p9.add(p8,BorderLayout.SOUTH);

add(p9);

//

btnOK.addActionListener(this);

btnDisplay.addActionListener(this);

btnDisplay.setEnabled(false);

strName=new String();

strNumber=new String();

strSex=new String();

strJob=new String();

strText=new String();

}

public void actionPerformed(ActionEvent evt)

{

string arg =evt.getActionCommand();

//

if(arg.equals("確定"))

{

strName=tfName.getText().trim();

strNumber=tfNumber.getText().trim();

if(chMale.getState() )

strSex="男";

else

strSex="女";

strJob=chJob.getselectedItem();

strText=taText.getText().trim();

try

{

//

DoumentBuildFactory dbf=DocumentBuilderFactory.newInstance();

db=dbf.newDocumentBuilder();

Doument doc=db.newDoument();

//

Element root=doc.CreateElement("UserDAta");

Element eName=doc.createElement("Name");

Element eNumber=doc.createElement("Number");

Element eJob=doc.createElement("Job");

Element eText=doc.createElement("Text");

//

root.appendChild(eName);

root.appendChild(eNumber);

root.appendChild(eSex);

root.appendChild(eJob);

root.appendChild(eText);

//

eName.appendChild(doc.creatTextNode("\n" strName "\n") );

eNumber.appendChild(doc.creatTextNode("\n" strNumber "\n") );

eSex.appendChild(doc.creatTextNode("\n" strSex "\n") );

eJob.appendChild(doc.creatTextNode("\n" strJob "\n") );

eText.appendChild(doc.creatTextNode("\n" strText "\n") );

//

File f=new File("user.xml");

FileOutputStream fOut=new FileOutStream(f);

//

fOut.write("

如何用java做登錄界面

import javax.swing.JFrame;//框架

import javax.swing.JPanel;//面板

import javax.swing.JButton;//按鈕

import javax.swing.JLabel;//標(biāo)簽

import javax.swing.JTextField;//文本框

import java.awt.Font;//字體

import java.awt.Color;//顏色

import javax.swing.JPasswordField;//密碼框

import java.awt.event.ActionListener;//事件監(jiān)聽

import java.awt.event.ActionEvent;//事件處理

import javax.swing.JOptionPane;//消息窗口public class UserLogIn extends JFrame{

public JPanel pnluser;

public JLabel lbluserLogIn;

public JLabel lbluserName;

public JLabel lbluserPWD;

public JTextField txtName;

public JPasswordField pwdPwd;

public JButton btnSub;

public JButton btnReset;

public UserLogIn(){

pnluser = new JPanel();

lbluserLogIn = new JLabel();

lbluserName = new JLabel();

lbluserPWD = new JLabel();

txtName = new JTextField();

pwdPwd = new JPasswordField();

btnSub = new JButton();

btnReset = new JButton();

userInit();

}

public void userInit(){

this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);//設(shè)置關(guān)閉框架的同時結(jié)束程序

this.setSize(300,200);//設(shè)置框架大小為長300,寬200

this.setResizable(false);//設(shè)置框架不可以改變大小

this.setTitle("用戶登錄");//設(shè)置框架標(biāo)題

this.pnluser.setLayout(null);//設(shè)置面板布局管理

this.pnluser.setBackground(Color.cyan);//設(shè)置面板背景顏色

this.lbluserLogIn.setText("用戶登錄");//設(shè)置標(biāo)簽標(biāo)題

this.lbluserLogIn.setFont(new Font("宋體",Font.BOLD | Font.ITALIC,14));//設(shè)置標(biāo)簽字體

this.lbluserLogIn.setForeground(Color.RED);//設(shè)置標(biāo)簽字體顏色

this.lbluserName.setText("用戶名:");

this.lbluserPWD.setText("密 碼:");

this.btnSub.setText("登錄");

this.btnReset.setText("重置");

this.lbluserLogIn.setBounds(120,15,60,20);//設(shè)置標(biāo)簽x坐標(biāo)120,y坐標(biāo)15,長60,寬20

this.lbluserName.setBounds(50,55,60,20);

this.lbluserPWD.setBounds(50,85,60,25);

this.txtName.setBounds(110,55,120,20);

this.pwdPwd.setBounds(110,85,120,20);

this.btnSub.setBounds(85,120,60,20);

this.btnSub.addActionListener(new ActionListener()//匿名類實現(xiàn)ActionListener接口

{

public void actionPerformed(ActionEvent e){

btnsub_ActionEvent(e);

}

}

);

this.btnReset.setBounds(155,120,60,20);

this.btnReset.addActionListener(new ActionListener()//匿名類實現(xiàn)ActionListener接口

{

public void actionPerformed(ActionEvent e){

btnreset_ActionEvent(e);

}

}

);

this.pnluser.add(lbluserLogIn);//加載標(biāo)簽到面板

this.pnluser.add(lbluserName);

this.pnluser.add(lbluserPWD);

this.pnluser.add(txtName);

this.pnluser.add(pwdPwd);

this.pnluser.add(btnSub);

this.pnluser.add(btnReset);

this.add(pnluser);//加載面板到框架

this.setVisible(true);//設(shè)置框架可顯

}

public void btnsub_ActionEvent(ActionEvent e){

String name = txtName.getText();

String pwd = String.valueOf(pwdPwd.getPassword());

if(name.equals("")){

JOptionPane.showMessageDialog(null,"賬號不能為空","錯誤",JOptionPane.ERROR_MESSAGE);

return;

}else if (pwd.equals("")){

JOptionPane.showMessageDialog(null,"密碼不能為空","錯誤",JOptionPane.ERROR_MESSAGE);

return;

}else if(true){

this.dispose();

}else{

JOptionPane.showMessageDialog(null,"賬號或密碼錯誤","錯誤",JOptionPane.ERROR_MESSAGE);

return;

}

}

public void btnreset_ActionEvent(ActionEvent e){

txtName.setText("");

pwdPwd.setText("");

}

public static void main(String[] args){

new UserLogIn();

}

}

登錄界面的java代碼,分別有教師登錄,管理員登錄,學(xué)生登錄,右邊是用戶名和密碼,見圖。

分三個包,自己建個包,導(dǎo)進(jìn)去就ok了,數(shù)據(jù)庫是access的。

package 登錄;

import java.awt.EventQueue;

public class Cilent {

private JFrame frame;

private JTextField textField;

private JPasswordField passwordField;

/**

* Launch the application.

*/

public static void main(String[] args) {

EventQueue.invokeLater(new Runnable() {

public void run() {

try {

Cilent window = new Cilent();

window.frame.setVisible(true);

} catch (Exception e) {

e.printStackTrace();

}

}

});

}

/**

* Create the application.

*/

public Cilent() {

initialize();

}

/**

* Initialize the contents of the frame.

*/

private void initialize() {

frame = new JFrame();

frame.setTitle("登陸界面");

frame.setBounds(100, 100, 450, 300);

frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

frame.getContentPane().setLayout(null);

frame.setResizable(false);

JLabel lblNewLabel = new JLabel("用戶名");

lblNewLabel.setBounds(38, 43, 80, 34);

frame.getContentPane().add(lblNewLabel);

textField = new JTextField();

textField.setBounds(155, 42, 227, 37);

frame.getContentPane().add(textField);

textField.setColumns(10);

JLabel label = new JLabel("密 碼");

label.setBounds(38, 115, 80, 34);

frame.getContentPane().add(label);

passwordField = new JPasswordField();

passwordField.setBounds(155, 115, 227, 37);

frame.getContentPane().add(passwordField);

JButton btnNewButton = new JButton("登 錄");

btnNewButton.setBounds(60, 187, 115, 34);

frame.getContentPane().add(btnNewButton);

btnNewButton.addActionListener(new ActionListener() {

@Override

public void actionPerformed(ActionEvent arg0) {

// TODO Auto-generated method stub

UserCheck UC=new UserCheck(textField.getText(),String.valueOf(passwordField.getPassword()));

if(UC.getI()!=0) //有此用戶

{

frame.setVisible(false);

}

else

{

textField.setText("");

passwordField.setText("");

}

}

});

JButton button = new JButton("取 消");

button.setBounds(242, 187, 115, 34);

frame.getContentPane().add(button);

button.addActionListener(new ActionListener() {

@Override

public void actionPerformed(ActionEvent arg0) {

// TODO Auto-generated method stub

textField.setText("");

passwordField.setText("");

}

});

}

}

/*****************************************************************/

package 登錄;

import java.sql.Connection;

import java.sql.DriverManager;

import java.sql.PreparedStatement;

import java.sql.ResultSet;

import java.sql.SQLException;

import java.sql.Statement;

import 操作處理.UsersCL;

/**@author 20111024

* 檢測登錄的用戶在數(shù)據(jù)庫中有無,若沒有,則提示沒有此用戶,

* 若有,則判斷級別:普通用戶還是管理員。

*/

public class UserCheck {

private int i=0; //用戶級別:0不是用戶、1是管理員、2是普通用戶

UserCheck(String name ,String password)

{

String jdriver="sun.jdbc.odbc.JdbcOdbcDriver";

String connectDB="jdbc:odbc:Students";

Statement stmt=null;

ResultSet rs=null;

Connection con=null;

try {

Class.forName(jdriver);

con=DriverManager.getConnection(connectDB);

stmt=con.createStatement();

String query="select * from users where name='"+name+"' and passwd='"+password+"'";

rs=stmt.executeQuery(query);

if(rs.next())

{

//數(shù)據(jù)庫中有此用戶,訪問成功

i=Integer.parseInt(rs.getString(3));

UsersCL UL=new UsersCL(i);

}

else

{

i=0; //沒有用戶是默認(rèn)是0級

}

} catch (ClassNotFoundException e) {

// TODO Auto-generated catch block

e.printStackTrace();

} catch (SQLException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

}

public int getI() {

return i;

}

}

/********************************************************************************************/

package 操作處理;

import java.awt.EventQueue;

public class UsersCL implements ActionListener{

private JFrame frame;

private JTextField textField;

private JTextField textField_1;

private JTextField textField_2;

private JTextField textField_3;

private int i=0;

private JLabel label_3;

private JTextField textField_4;

public UsersCL(int i) {

this.i=i;

frame = new JFrame();

frame.setTitle("用戶處理界面");

frame.setBounds(100, 100, 450, 300);

frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

frame.getContentPane().setLayout(null);

frame.setResizable(false);

frame.setVisible(true);

JLabel lblNewLabel = new JLabel("學(xué) 號");

lblNewLabel.setBounds(24, 32, 74, 29);

frame.getContentPane().add(lblNewLabel);

JLabel label = new JLabel("姓 名");

label.setBounds(24, 71, 74, 29);

frame.getContentPane().add(label);

JLabel label_1 = new JLabel("年 齡");

label_1.setBounds(24, 110, 74, 29);

frame.getContentPane().add(label_1);

label_3 = new JLabel("性 別");

label_3.setBounds(24, 149, 74, 29);

frame.getContentPane().add(label_3);

JLabel label_2 = new JLabel("狀 態(tài)");

label_2.setBounds(24, 195, 74, 29);

frame.getContentPane().add(label_2);

textField = new JTextField();

textField.setBounds(101, 34, 113, 25);

frame.getContentPane().add(textField);

textField.setColumns(10);

textField_1 = new JTextField();

textField_1.setColumns(10);

textField_1.setBounds(101, 73, 113, 25);

frame.getContentPane().add(textField_1);

textField_2 = new JTextField();

textField_2.setColumns(10);

textField_2.setBounds(101, 112, 113, 25);

frame.getContentPane().add(textField_2);

textField_3 = new JTextField();

textField_3.setEditable(false);

textField_3.setColumns(10);

textField_3.setBounds(101, 199, 288, 25);

frame.getContentPane().add(textField_3);

textField_4 = new JTextField();

textField_4.setColumns(10);

textField_4.setBounds(101, 149, 113, 25);

frame.getContentPane().add(textField_4);

if(1==i)

{

JButton btnNewButton = new JButton("追 加");

btnNewButton.setBounds(276, 41, 113, 29);

frame.getContentPane().add(btnNewButton);

btnNewButton.addActionListener(this);

btnNewButton.setActionCommand("追加");

JButton button_1 = new JButton("刪 除");

button_1.setBounds(276, 145, 113, 29);

frame.getContentPane().add(button_1);

button_1.addActionListener(this);

button_1.setActionCommand("刪除");

}

JButton button = new JButton("查 詢");

button.setBounds(276, 91, 113, 29);

frame.getContentPane().add(button);

button.addActionListener(this);

button.setActionCommand("查詢");

}

@Override

public void actionPerformed(ActionEvent e) {

// TODO Auto-generated method stub

String name,age,sex,query=null;

int num,age1,count=0;

num=Integer.parseInt(textField.getText());

name=textField_1.getText();

age1=Integer.parseInt(textField_2.getText());

sex=textField_4.getText();

if(e.getActionCommand().equals("追加"))

{

query="insert into students values("+num+","+"'"+name+"',"+age1+",'"+sex+"');";

count=1;

}

else if(e.getActionCommand().equals("查詢"))

{

query="select * from students where XSB="+num+";";

count=2;

}

else if(e.getActionCommand().equals("刪除"))

{

query="delete from students where XSB="+num+" and name="+"'"+name+"'";

count=3;

}

Statement stmt=null;

ResultSet rs=null;

Connection con=null;

String jdriver="sun.jdbc.odbc.JdbcOdbcDriver";

String connectDB="jdbc:odbc:Students";

String query1=null;

try {

Class.forName(jdriver);

con=DriverManager.getConnection(connectDB);

stmt=con.createStatement();

if(count==1)

{

query1="select * from students where XSB="+num+";";

rs=stmt.executeQuery(query1);

if(rs.next())

textField_3.setText("已經(jīng)由此記錄,不能追加!");

else

{

stmt.executeUpdate(query);

textField_3.setText("已經(jīng)追加完成!");

}

}

else if(2==count)

{

stmt.executeQuery(query);

rs=stmt.executeQuery(query);

if(rs.next())

{

textField_3.setText("已查找到此記錄!");

}

else

{

textField_3.setText("沒有此記錄,可以追加!");

}

}

else if(3==count)

{

query1="select * from students where XSB="+num+" and name="+"'"+name+"'";

rs=stmt.executeQuery(query1);

if(rs.next())

{

stmt.executeUpdate(query);

textField_3.setText("已刪除此記錄!");

}

else

textField_3.setText("無此記錄!");

}

} catch (ClassNotFoundException e1) {

// TODO Auto-generated catch block

e1.printStackTrace();

} catch (SQLException e1) {

// TODO Auto-generated catch block

e1.printStackTrace();

}

finally{

//關(guān)閉資源

if(stmt!=null){

try {

stmt.close();

} catch (Exception e2) {

// TODO: handle exception

}

stmt=null;

}

if(con!=null){

try {

con.close();

} catch (Exception e2) {

// TODO: handle exception

}

con=null;

}

}

}

}

分享題目:學(xué)生登錄界面java代碼 java設(shè)置學(xué)生管理登陸界面
分享路徑:http://www.muchs.cn/article10/dosshdo.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供商城網(wǎng)站、ChatGPT、搜索引擎優(yōu)化品牌網(wǎng)站制作、電子商務(wù)、App開發(fā)

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

成都網(wǎng)站建設(shè)