这主要是根据请假需求做的一个界面,目前只做了学生部分的界面,而且没有录入功能,只有简单的事件处理功能;
主要用到了用到了JTextfield,JpasswordField,JFrame,JButton,JLabel
JTextfield,JTextAraea这几个,
更新了io流版本的请假系统,基本的功能已实现,可到此链接查看:https://blog.csdn.net/qq_44716544/article/details/103658832
下边这个是请假系统代码
package sx;
import java.awt.Color;
//import java.awt.Dimension;
//import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
public class System extends JFrame implements ActionListener{
JButton jb1=new JButton("学生申请请假");
JButton jb2=new JButton("学生申请销假");
JButton jb3=new JButton("查询请假记录");
JButton jb4=new JButton("提交");
JButton jb5=new JButton("退出");
public static void main(String[] args) {
// TODO Auto-generated method stub
System s=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));
JTextField xmg=new JTextField();
JTextField xhg=new JTextField();
JTextField zyg=new JTextField();
JTextField lxg=new JTextField();
JTextField ksrqg=new JTextField();
JTextField jsrqg=new JTextField();
//JTextField qjsyg=new JTextField();
JTextArea jt=new JTextArea();
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)){
JOptionPane.showMessageDialog(null, "提交成功");
}
Object[] options={"好啊","去一边"};
if(e.getSource().equals(jb3)){
int m=JOptionPane.showOptionDialog(null, "我可以约你吗","标题",JOptionPane.YES_NO_OPTION,JOptionPane.QUESTION_MESSAGE,null,options,options[0]);
}
if(e.getSource().equals(jb2)){
JOptionPane.showMessageDialog(null, "对不起,该功能未开通");
}
if(e.getSource().equals(jb1)){
JOptionPane.showMessageDialog(null, "你已处于当前界面");
}
}
}
然后后边这个是登陆界面代码;
package sx;
//import java.awt.Button;
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("请假系统登录界面");
ImageIcon img1=new ImageIcon("src/12.jpg");
JLabel label0 = new JLabel(img1);
// 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);
this.setVisible(true);
//jb1.setEnabled(true);
//jb2.setEnabled(true);
// pwd 监听enter键
fieldPassword.addActionListener(this);
}
public void paint(Graphics g){
super.paint(g);
ImageIcon imge=new ImageIcon("src/15.jpg");
imge.setImage(imge.getImage().getScaledInstance(this.getWidth(),this.getHeight(),Image.SCALE_AREA_AVERAGING));
//g.drawImage(imge.getImage(),10,10,null);
g.drawImage(imge.getImage(),10,10,null);
}
//@Override
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){
JOptionPane.showMessageDialog(null, "登录成功");
this.dispose();
System s=new System();
//Login_Photo window = new Login_Photo();
//window.setVisible(true);
//this.dispose();
}
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();
}
}