java请假系统(利用io流完成)

这里给大家说一个利用io流完成的请假系统,上篇文章有展示只是单纯的请假界面,感兴趣的朋友可以去博客看下。这里主要简单实现了学生请假和学生查看请假记录,辅导员审核请假信息和老师以及辅导员查看请假信息。下个文章会给大家展示利用数据库实现的请假系统,代码会比现在这个的复杂一点,当然功能也会相对的完善很多。

下面展示代码,主要有五个类,

第一个类,登录界面


/**
 * 登陆主界面
 */


import java.awt.Color;
//import java.awt.FlowLayout;
import java.awt.Graphics;
//import java.awt.GridLayout;
import java.awt.Image;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

//import javax.imageio.ImageIO;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
import java.awt.*;
//import java.io.File;
//import java.io.IOException;

import javax.swing.*;

public class Login extends JFrame implements ActionListener {	
		  //private static final String JPanel = null;
	    JPanel jp=new JPanel();
	      
		  JTextField fieldAccount = new JTextField(1000);
		 
		  JPasswordField fieldPassword = new JPasswordField(1000);
		 JButton jb1 = new JButton("登 录");
		 
		  JButton jb2=new JButton("退出");
		  
		  JLabel label = new JLabel("  帐  号   ");
		  JLabel label1 = new JLabel(" 密 码   ");
		  JLabel label2=new JLabel("请假系统登录界面");
		 
		 JRadioButton jrb1=new JRadioButton("学生");
		 JRadioButton jrb2=new JRadioButton("教师");
		 JRadioButton jrb3=new JRadioButton("辅导员");
		 ButtonGroup bg=new ButtonGroup();
		 
//		  public void paint(Graphics g){
//				 super.paint(g);
//				 ImageIcon imge=new ImageIcon("src/12.jpg");
//				 imge.setImage(imge.getImage().getScaledInstance(this.getWidth(),this.getHeight(),Image.SCALE_AREA_AVERAGING));
//			g.drawImage(imge.getImage(),10,10,null);
//		
//			}
//		
	  

public Login(){
			this.setTitle("用户登录界面.....");
			this.setBounds(550, 200, 700, 500);
			this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
			this.setLayout(null);
			this.setVisible(true);
		    
			jb2.addActionListener(this);	
			  
		  
		    jb1.setBackground(new Color(233,240,247));
	        jb1.setForeground(new Color(30,57,91));
	        jb2.setBackground(new Color(233,240,247));
	        jb2.setForeground(new Color(30,57,91));

			
			

			JLabel label = new JLabel("账号");
		  
		    label.setOpaque(false);
			label.setBounds(150,140,100,50);
			//label.setForeground(Color.white);
			label.setFont(new Font("微软雅黑",Font.PLAIN,18));
		    
			//jb1.setForeground(Color.white);
			jb1.setFont(new Font("微软雅黑",Font.PLAIN,18));
			//jb2.setForeground(Color.white);
			jb2.setFont(new Font("微软雅黑",Font.PLAIN,18));
		    
			// fieldAccount.setOpaque(false);
			 fieldAccount.setBorder(null);
			// fieldPassword.setOpaque(false);
			// fieldPassword.setBorder(null);
			jb1.setOpaque(false);
			jb2.setOpaque(false);
			jb1.setBorder(null);
			 jb2.setBorder(null);
			//label.setBackground(Color.red);
			//label.setForeground(Color.red);
		
			this.add(label);
			fieldAccount.setBounds(250, 140, 300, 50);
			this.add(fieldAccount);
			
			label1 = new JLabel("  密 码   ");
			
			label1.setAlignmentX(JLabel.CENTER_ALIGNMENT);
			//label1.setForeground(Color.white);
			label1.setFont(new Font("微软雅黑",Font.PLAIN,18));
		    
			//label1.setForeground(Color.red);
			label1.setBounds(145, 238, 100, 50);
			this.add(label1);
			fieldPassword.setBounds(250, 240, 300, 50);
			fieldPassword.setBorder(null);
			this.add(fieldPassword);
			
		
			this.add(jb1);
			this.add(jb2);
			
			
			
			jb1.setBounds(250,350,100,50);
			jb2.setBounds(450,350,100,50);
			jb1.addActionListener(this);
			
			label2.setBounds(300,50,200,50);
			label2.setFont(new Font("微软雅黑",Font.PLAIN,18));
			this.add(label2);
			
			bg.add(jrb1);
			bg.add(jrb2);
			bg.add(jrb3);
			jrb1.setFont(new Font("微软雅黑",Font.PLAIN,18));
			jrb2.setFont(new Font("微软雅黑",Font.PLAIN,18));
			jrb3.setFont(new Font("微软雅黑",Font.PLAIN,18));
		
			jrb1.setBounds(250,320,70,30);
			jrb2.setBounds(320,320,70,30);
			jrb3.setBounds(390,320,100,30);
			this.add(jrb1);
			this.add(jrb2);
			this.add(jrb3);
			// pwd 监听enter键
			fieldPassword.addActionListener(this);
			fieldAccount.addActionListener(this);
			
		
			jrb1.addActionListener(this);	
			jrb2.addActionListener(this);	
			jrb3.addActionListener(this);	
			jb1.addActionListener(this);	
		
			this.setVisible(true);
			
			
		

  
   }

		public void actionPerformed(ActionEvent e) {
			if( e.getSource().equals(jb2))
	        {
				this.dispose();
	           // System.exit( 0 );

		       
			}
			
			
			if(e.getSource() == fieldPassword|| e.getSource() == jb1){
				// 获取帐号
				String account = fieldAccount.getText();
				// 获取密码
				String pwd = new String(fieldPassword.getPassword());
			
				if (account.compareTo("123") == 0 && pwd.compareTo("123")==0 ){
				if(jrb1.isSelected()){
						
					
					
					JOptionPane.showMessageDialog(null, "登录成功");
					this.dispose();
					System s=new System();
				
					}				
				else if(!jrb1.isSelected( )){
					JOptionPane.showMessageDialog(null, "对不起,你不是学生用户");
					}
				}
			
			
				else if (account.compareTo("1234") == 0 && pwd.compareTo("1234")==0 ){
					if(jrb2.isSelected()){
						
					
					
					JOptionPane.showMessageDialog(null, "登录成功");
					this.dispose();
					TeacherSystem TS=new TeacherSystem();
				
					}
					else JOptionPane.showMessageDialog(null, "对不起,你不是教师用户");
				
				}
			
			
				else if(account.equals("12345")  && pwd.equals("12345")){
					if(jrb3.isSelected()){
						
					
					
					JOptionPane.showMessageDialog(null, "登录成功");
					this.dispose();
					CounsellorSystem CS=new CounsellorSystem();
				
					}
					else  JOptionPane.showMessageDialog(null, "对不起,你不是辅导员用户");
			}
				if( e.getSource().equals(jb1))
		        {	
					fieldAccount.setText("账号或密码错误");
					
				}
//			  if(account.compareTo("123")!=0||account.compareTo("1234")!=0 ){	
//				
//				if(pwd.compareTo("123")!=0||pwd.compareTo("1234")!=0){
//					fieldAccount.setText("账号或密码错误");
//				}
//				
//			  
//			  }	
		}
//		if(account.compareTo("123")!=0&&pwd.compareTo("123")!=0){
				
//				JOptionPane.showMessageDialog(null, "登录失败" + "\n" + "id:123" + "\n" + "password:123");
//		}
			//else {JOptionPane.showMessageDialog(null, "登录失败" + "\n" + "id:123" + "\n" + "password:123");
					
		//	}
				
			
		
		
}

public static void main(String[] args) {
		// TODO Auto-generated method stub
		new Login();
	}
}



第二个类,学生界面

import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.*;
import java.awt.Color;

import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;

/**
 * 学生请假系统模块
 */



public class System extends JFrame implements ActionListener{

	     JFrame frame;
		JButton jb1=new JButton("学生申请请假");
		JButton jb2=new JButton("学生申请销假");
		JButton jb3=new JButton("查询请假记录");
		JButton jb4=new JButton("提交");
		JButton jb5=new JButton("退出");
		
		 static JTextArea jt;
		 static  JTextField xmg;
		 static JTextField xhg;
		 static JTextField zyg;
		 static JTextField lxg;
		 static JTextField ksrqg;
		 static JTextField jsrqg;
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		
		System a=new System();	}

	
public System(){
	
	
	
	this.setTitle("学生请假系统");
	this.setLocation(550,200);
	this.setSize(700,500);
	this.setDefaultCloseOperation(EXIT_ON_CLOSE);
	this.setLayout(null);
	
	
	
//	JButton jb1=new JButton("学生申请请假");
//	JButton jb2=new JButton("学生申请销假");
//	JButton jb3=new JButton("查询请假记录");
//	JButton jb4=new JButton("提交");
//	JButton jb5=new JButton("退出");
	
	
	
//	 jb1.setBorder(null);
//	 jb2.setBorder(null);
//	 jb3.setBorder(null);
//	 jb4.setBorder(null);
//	 jb5.setBorder(null);
//	 
	  jb1.setOpaque(false);
	  jb1.setFont(new Font("微软雅黑",Font.PLAIN,18));
	  jb2.setOpaque(false);
	  jb2.setFont(new Font("微软雅黑",Font.PLAIN,18));
	  jb3.setOpaque(false);
	  jb3.setFont(new Font("微软雅黑",Font.PLAIN,18));
	  jb4.setOpaque(false);
	  jb4.setFont(new Font("微软雅黑",Font.PLAIN,18));
	  jb5.setOpaque(false);
	  jb5.setFont(new Font("微软雅黑",Font.PLAIN,18));
	  
	 jb1.setBackground(new Color(233,240,247));
	 jb2.setBackground(new Color(233,240,247));
	 jb3.setBackground(new Color(233,240,247));
	 jb4.setBackground(new Color(233,240,247));
	 jb5.setBackground(new Color(233,240,247));
	 
	 
	JLabel jl=new JLabel("请假申请");
	JLabel xm=new  JLabel("姓名");
	JLabel xh=new JLabel("学号");
	JLabel zy=new JLabel("专业");
	JLabel lx=new JLabel("联系");
	JLabel ksrq=new JLabel("开始日期");
	JLabel jsrq=new JLabel("结束日期");
	JLabel qjsy=new JLabel("请假事由");
	
	
	 jl.setFont(new Font("微软雅黑",Font.PLAIN,18));
	 xm.setFont(new Font("微软雅黑",Font.PLAIN,18));
	 xh.setFont(new Font("微软雅黑",Font.PLAIN,18));
	 zy.setFont(new Font("微软雅黑",Font.PLAIN,18));
	 lx.setFont(new Font("微软雅黑",Font.PLAIN,18));
	 ksrq.setFont(new Font("微软雅黑",Font.PLAIN,18));
	 jsrq.setFont(new Font("微软雅黑",Font.PLAIN,18));
	 qjsy.setFont(new Font("微软雅黑",Font.PLAIN,18));
	  
	 xmg=new JTextField();
	 xhg=new JTextField();
	 zyg=new JTextField();
	 lxg=new JTextField();
	 ksrqg=new JTextField();
	 jsrqg=new JTextField();
	//JTextField qjsyg=new JTextField();
	 jt=new JTextArea();
	 
	 xmg.setFont(new Font("微软雅黑",Font.PLAIN,18));
	 xhg.setFont(new Font("微软雅黑",Font.PLAIN,18));
	 zyg.setFont(new Font("微软雅黑",Font.PLAIN,18));
	 lxg.setFont(new Font("微软雅黑",Font.PLAIN,18));
	 ksrqg.setFont(new Font("微软雅黑",Font.PLAIN,18));
	 jsrqg.setFont(new Font("微软雅黑",Font.PLAIN,18));
	 jt.setFont(new Font("微软雅黑",Font.PLAIN,18));
	 
	 xmg.setBorder(null);
	 xhg.setBorder(null);
	 zyg.setBorder(null);
	 lxg.setBorder(null);
	 ksrqg.setBorder(null);
	 jsrqg.setBorder(null);
	// qjsyg.setBorder(null);

	jb1.setBounds(5, 0, 233, 50);
	jb2.setBounds(236, 0, 223, 50);
	jb3.setBounds(457, 0, 223, 50);
	
	jl.setBounds(300,51,620,50);
	
	xm.setBounds(30,90,60,50);
	xmg.setBounds(68,102,110,30);
	
	xh.setBounds(190,90,50,50);
	xhg.setBounds(227,102,110,30);
	
	zy.setBounds(350,90,50,50);
	zyg.setBounds(389,102,110,30);
	
	lx.setBounds(517,90,50,50);
	lxg.setBounds(556,102,110,30);
	
	ksrq.setBounds(30,135,90,50);
	ksrqg.setBounds(105,145,170,30);
	
	jsrq.setBounds(300,135,90,50);
	jsrqg.setBounds(375,145,170,30);
	
	qjsy.setBounds(30,210,90,100);
	//jt.setBounds(30,210,90,100);
	jt.setBounds(105,200,555,130);
	
	
	jb4.setBounds(30,380,100,50);
	jb5.setBounds(140,380,100,50);
	//this.add(upper);
	
	this.add(jb1);
	this.add(jb2);
	this.add(jb3);
	this.add(jl);
	this.add(xm);
	this.add(xmg);
	this.add(zy);
	this.add(zyg);
	this.add(xh);
	this.add(xhg);
	this.add(lx);
	this.add(lxg);
	this.add(ksrq);
	this.add(ksrqg);
	this.add(jsrq);
	this.add(jsrqg);
	this.add(qjsy);
	//this.add(qjsyg);
	this.add(jt);
	this.add(jb4);
	this.add(jb5);
	
	jb1.addActionListener(this);	
	jb2.addActionListener(this);	
	jb3.addActionListener(this);	
	jb4.addActionListener(this);	
	jb5.addActionListener(this);	
	
	this.setVisible(true);
}

	public void actionPerformed(ActionEvent e) {
		// TODO Auto-generated method stub
		 // String input = e.getActionCommand();
		  if( e.getSource().equals(jb5))
	        {
				this.dispose();
	           // System.exit( 0 );

		       
			}
//		  if(input.equals("退出")){
//			  this.dispose();
//		  }
	       
		  if(e.getSource().equals(jb4)){
				
			  File f = new File("d:\\student1.txt");
				//字节输出流
				FileOutputStream fos=null;
				
				try {
					fos = new FileOutputStream(f);
				
					String s="姓名:"+"  "+xmg.getText()+"\r\n";
					String s1="学号:"+"  "+xhg.getText()+"\r\n";
					String s2="专业:"+"  "+zyg.getText()+"\r\n";
					String s3="联系:"+"  "+lxg.getText()+"\r\n";
					String s4="开始:"+"  "+ksrqg.getText()+"\r\n";
					String s5="结束:"+"  "+jsrqg.getText()+"\r\n";
					String s6 = "请假事由:"+"  "+jt.getText()+"\r\n";//换行:/r/n
					String s7="请假信息已提交,等待审核通过";
					//定义字节数组
					byte []btyes = new byte[10024];
					
					fos.write(s.getBytes());
					fos.write(s1.getBytes());
					fos.write(s2.getBytes());
					fos.write(s3.getBytes());
					fos.write(s4.getBytes());
					fos.write(s5.getBytes());
					fos.write(s6.getBytes());
					fos.write(s7.getBytes());
					
				} catch (Exception e1) {
					e1.printStackTrace();
					// TODO: handle exception
				}finally{
					try {
						fos.close();
					} catch (IOException e1) {
						// TODO Auto-generated catch block
						e1.printStackTrace();
					}
				}
				JOptionPane.showMessageDialog(null, "提交成功");
				xmg.setText("");
				xhg.setText("");
				zyg.setText("");
				lxg.setText("");
				ksrqg.setText("");
				jsrqg.setText("");
				jt.setText("");
				
				
				
			}  
		Object[] options={"好啊","去一边"};
		if(e.getSource().equals(jb3)){
			
			StudentLeaveRecord SLR=new StudentLeaveRecord();
			this.dispose();
//			xmg.setText("");
//			xhg.setText("");
//			zyg.setText("");
//			lxg.setText("");
//			ksrqg.setText("");
//			jsrqg.setText("");
//			jt.setText("");
		}  
		if(e.getSource().equals(jb2)){
			JOptionPane.showMessageDialog(null, "对不起,该功能未开通");
		}  
		if(e.getSource().equals(jb1)){
			JOptionPane.showMessageDialog(null, "你已处于当前界面");
		}  }
		 
	}   
	
		          
	
   

第三个类,学生查看请假信息

import java.awt.Color;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.*;
import javax.swing.*;
public class StudentLeaveRecord extends JFrame implements ActionListener{

	/**
	 * 学生查询请假记录模块
	 */

	JButton jb1=new JButton("学生申请请假");
	JButton jb2=new JButton("学生申请销假");
	JButton jb3=new JButton("查询请假记录");
	JButton jb4=new JButton("退出");
	JTextArea jt=new JTextArea();
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		
//		
//		FileReader fr=null;
//		//写入文件(输出流)
//		//FileWriter fw=null;
//		
//		try {
//			//创建fir对象
//			fr = new FileReader("d:\\g1.txt");
//			
//			
//			int n=0;//实际读取的字符数
//			//读入到内存
//			char c[]=new char[10024];
//			while((n=fr.read(c))!=-1){
//				//System.out.println(c);
//				String s= new String(c,0,n);
//				System.out.println(s);
//			}
//			
//			
//		} catch (Exception e) {
//			e.printStackTrace();
//			// TODO: handle exception
//		}
		StudentLeaveRecord SLR=new StudentLeaveRecord();
	}



		
	
	
public StudentLeaveRecord(){
	this.setTitle("学生请假系统");
	this.setLocation(550,200);
	this.setSize(700,500);
	this.setDefaultCloseOperation(EXIT_ON_CLOSE);
	this.setLayout(null);
	
	jt.setEditable(false);//设计文本框不能外部输入
	jt.setForeground(Color.BLACK);
	jt.setFont(new Font("微软雅黑",Font.PLAIN,18));
	jb1.setOpaque(false);
	jb1.setFont(new Font("微软雅黑",Font.PLAIN,18));
	jb2.setOpaque(false);
	jb2.setFont(new Font("微软雅黑",Font.PLAIN,18));
	jb3.setOpaque(false);
	jb3.setFont(new Font("微软雅黑",Font.PLAIN,18));
	jb4.setOpaque(false);
	jb4.setFont(new Font("微软雅黑",Font.PLAIN,18));
	jb1.setBackground(new Color(233,240,247));
	jb2.setBackground(new Color(233,240,247));
    jb3.setBackground(new Color(233,240,247));
    jb4.setBackground(new Color(233,240,247));


	jb1.setBounds(5, 0, 233, 50);
	jb2.setBounds(236, 0, 223, 50);
	jb3.setBounds(457, 0, 223, 50);
	jb4.setBounds(457, 400, 223, 50);
	jt.setBounds(30,80,620,300);
	jb1.addActionListener(this);	
	jb2.addActionListener(this);	
	jb3.addActionListener(this);
	jb4.addActionListener(this);
	
    this.add(jb1);
    this.add(jb2);
    this.add(jb3);
    this.add(jb4);
    this.add(jt);
    this.setVisible(true);

	FileReader fr=null;
	//写入文件(输出流)
	//FileWriter fw=null;
	
	try {
		//创建fir对象
		fr = new FileReader("d:\\student1.txt");
		
		
		int n=0;//实际读取的字符数
		//读入到内存
		char c[]=new char[10024];
		while((n=fr.read(c))!=-1){
			//System.out.println(c);
			String s= new String(c,0,n);
			
			jt.setText(s);
		}
		
		
	} catch (Exception e) {
		e.printStackTrace();
		// TODO: handle exception
	}
	
}

	public void actionPerformed(ActionEvent e) {
		// TODO Auto-generated method stub
		  if(e.getSource().equals(jb4)){
				this.dispose();
			}  
		//Object[] options={"好啊","去一边"};
		if(e.getSource().equals(jb1)){
	//	int m=JOptionPane.showOptionDialog(null, "我可以约你吗","标题",JOptionPane.YES_NO_OPTION,JOptionPane.QUESTION_MESSAGE,null,options,options[0]);
			System a=new System();	
			this.dispose();
		}  
		if(e.getSource().equals(jb2)){
			JOptionPane.showMessageDialog(null, "对不起,该功能未开通");
		}  
		if(e.getSource().equals(jb3)){
			JOptionPane.showMessageDialog(null, "你已处于当前界面");
		}  
	
	}

}

第四个类,辅导员审核请假信息,

import java.awt.Color;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
public class CounsellorSystem extends JFrame implements ActionListener{

	/**
	 *辅导员管理请假信息系统
	 */

	JButton jb1=new JButton("审核请假信息");
	JButton jb2=new JButton("审核销假信息");
	JButton jb3=new JButton("学生请假记录");
	
	JButton jb4=new JButton("退出");
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		CounsellorSystem CS=new CounsellorSystem();
	}
	
public CounsellorSystem(){
	this.setTitle("辅导员管理请假信息系统");
	this.setLocation(550,200);
	this.setSize(700,500);
	this.setDefaultCloseOperation(EXIT_ON_CLOSE);
	this.setLayout(null);
	
	
	jb1.setOpaque(false);
	jb1.setFont(new Font("微软雅黑",Font.PLAIN,18));
	jb2.setOpaque(false);
	jb2.setFont(new Font("微软雅黑",Font.PLAIN,18));
	jb3.setOpaque(false);
	jb3.setFont(new Font("微软雅黑",Font.PLAIN,18));
	jb4.setOpaque(false);
	jb4.setFont(new Font("微软雅黑",Font.PLAIN,18));
	jb1.setBackground(new Color(233,240,247));
	jb2.setBackground(new Color(233,240,247));
    jb3.setBackground(new Color(233,240,247));
    jb4.setBackground(new Color(233,240,247));


	jb1.setBounds(5, 0, 233, 50);
	jb2.setBounds(236, 0, 223, 50);
	jb3.setBounds(457, 0, 223, 50);
	jb4.setBounds(457, 400, 223, 50);
	jb1.addActionListener(this);	
	jb2.addActionListener(this);	
	jb3.addActionListener(this);
	jb4.addActionListener(this);
    this.add(jb1);
    this.add(jb2);
    this.add(jb3);
    this.add(jb4);
    this.setVisible(true);
}

	public void actionPerformed(ActionEvent e) {
		// TODO Auto-generated method stub
		  if(e.getSource().equals(jb4)){
				this.dispose();
			}  
	
		if(e.getSource().equals(jb3)){
			CounsellorLookRecord clr=new CounsellorLookRecord();
		}  
		if(e.getSource().equals(jb2)){
			JOptionPane.showMessageDialog(null, "对不起,该功能未开通");
		}  
		if(e.getSource().equals(jb1)){
			//JOptionPane.showMessageDialog(null, "你已处于当前界面");
			Set s1=new Set();
			this.dispose();
		}  
	
	}

}













import java.awt.Color;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.*;

import javax.swing.*;
public class Set extends JFrame implements ActionListener{

	/**
	 * 辅导员查看学生请假信息模块
	 */

	JButton jb1=new JButton("审核请假信息");
	JButton jb2=new JButton("审核销假信息");
	JButton jb3=new JButton("学生请假记录");
	JButton jb4=new JButton("通过审核");
	JButton jb6=new JButton("审核不通过");
	JButton jb5=new JButton("退出");
	JTextArea jt=new JTextArea();
	
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		
//		
//		FileReader fr=null;
//		//写入文件(输出流)
//		//FileWriter fw=null;
//		
//		try {
//			//创建fir对象
//			fr = new FileReader("d:\\g1.txt");
//			
//			
//			int n=0;//实际读取的字符数
//			//读入到内存
//			char c[]=new char[10024];
//			while((n=fr.read(c))!=-1){
//				//System.out.println(c);
//				String s= new String(c,0,n);
//				System.out.println(s);
//			}
//			
//			
//		} catch (Exception e) {
//			e.printStackTrace();
//			// TODO: handle exception
//		}
		Set s1=new Set();
	}



		
	
	
public Set(){
	this.setTitle("辅导员管理请假信息系统");
	this.setLocation(550,200);
	this.setSize(700,500);
	this.setDefaultCloseOperation(EXIT_ON_CLOSE);
	this.setLayout(null);
	
	
	jb1.setOpaque(false);
	jb1.setFont(new Font("微软雅黑",Font.PLAIN,18));
	jb2.setOpaque(false);
	jb2.setFont(new Font("微软雅黑",Font.PLAIN,18));
	jb3.setOpaque(false);
	jb3.setFont(new Font("微软雅黑",Font.PLAIN,18));
	jb4.setOpaque(false);
	jb4.setFont(new Font("微软雅黑",Font.PLAIN,18));
	jb5.setOpaque(false);
	jb5.setFont(new Font("微软雅黑",Font.PLAIN,18));
	jb6.setOpaque(false);
	jb6.setFont(new Font("微软雅黑",Font.PLAIN,18));
	jb1.setBackground(new Color(233,240,247));
	jb2.setBackground(new Color(233,240,247));
    jb3.setBackground(new Color(233,240,247));
    jb4.setBackground(new Color(233,240,247));
    jb5.setBackground(new Color(233,240,247));
    jb6.setBackground(new Color(233,240,247));



	jb1.setBounds(5, 0, 233, 50);
	jb2.setBounds(236, 0, 223, 50);
	jb3.setBounds(457, 0, 223, 50);
	jb4.setBounds(230, 400, 223, 50);
	jb5.setBounds(450, 400, 223, 50);
	jb6.setBounds(10, 400, 223, 50);
	
	
	jt.setBounds(30,80,620,300);
	jt.setEditable(false);//设计文本框不能外部输入
	 jt.setFont(new Font("微软雅黑",Font.PLAIN,18));
	jb1.addActionListener(this);	
	jb2.addActionListener(this);	
	jb3.addActionListener(this);
	jb4.addActionListener(this);
	jb5.addActionListener(this);
	jb6.addActionListener(this);
	
    this.add(jb1);
    this.add(jb2);
    this.add(jb3);
    this.add(jb4);
    this.add(jb5);
    this.add(jb6);
    this.add(jt);
    this.setVisible(true);

	FileReader fr=null;
	//写入文件(输出流)
	//FileWriter fw=null;
	
	try {
		//创建fir对象
		fr = new FileReader("d:\\student1.txt");
		
		
		int n=0;//实际读取的字符数
		//读入到内存
		char c[]=new char[10024];
		
		while((n=fr.read(c))!=-1){
			//System.out.println(c);
			String s= new String(c,0,n);
			
			jt.setText(s);
		}
		
		
	} catch (Exception e) {
		e.printStackTrace();
		// TODO: handle exception
	}
	
}

	public void actionPerformed(ActionEvent e) {
		// TODO Auto-generated method stub
		  if(e.getSource().equals(jb5)){
				this.dispose();
			}  
		Object[] options={"好啊","去一边"};
		if(e.getSource().equals(jb3)){
			CounsellorLookRecord clr=new CounsellorLookRecord();
			this.dispose();
		}  
		if(e.getSource().equals(jb2)){
			JOptionPane.showMessageDialog(null, "对不起,该功能未开通");
		}  
		if(e.getSource().equals(jb1)){
			JOptionPane.showMessageDialog(null, "你已处于当前界面");
		}  
		if(e.getSource().equals(jb4)){
			JOptionPane.showMessageDialog(null, "审核完毕");
			  File f = new File("d:\\student1.txt");
			  File f1 = new File("d:\\student2.txt");
			//字节输出流
			FileOutputStream fos=null;
			FileOutputStream fos1=null;
			
			try {
				fos = new FileOutputStream(f);
				fos1 = new FileOutputStream(f1);
			
					String s1 = jt.getText()+"\r\n";//换行:/r/n
					String s2 = "请假状态:"+"  "+"已通过审核";
					String s3=jt.getText()+"\r\n";
				//定义字节数组
				byte []btyes = new byte[10024];
				
			
				fos.write(s1.getBytes());
				fos.write(s2.getBytes());
				fos1.write(s3.getBytes());
				fos1.write(s2.getBytes());
				
			} catch (Exception e1) {
				e1.printStackTrace();
				// TODO: handle exception
			}finally{
				try {
					fos.close();
					fos1.close();
					
				} catch (IOException e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
				}
			}
		//	JOptionPane.showMessageDialog(null, "提交成功");
		
		
			
			jt.setText("");
		}  
		if(e.getSource().equals(jb6)){
			JOptionPane.showMessageDialog(null, "请假信息将撤回");
			  File f = new File("d:\\student1.txt");
			
			//字节输出流
			FileOutputStream fos=null;
		
			try {
				fos = new FileOutputStream(f);
			
			
					String s1 = jt.getText()+"\r\n";//换行:/r/n
					String s2 = "请假状态:"+"  "+"审核不通过,请假失败";
					
				//定义字节数组
				byte []btyes = new byte[10024];
				
			
				fos.write(s1.getBytes());
				fos.write(s2.getBytes());
			
				
			} catch (Exception e1) {
				e1.printStackTrace();
				// TODO: handle exception
			}finally{
				try {
					fos.close();
					
					
				} catch (IOException e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
				}
			jt.setText("");
			}}}
	
	}


第五个类,辅导员查看学生请假信息,

import java.awt.Color;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Enumeration;

import javax.swing.*;
import javax.swing.border.Border;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import javax.swing.table.JTableHeader;
import javax.swing.table.TableColumn;
/**
 *辅导员管理请假信息系统
 */
public class CounsellorLookRecord extends JFrame implements ActionListener{

	

	JButton jb1=new JButton("审核请假信息");
	JButton jb2=new JButton("审核销假信息");
	JButton jb3=new JButton("学生请假记录");
	JButton jb4=new JButton("退出");
	JButton jb5=new JButton("查询");
	JTextField jt=new JTextField();
	JLabel jl=new JLabel("学号");
	String[] columnNames={"姓名","学号","专业","联系","开始日期","结束日期","请假状态","请假事由"};//定义表格列名数
	String[][] tableValues={{"陈锦贤11111111111111111","182017331","计算机","15119747306","2019-9-23-17:55","2019-9-23-19:14","通过","因为想呆在宿舍2222222222222222222222"},{"21","22","23","24","25","26","27","28"},{"","","","","","","",""},
			{"","","","","","","",""},{"","","","","","","",""},{"","","","","","","",""},{"","","","","","","",""},{"","","","","","","",""},
			{"","","","","","","",""},{"","","","","","","",""},{"","","","","","","",""},{"","","","","","","",""},{"","","","","","","",""},
			{"","","","","","","",""},{"","","","","","","",""},{"","","","","","","",""},{"","","","","","","",""},{"","","","","","","",""}};//定义表格数据数组
	
			JTable table=new JTable(tableValues,columnNames);//创建指定列名和数据的表格
	
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		CounsellorLookRecord clr=new CounsellorLookRecord();
	}
	
public CounsellorLookRecord(){
	this.setTitle("辅导员查看请假信息系统");
	this.setLocation(550,200);
	this.setSize(700,500);
	this.setDefaultCloseOperation(EXIT_ON_CLOSE);
	this.setLayout(null);
	
	//JTable table=new JTable(tableValues,columnNames);//创建指定列名和数据的表格
	JScrollPane scrollpane=new JScrollPane(table);//创建显示表格的滚动面板
	//FitTableColumns(table);
	table.setRowHeight(40);
	table.setDefaultRenderer(Object.class, new TableCellTextAreaRenderer()); 



	
	//JTableAUTO_RESIZE_ALL_COLUMNS;
	//table.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS);
	//JTable.AUTO_RESIZE_OFF
	//table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
	
	
	
	
	//jb1.setBorder(null);
	jb1.setOpaque(false);
	jb1.setFont(new Font("微软雅黑",Font.PLAIN,18));
	//jb2.setBorder(null);
	jb2.setOpaque(false);
	jb2.setFont(new Font("微软雅黑",Font.PLAIN,18));
	//jb3.setBorder(null);
	jb3.setOpaque(false);
	jb3.setFont(new Font("微软雅黑",Font.PLAIN,18));
	//jb4.setBorder(null);
	jb4.setOpaque(false);
	jb4.setFont(new Font("微软雅黑",Font.PLAIN,18));
	//jb5.setBorder(null);
	jb5.setOpaque(false);
	jb5.setFont(new Font("微软雅黑",Font.PLAIN,18));
	jl.setFont(new Font("微软雅黑",Font.PLAIN,18));
	//jl.setBorder(null);
	jl.setOpaque(false);
	scrollpane.setOpaque(false);
	
	jl.setFont(new Font("微软雅黑",Font.PLAIN,18));
	jb1.setBackground(new Color(233,240,247));
	jb2.setBackground(new Color(233,240,247));
    jb3.setBackground(new Color(233,240,247));
    jb4.setBackground(new Color(233,240,247));
    jb5.setBackground(new Color(233,240,247));
    jl.setBackground(new Color(233,240,247));
    scrollpane.setBackground(new Color(233,240,247));
  
    
	jb1.setBounds(5, 0, 233, 50);
	jb2.setBounds(236, 0, 223, 50);
	jb3.setBounds(457, 0, 223, 50);
	jb4.setBounds(457, 400, 223, 50);
	jb5.setBounds(5, 55, 123, 25);
	jl.setBounds(150, 55, 123, 25);
	jt.setBounds(220, 55, 123, 25);
	scrollpane.setBounds(5, 92, 675, 300);
	

	jb1.addActionListener(this);	
	jb2.addActionListener(this);	
	jb3.addActionListener(this);
	jb4.addActionListener(this);
    this.add(jb1);
    this.add(jb2);
    this.add(jb3);
    this.add(jb4);
    this.add(jb5);
    this.add(jl);
    this.add(jt);
    this.add(scrollpane);
    this.setVisible(true);
    
}

public static void FitTableColumns(JTable myTable) {
    JTableHeader header = myTable.getTableHeader();
    int rowCount = myTable.getRowCount();

    Enumeration columns = myTable.getColumnModel().getColumns();
    while (columns.hasMoreElements()) {
        TableColumn column = (TableColumn) columns.nextElement();
        int col = header.getColumnModel().getColumnIndex(column.getIdentifier());
        int width = (int) myTable.getTableHeader().getDefaultRenderer()
                .getTableCellRendererComponent(myTable, column.getIdentifier(), false, false, -1, col)
                .getPreferredSize().getWidth();
        for (int row = 0; row < rowCount; row++) {
            int preferedWidth = (int) myTable.getCellRenderer(row, col)
                    .getTableCellRendererComponent(myTable, myTable.getValueAt(row, col), false, false, row, col)
                    .getPreferredSize().getWidth();
            width = Math.max(width, preferedWidth);
        }
        header.setResizingColumn(column);
        column.setWidth(width + myTable.getIntercellSpacing().width + 10);
    }
}

public boolean isCellEditable(int rowlndex ,int columlndex){
	return false;
}
	public void actionPerformed(ActionEvent e) {
		// TODO Auto-generated method stub
		  if(e.getSource().equals(jb4)){
				this.dispose();
			}  
		
		if(e.getSource().equals(jb3)){
			JOptionPane.showMessageDialog(null, "你已处于当前界面");
		} 
		if(e.getSource().equals(jb2)){
			JOptionPane.showMessageDialog(null, "对不起,该功能未开通");
		}  
		if(e.getSource().equals(jb1)){
			//JOptionPane.showMessageDialog(null, "你已处于当前界面");
			Set s1=new Set();
			this.dispose();
		}  
	
	}


}







import java.awt.Component;

import javax.swing.JTable;
import javax.swing.JTextArea;
import javax.swing.table.TableCellRenderer;
/*
 * 
 * 表格高度设置
*/
public class TableCellTextAreaRenderer  extends JTextArea implements TableCellRenderer { 
	
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub

	}
	
		public TableCellTextAreaRenderer() { 
		
			
		setLineWrap(true); 
		setWrapStyleWord(true); 
		
		} 
		 
		
		

		public Component getTableCellRendererComponent(JTable table, Object value, 
				boolean isSelected, boolean hasFocus, int row, int column) { 
		// 计算当下行的最佳高度 
		int maxPreferredHeight = 30; 
		
		for (int i = 0; i < table.getColumnCount(); i++) { 
		setText("" + table.getValueAt(row, i)); 
		setSize(table.getColumnModel().getColumn(column).getWidth(), 0); 
		maxPreferredHeight = Math.max(maxPreferredHeight, getPreferredSize().height); 
		} 
		 
		if (table.getRowHeight(row) != maxPreferredHeight) {// 少了这行则处理器瞎忙 
		table.setRowHeight(row, maxPreferredHeight); }
		if(isSelected)
		{
			this.setBackground(table.getSelectionBackground());
		}
		else
		{
			this.setBackground(table.getBackground());
			}
		 
		setText(value == null ? "" : value.toString()); 
		
		return this; 
		} 
	}



 

第六个,老师查看学生请假信息

import java.awt.Color;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;

public class TeacherSystem  extends JFrame implements ActionListener{

	/**
	 * 教师查看学生请假信息系统模块
	 */
	
	JButton jb1=new JButton("学生请假信息");
	JButton jb2=new JButton("学生销假信息");
	JButton jb3=new JButton("退出");
	public static void main(String[] args) {
		// TODO Auto-generated method stub
TeacherSystem TS=new TeacherSystem();
	}

public TeacherSystem(){

	this.setTitle("教师查看学生请假信息系统");
	this.setLocation(550,200);
	this.setSize(700,500);
	this.setDefaultCloseOperation(EXIT_ON_CLOSE);
	this.setLayout(null);
	
	
	jb1.setOpaque(false);
	jb1.setFont(new Font("微软雅黑",Font.PLAIN,18));
	jb2.setOpaque(false);
	jb2.setFont(new Font("微软雅黑",Font.PLAIN,18));
	jb3.setOpaque(false);
	jb3.setFont(new Font("微软雅黑",Font.PLAIN,18));
	jb1.setBackground(new Color(233,240,247));
	jb2.setBackground(new Color(233,240,247));
    jb3.setBackground(new Color(233,240,247));

	jb1.setBounds(5, 0, 233, 50);
	jb2.setBounds(236, 0, 223, 50);
	jb3.setBounds(457, 0, 223, 50);
	jb1.addActionListener(this);	
	jb2.addActionListener(this);	
	jb3.addActionListener(this);	
    this.add(jb1);
    this.add(jb2);
    this.add(jb3);
    this.setVisible(true);
}

@Override
public void actionPerformed(ActionEvent e) {
	// TODO Auto-generated method stub
	
	if(e.getSource().equals(jb3)){
	 this.dispose();
	}  
		if(e.getSource().equals(jb2)){
			JOptionPane.showMessageDialog(null, "对不起,该功能未开通");
		}  
		if(e.getSource().equals(jb1)){
			TeacherLookRecord TLR=new TeacherLookRecord();
			this.dispose();
		}  
	}
}

import java.awt.Color;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.*;
import javax.swing.*;

public class TeacherLookRecord extends JFrame implements ActionListener{

	/**
	 * 教师查看学生请假信息系统模块
	 */
	
	JButton jb1=new JButton("学生请假信息");
	JButton jb2=new JButton("学生销假信息");
	JButton jb3=new JButton("退出");
	JTextArea jt=new JTextArea();
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		TeacherLookRecord TLR=new TeacherLookRecord();
	}

public TeacherLookRecord(){

	this.setTitle("教师查看学生请假信息系统");
	this.setLocation(550,200);
	this.setSize(700,500);
	this.setDefaultCloseOperation(EXIT_ON_CLOSE);
	this.setLayout(null);
	
	
	jb1.setOpaque(false);
	jb1.setFont(new Font("微软雅黑",Font.PLAIN,18));
	jb2.setOpaque(false);
	jb2.setFont(new Font("微软雅黑",Font.PLAIN,18));
	jb3.setOpaque(false);
	jb3.setFont(new Font("微软雅黑",Font.PLAIN,18));
	jb1.setBackground(new Color(233,240,247));
	jb2.setBackground(new Color(233,240,247));
    jb3.setBackground(new Color(233,240,247));

	jb1.setBounds(5, 0, 233, 50);
	jb2.setBounds(236, 0, 223, 50);
	jb3.setBounds(457, 0, 223, 50);
	jt.setBounds(30,80,620,300);
	jt.setEditable(false);//设计文本框不能外部输入
	 jt.setFont(new Font("微软雅黑",Font.PLAIN,18));
	jb1.addActionListener(this);	
	jb2.addActionListener(this);	
	jb3.addActionListener(this);	
    this.add(jb1);
    this.add(jb2);
    this.add(jb3);
    this.add(jt);
    this.setVisible(true);
    
    FileReader fr=null;
	//写入文件(输出流)
	//FileWriter fw=null;
	
	try {
		//创建fir对象
		fr = new FileReader("d:\\student2.txt");
		
		
		int n=0;//实际读取的字符数
		//读入到内存
		char c[]=new char[10024];
		while((n=fr.read(c))!=-1){
			//System.out.println(c);
			String s= new String(c,0,n);
			
			jt.setText(s);
		}
		
		
	} catch (Exception e) {
		e.printStackTrace();
		// TODO: handle exception
	}
	
}

@Override
public void actionPerformed(ActionEvent e) {
	// TODO Auto-generated method stub
	
	if(e.getSource().equals(jb3)){
	 this.dispose();
	}  
		if(e.getSource().equals(jb2)){
			JOptionPane.showMessageDialog(null, "对不起,该功能未开通");
		}  
		if(e.getSource().equals(jb1)){
			JOptionPane.showMessageDialog(null, "你已处于当前界面");
		}  
	}
}

关注我可以查看下个有关数据库的请假系统哦。

带数据库的请假系统链接 https://blog.youkuaiyun.com/qq_44716544/article/details/109268640?utm_source=app

最后,感觉对你有用的就点个赞呗。

评论 11
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值