成都网站建设设计

将想法与焦点和您一起共享

学生出入校园JAVA代码 学生出入校园java代码是什么

利用swing设计一个班级学生信息管理系统,一道JAVA题 求代码,不要废话

public class RandomUtils {

创新互联公司是一家专业提供鸡西梨树企业网站建设,专注与成都网站设计、做网站、成都外贸网站建设公司H5场景定制、小程序制作等业务。10年已为鸡西梨树众多企业、政府机构等服务。创新互联专业的建站公司优惠进行中。

public static String randomId(){

Random random = new Random();

StringBuilder sb = new StringBuilder();

for (int i = 0; i  6; i++) {

sb.append(random.nextInt(10));

}

return sb.toString();

}

public static int randomIntId(){

Random random = new Random();

StringBuilder sb = new StringBuilder();

for (int i = 0; i  6; i++) {

sb.append(random.nextInt(10));

}

return Integer.parseInt(sb.toString());

}

public static String randomName(){

String[] name1 = {"赵","钱","孙","李","周","吴","郑","王","张","刘"};

String[] name2 = {"一","二","三","四","五","六","七","八","九","十"};

Random random = new Random();

StringBuilder sb = new StringBuilder();

sb.append(name1[random.nextInt(10)]);

sb.append(name2[random.nextInt(10)]);

sb.append(name2[random.nextInt(10)]);

return sb.toString();

}

public static String randomSex(){

Random random = new Random();

return random.nextInt(4)/2==0?"男":"女";

}

public static int randomAge(int min, int max){

Random random = new Random();

return random.nextInt(min) + max-min;

}

public static int randomScore(){

Random random = new Random();

return (int)(random.nextDouble()*100%100);

}

public static String randomAddress(){

String[] address1 = {"商业","红叶","安康","河南","长海","黄河","桐柏","科学","瑞达","花园"};

String[] address2 = {"东","南","西","北","中"};

String[] address3 = {"街","路","大道","巷"};

Random random = new Random();

StringBuilder sb = new StringBuilder();

sb.append(address1[random.nextInt(10)]);

sb.append(address2[random.nextInt(5)]);

sb.append(address3[random.nextInt(4)]);

sb.append(random.nextInt(1000)+1);

sb.append("号");

return sb.toString();

}

}

import javax.swing.*;

import javax.swing.event.TreeSelectionEvent;

import javax.swing.event.TreeSelectionListener;

import javax.swing.table.DefaultTableModel;

import javax.swing.tree.DefaultMutableTreeNode;

import java.awt.*;

import java.util.*;

import java.util.List;

public class StudentManage extends JFrame{

public final static String[] CH_NUM = {"一","二","三","四","五","六","七","八","九","十"};

public final static String ROOT = "班级管理";

public final static int GRADE_NUM = 3;

public final static int CLASS_NUM = 3;

private MapString, ListStudent classes;

public StudentManage() {

setTitle("学生管理系统");

setSize(300, 300);

setLayout(new BorderLayout());

if(classes == null) classes = new HashMap();

DefaultMutableTreeNode top = new DefaultMutableTreeNode(ROOT);

DefaultMutableTreeNode[] gradeNodes = new DefaultMutableTreeNode[GRADE_NUM];

for (int i = 0; i  GRADE_NUM; i++) {

gradeNodes[i] = new DefaultMutableTreeNode(CH_NUM[i] + "年级");

for (int j = 0; j  CLASS_NUM; j++) {

gradeNodes[i].add(new DefaultMutableTreeNode(CH_NUM[j] + "班"));

}

top.add(gradeNodes[i]);

}

final JTree tree = new JTree(top);

String title[] = {"ID","姓名","性别","年龄","地址"};

final DefaultTableModel model = new DefaultTableModel(title, 0);

JTable table=new JTable(model);

tree.addTreeSelectionListener(new TreeSelectionListener() {

@Override

public void valueChanged(TreeSelectionEvent e) {

DefaultMutableTreeNode node = (DefaultMutableTreeNode) tree .getLastSelectedPathComponent();

if (node == null) return;

Object object = node.getUserObject();

if (node.isLeaf()) {

ListStudent stdList = classes.get(getFullPath(node));

Object[][] data = new Object[stdList.size()][5];

for (int i = 0; i  stdList.size(); i++) {

data[i][0] = stdList.get(i).getId();

data[i][1] = stdList.get(i).getName();

data[i][2] = stdList.get(i).getSex();

data[i][3] = stdList.get(i).getAge();

data[i][4] = stdList.get(i).getAddress();

}

while(model.getRowCount()0){

model.removeRow(model.getRowCount()-1);

}

for (int i = 0; i  stdList.size(); i++) {

model.addRow(data[i]);

}

model.fireTableDataChanged();

}

}

});

add(tree, BorderLayout.WEST);

add(new JScrollPane(table), BorderLayout.CENTER);

setVisible(true);

setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

}

private String getFullPath(DefaultMutableTreeNode defaultMutableTreeNode){

StringBuilder sb = new StringBuilder();

Object[] objs = defaultMutableTreeNode.getUserObjectPath();

for (int i = 0; i  objs.length; i++) {

sb.append(objs[i]);

}

return sb.toString().replace(ROOT,"");

}

public void init(){

for (int i = 0; i  GRADE_NUM; i++) {

for (int j = 0; j  CLASS_NUM; j++) {

int n = new Random().nextInt(30)+1;

ListStudent stdList = new ArrayList(n);

for (int k = 0; k  n; k++) {

stdList.add(new Student(RandomUtils.randomIntId(),RandomUtils.randomName(),RandomUtils.randomSex(),

RandomUtils.randomAge(6,12),RandomUtils.randomAddress()));

}

classes.put(CH_NUM[i] + "年级"+ CH_NUM[j] +"班", stdList);

}

}

}

public static void main(String[] args) {

StudentManage studentManage = new StudentManage();

studentManage.init();

}

}

class Student {

private int id;

private String name;

private String sex;

private int age;

private String address;

public Student(int id, String name, String sex, int age, String address) {

this.id = id;

this.name = name;

this.sex = sex;

this.age = age;

this.address = address;

}

public Student() {

}

public int getId() {

return id;

}

public String getName() {

return name;

}

public String getSex() {

return sex;

}

public int getAge() {

return age;

}

public String getAddress() {

return address;

}

@Override

public String toString() {

return "Student{" +

"id=" + id +

", name='" + name + '\'' +

", sex='" + sex + '\'' +

", age=" + age +

", address='" + address + '\'' +

'}';

}

}

登录界面的java代码,分别有教师登录,管理员登录,学生登录,右边是用户名和密码,见图。

分三个包,自己建个包,导进去就ok了,数据库是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

* 检测登录的用户在数据库中有无,若没有,则提示没有此用户,

* 若有,则判断级别:普通用户还是管理员。

*/

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())

{

//数据库中有此用户,访问成功

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

UsersCL UL=new UsersCL(i);

}

else

{

i=0; //没有用户是默认是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("学 号");

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("状 态");

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("已经由此记录,不能追加!");

else

{

stmt.executeUpdate(query);

textField_3.setText("已经追加完成!");

}

}

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{

//关闭资源

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;

}

}

}

}

求一Java程序代码!!

public class Matriculate {

private int score=400;

public int isMatriculate(Student stu){

if (stu.getIntgretResult()=score||(stu.getIntgretResult()=300stu.getSports()=90)) {

return 1;

}else {

return 0;

}

}

public static void main(String[] args) throws Exception {

Student stu1=new Student("zhangsan",1);

stu1.setIntgretResult(400);

Student stu2=new Student("lisi",2);

stu2.setSports(85);

stu2.setIntgretResult(356);

Matriculate m=new Matriculate();

int c1=m.isMatriculate(stu1);

if (c10) {

System.out.println("id:"+stu1.getId()+"\tname:"+stu1.getName()

+"\tIntgretResult:"+stu1.getIntgretResult()+"\tsports"+stu1.getSports());

System.out.println("被录取");

}

int c2=m.isMatriculate(stu2);

if (c20) {

System.out.println("id:"+stu2.getId()+"\tname:"+stu2.getName()

+"\tIntgretResult:"+stu2.getIntgretResult()+"\tsports"+stu2.getSports());

System.out.println("被录取");

}

}

}

class School{

public School(){}

public School(String schoolname, double scoreLine) {

this.schoolname = schoolname;

this.scoreLine = scoreLine;

}

private String schoolname;

private double scoreLine;

public String getSchoolname() {

return schoolname;

}

public double getScoreLine() {

return scoreLine;

}

}

class Student{

public Student(){}

public Student(String name, int id) {

this.name = name;

this.id = id;

}

private String name;

private int id;

private double intgretResult;

private int sports;

public String getName() {

return name;

}

public void setName(String name) {

this.name = name;

}

public int getId() {

return id;

}

public void setId(int id) {

this.id = id;

}

public double getIntgretResult() {

return intgretResult;

}

public void setIntgretResult(double intgretResult) {

this.intgretResult = intgretResult;

}

public int getSports() {

return sports;

}

public void setSports(int sports) {

this.sports = sports;

}

}

简单的JAVA学生管理系统代码···

lListStudent students = new ArrayListStudent();

BufferedReader br = new BufferedReader(new FileReader("D:\student.txt"));

String tmpStr = br.readLine();

while(tmpStr != null){

int firstIndex = tmpStr.indexOf(" ");

int secondIndex = tmpStr.indexOf(" ",firstIndex + 1);

int thirdIndex = tmpStr.indexOf(" ", secondIndex + 1);

int forthIndex = tmpStr.indexOf(" ", thirdIndex + 1);

Integer stuId = Integer.parseInt(tmpStr.substring(0,firstIndex));

String stuName = tmpStr.substring(firstIndex + 1,secondIndex);

Integer stuYW = Integer.parseInt(tmpStr.substring(secondIndex + 1,thirdIndex));

Integer stuSX = Integer.parseInt(tmpStr.substring(thirdIndex + 1,forthIndex));

Integer stuYY = Integer.parseInt(tmpStr.substring(forthIndex + 1));

Student student = new Student();

student.setStuId(stuId);

student.setStuName(stuName);

student.setStuYW(stuYW);

student.setStuSX(stuSX);

student.setStuYY(stuYY);

students.add(student);

tmpStr.readLine();

}

//创建一个学生实体类 封装stuId stuName stuYW stuSx stuYY 这5个属性。。。

//已经帮你把数据拆分出来 并以Student 对象的形式放入集合中了 接下来 给分吧 哇咔咔


本文标题:学生出入校园JAVA代码 学生出入校园java代码是什么
网址分享:http://chengdu.cdxwcx.cn/article/dodjpsh.html