📄 studentview.java
字号:
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.StringTokenizer;
import javax.swing.*;
public class StudentView extends JFrame{
Book bk=new Book();
Book []borrow=new Book[6];
Book []sort_book=new Book[10];
LibraryManager LM=new LibraryManager();
StudentView(){
Toolkit kit = Toolkit.getDefaultToolkit();
Image img = kit.getImage("pic//sbook.jpg");
setIconImage(img);
Container c=this.getContentPane();
c.setLayout(new BorderLayout());
c.add(wp,BorderLayout.WEST);
c.add(np,BorderLayout.NORTH);
c.add(ep,BorderLayout.EAST);
label1=new JLabel("欢迎进入学生管理系统!");
label1.setFont(new Font("华文行楷",Font.BOLD,20));
//按钮
np.setLayout(new FlowLayout());
bt[0]=new JButton("已借");
bt[1]=new JButton("查找");
bt[2]=new JButton("预约");
bt[3]=new JButton("续借");
np.add(label1);
for (int i=0;i<4;i++)
{
np.add(bt[i]);
}
//显示区
text1=new JTextArea(36,54);
text1.setMaximumSize(text1.getPreferredSize());
text1.setEditable(false);
scroll=new JScrollPane(text1);
add(scroll);
//功能区
for (int i=0;i<4;i++)
{
lf_pn[i]=new JPanel();
bb[i]=Box.createVerticalBox();
}
//已借panel
lf_pn[0].setLayout(new FlowLayout());
b2=Box.createHorizontalBox();
label2=new JLabel("请在两周之内还书");
label3=new JLabel("否则将按图书馆规则罚款");
StuInfo();
b1=Box.createVerticalBox();
b1.add(label2);
b1.add(label3);
bbtt[0]=new JButton("查看已借图书");
b2.add(bbtt[0]);
b2.add(b1);
bb[0].add(b_totalinfo);
bb[0].add(Box.createVerticalStrut(35));
bb[0].add(b2);
bb[0].add(Box.createVerticalStrut(35));
bb[0].add(new clock());
lf_pn[0].add(bb[0]);
//查找panel
warnlabel[0]=new JLabel("查找时请输入书的全名!");
findList=new JComboBox(findName);
tf[0]=new JTextField(20);
tf[0].setMaximumSize(tf[0].getPreferredSize());
b[0]=Box.createHorizontalBox();
b[0].add(findList);
b[0].add(Box.createHorizontalStrut(15));
b[0].add(tf[0]);
bbtt[1]=new JButton("查找");
b_warn[0]=Box.createHorizontalBox();
b_warn[0].add(bbtt[1]);
b_warn[0].add(warnlabel[0]);
StuInfo();
bb[1].add(b_totalinfo);
bb[1].add(Box.createVerticalStrut(35));
bb[1].add(b[0]);
bb[1].add(Box.createVerticalStrut(15));
bb[1].add(b_warn[0]);
bb[1].add(Box.createVerticalStrut(45));
bb[1].add(new clock());
bb[1].add(Box.createVerticalStrut(35));
lf_pn[1].add(bb[1]);
//预约及续借panel
for(int i=2;i<4;i++)
{
label[i-1]=new JLabel("编号: ");
tf[i-1]=new JTextField(20);
tf[i-1].setMaximumSize(tf[i-1].getPreferredSize());
b[i-1]=Box.createHorizontalBox();
b[i-1].add(label[i-1]);
b[i-1].add(tf[i-1]);
warnlabel[1]=new JLabel("3天之内到图书馆拿书!");
warnlabel[2]=new JLabel("网上续借只能使用一次!");
warnlabel[i-1].setFont(new Font("微软雅黑",Font.BOLD,15));
b_warn[i-1]=Box.createHorizontalBox();
bb[i-1]=Box.createVerticalBox();
bbtt[i]=new JButton("确定");
b_warn[i-1].add(bbtt[i]);
b_warn[i-1].add(warnlabel[i-1]);
StuInfo();
bb[i].add(b_totalinfo);
bb[i].add(Box.createVerticalStrut(35));
bb[i].add(b[i-1]);
bb[i].add(Box.createVerticalStrut(15));
bb[i].add(b_warn[i-1]);
bb[i].add(Box.createVerticalStrut(45));
bb[i].add(new clock());
lf_pn[i].add(bb[i]);
}
for (int i=0;i<4;i++)
{
wp.add(lf_pn[i]);
}
lf_card=new CardLayout();
for(int i=0;i<4;i++)
lf_card.addLayoutComponent(lf_pn[i],"lf_pn"+i);
wp.setLayout(lf_card);
for (int i=0;i<4;i++){
bt[i].addActionListener(new MyEvent());
bbtt[i].addActionListener(new LeftEvent());
}
}
public void StuInfo(){
//读入学生学号
try{
FileReader fr = new FileReader("deng.txt");
BufferedReader br = new BufferedReader(fr);
while ((r = br.readLine())!= null) {
StringTokenizer sto = new StringTokenizer(r);
r_name = sto.nextToken();
}
}catch(IOException ie){
System.err.println("error:" + ie.getMessage());
}
//读入学生信息
try{
FileReader fr = new FileReader(r_name+".txt");
BufferedReader br = new BufferedReader(fr);
r=br.readLine();
info[0]=r;
r=br.readLine();
info[1]=r;
r=br.readLine();
info[2]=r;
r=br.readLine();
info[3]=r;
}catch(IOException ie){
System.err.println("error:" + ie.getMessage());
}
//显示学生信息
b_totalinfo=Box.createHorizontalBox();
b_info=Box.createVerticalBox();
for (int i=0;i<4;i++){
lb_info[i]=new JLabel();
lb_info[i].setText(info[i]);
b_info.add(lb_info[i]);
}
try{
ImageIcon icon = new ImageIcon("pic//"+r_name+".jpg");
photo=new JLabel();
photo.setIcon(icon);
photo.setToolTipText("A photo of " + r_name.toLowerCase());
b_totalinfo.add(Box.createHorizontalStrut(35));
b_totalinfo.add(photo);
}catch(Exception ie){
System.err.println("error:" + ie.getMessage());
}
b_totalinfo.add(Box.createHorizontalStrut(35));
b_totalinfo.add(b_info);
//add(b_totalinfo,BorderLayout.CENTER);
}
class MyEvent implements ActionListener{
public void actionPerformed(ActionEvent evt) {
Object source = evt.getSource();
for (int i=0;i<4;i++)
if(source==bt[i]){
lf_card.show(wp, "lf_pn"+i);
}
}
}
class LeftEvent implements ActionListener{
public void actionPerformed(ActionEvent lf_evt) {
Object source = lf_evt.getSource();
for (int i=0;i<6;i++)
borrow[i]=new Book();
if (source==bbtt[0]){
String r,temp1,temp2,temp3,temp4,temp5,temp6,temp7,temp8,temp9,temp0;
int count=0;
try{
FileReader fileReader = new FileReader(r_name+"_borrow.txt");
BufferedReader bufferReader = new BufferedReader(fileReader);
while ((r = bufferReader.readLine()) != null) {
StringTokenizer toKen_Student = new StringTokenizer(r);
temp0=toKen_Student.nextToken();
temp1=toKen_Student.nextToken();
temp2=toKen_Student.nextToken();
temp3=toKen_Student.nextToken();
temp4=toKen_Student.nextToken();
temp5=toKen_Student.nextToken();
temp6=toKen_Student.nextToken();
temp7=toKen_Student.nextToken();
temp8=toKen_Student.nextToken();
temp9=toKen_Student.nextToken();
borrow[count].setNO(Integer.parseInt(temp0));
borrow[count].setName(temp1);
borrow[count].setSort(temp2);
borrow[count].setHolder(temp3);
borrow[count].setDeadline(temp4);
borrow[count].setISBN(temp5);
borrow[count].setAuthor(temp6);
borrow[count].setPublisher(temp7);
borrow[count].setPrice(Double.parseDouble(temp8));
borrow[count].setPublicTime(temp9);
count++;
}
}catch(IOException ie){
System.err.println("error:" + ie.getMessage());
}
for (int i=0;i<count;i++)
text1.insert(borrow[i].getNO()+" "+borrow[0].getName()+
" "+borrow[i].getSort()+" "+borrow[i].getAuthor()+
" "+borrow[i].getPublisher()+" "+borrow[i].getPrice()+
" "+borrow[i].getPublicTime()+"\n",0);
}
if (source==bbtt[1]){
findlist= (String)findList.getSelectedItem();
String find=tf[0].getText();
if (findlist.equals("编号")){
bk=LM.searchByNO(Integer.parseInt(find));
if (bk==null)
JOptionPane.showMessageDialog(null,"本图书馆没有此书!");
else{
text1.setText(bk.getNO()+" "+bk.getName()+
" "+bk.getSort()+" "+bk.getAuthor()+
" "+bk.getPublisher()+" "+bk.getPrice()+
" "+bk.getPublicTime());
}
}
if (findlist.equals("书名")){
bk=LM.searchByName(find);
if (bk==null)
JOptionPane.showMessageDialog(null,"本图书馆没有此书!");
else{
text1.setText(bk.getNO()+" "+bk.getName()+
" "+bk.getSort()+" "+bk.getAuthor()+
" "+bk.getPublisher()+" "+bk.getPrice()+
" "+bk.getPublicTime());
}
}
if (findlist.equals("类别")){
for (int i=0;i<10;i++){
sort_book[i]=(LM.searchBySort(find))[i];
if (sort_book[i]==null)
JOptionPane.showMessageDialog(null,"本图书馆没有此书!");
else{
text1.insert(sort_book[i].getNO()+" "+sort_book[i].getName()+
" "+sort_book[i].getSort()+" "+sort_book[i].getAuthor()+
" "+sort_book[i].getPublisher()+" "+sort_book[i].getPrice()+
" "+sort_book[i].getPublicTime()+"\n",0);
}
}
}
}
if (source==bbtt[2]){
String jtf2=tf[1].getText();
int num=Integer.parseInt(jtf2);
reserve=LM.reserve(num,r_name);
if (reserve==true)
JOptionPane.showMessageDialog(null,"恭喜~~预约成功!");
else
JOptionPane.showMessageDialog(null,"对不起,您不能预约该书!");
}
if (source==bbtt[3]){
String jtf3=tf[2].getText();
int num=Integer.parseInt(jtf3);
renew=LM.renew(num,r_name);
if (renew==true)
JOptionPane.showMessageDialog(null,"恭喜~~续借成功!");
else
JOptionPane.showMessageDialog(null,"对不起,您不能续借该书!");
}
}
}
CardLayout lf_card;
private JPanel wp=new JPanel();
private JPanel np=new JPanel();
private JPanel ep=new JPanel();
private JPanel []lf_pn=new JPanel[4];
private JLabel label1,label2,label3;
private JLabel[]label=new JLabel[3];
private JLabel[]warnlabel=new JLabel[3];
private JTextField []tf=new JTextField[3];
private JTextArea text1;
private Box b1,b2;
private Box[]b=new Box[3];
private Box[]bb=new Box[4];
private Box[]b_warn=new Box[3];
private JScrollPane scroll;
private JButton [] bt=new JButton[4];
private JButton [] bbtt=new JButton[4];
String r_name,r,information,findlist;
private String []info={"","","",""};
private JLabel []lb_info=new JLabel[4];
private Box b_info,b_totalinfo;
private JLabel photo;
private JComboBox findList;
private String[] findName={"编号","书名","类别"};
private boolean renew=false,reserve=false;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -