全部代码已发送你的邮箱.
以下是部分代码.
package?zhidao;
import?java.util.Scanner;
public?class?Main?{
//从控制台读入信息
private?Scanner?scanner?=?new?Scanner(System.in);
private?StudentService?ss?=?new?StudentService();
public?static?void?main(String[]?args)?{
Main?main?=?new?Main();
main.startService();
}
public?void?startService(){
System.out.println("欢迎使用宿舍管理系统");
//加载之前的舍友信息
ss.getFromFile();
while(true){
System.out.print("请选择:");
int?choose?=?Integer.parseInt(scanner.nextLine());
switch?(choose)?{
case?1:
this.addRoomMates();
break;
ss.printRoomMates();
this.findRoomMatesByName();
ss.saveToFile();
this.removeRoomMatesBySno();
System.out.println("info?--?感谢使用,再见!");
System.exit(0);
default:
System.out.println("info?--?无此项,请重新选择!");
/**
*?调离舍友
*/
private?void?removeRoomMatesBySno()?{
remove();
return;
*?调离
private?void?remove()?{
System.out.print("请输入学号:");
String?sno?=?scanner.nextLine();
ss.removeRoomMatesBySno(sno);
*?按姓名查找
private?void?findRoomMatesByName()?{
check();
*?查找
private?void?check()?{
System.out.print("请输入姓名:");
String?name?=?scanner.nextLine();
ss.findRoomMateByName(name);
*?添加室友
private?void?addRoomMates()?{
add();
*?添加
private?void?add()?{
System.out.print("请输入性别:");
String?sex?=?scanner.nextLine();
System.out.print("请输入年龄:");
int?age?=?Integer.parseInt(scanner.nextLine());
ss.addRoomMates(new?Student(sno,name,sex,age));
import java.awt.BorderLayout;
import java.awt.CardLayout;
import java.awt.Container;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
import javax.swing.JToolBar;
import javax.swing.SwingConstants;
public class MainFrame extends JFrame implements ActionListener{
InsertPanel ip = null;
SelectPanel sp = null;
JPanel pframe;
CardLayout clayout;
public MainFrame(String s){
super(s);
JMenuBar mb = new JMenuBar();
this.setJMenuBar(mb);
JMenu m1 = new JMenu("系统");
mb.add(m1);
jm11 = new JMenuItem("退出系统");
m1.add(jm11);
Icon i1 = new ImageIcon();
jb1 = new JButton(i1);
jb1.setToolTipText("输入");
JToolBar tb = new JToolBar("系统工具");
tb.add(jb1);
add(tb,BorderLayout.NORTH);
jm11.addActionListener(this);
jb1.addActionListener(this);
clayout = new CardLayout();
pframe = new JPanel(clayout);
add(pframe);
JPanel mainp = new JPanel(new BorderLayout());
JLabel mainl = new JLabel("学生信息管理平台",SwingConstants.CENTER);
mainp.add(mainl);
pframe.add(mainp,"main");
clayout.show(pframe, "main");
public void actionPerformed(ActionEvent e){
if(ip == null){
ip= new InsertPanel();
pframe.add(ip,"insert");
clayout.show(pframe, "insert");
this.setTitle("输入学生信息");
if(sp == null){
sp= new SelectPanel();
pframe.add(sp,"select");
clayout.show(pframe, "select");
this.setTitle("查询学生信息");
第二个:
public class MainTest {
public static void main(String [] args){
MainFrame f = new MainFrame("学生信息管理平台");
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setVisible(true);
import java.sql.Connection;
import java.sql.DriverManager;
public class MySQLConnection {
static Connection getCon(){
Connection con = null;
try{
Class.forName("com.mysql.jdbc.Driver");
catch(Exception e){
System.out.println("建立数据库连接遇到异常!");
return con;
第四个:
import java.awt.GridLayout;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
public class SelectPanel extends JPanel implements ActionListener{
JButton jb;
JTextField jt;
public SelectPanel(){
JLabel jl = new JLabel("请输入学号:",SwingConstants.CENTER);
jt = new JTextField();
jb = new JButton("确定");
jp1.add(jl);
jp1.add(jt);
jp1.add(jb);
j1 = new JLabel("学号:",SwingConstants.CENTER);
jt1.setEditable(false);
this.setLayout(new BorderLayout());
add(jp1,BorderLayout.NORTH);
jb.addActionListener(this);
if(e.getSource() == jb){
String stuNo = jt.getText().trim();
Student s = new Student();
boolean b = true;
b = s.selectByStuNo(stuNo);
catch(Exception ex){
System.out.println("查询学生信息遇到异常!");
if(b){
jt1.setText(s.getStuNo());
int a = s.getAge();
Integer i = new Integer(a);
else{
JOptionPane.showMessageDialog(null, "无此学生!");
哇,不是吧,现在都用数据库,否则你的数据是死的呀.我这里直接有个我们自己做的一个公司管理系统项目,里面增删查改的功能都有,你有邮箱我发给你,改改就一样了.
以上就是土嘎嘎小编为大家整理的宿舍管理java代码相关主题介绍,如果您觉得小编更新的文章只要能对粉丝们有用,就是我们最大的鼓励和动力,不要忘记讲本站分享给您身边的朋友哦!!