⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 readingroompane.java

📁 图书馆座位管理系统
💻 JAVA
字号:
package librarysearchingsystem;

import java.awt.Color;
import java.awt.Dimension;

import javax.swing.*;

import fileUtility.ReadingRoom;
import fileUtility.filePath;
import java.awt.SystemColor;
import javax.swing.border.EtchedBorder;
import javax.swing.border.Border;
import javax.swing.border.TitledBorder;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.Font;
import java.awt.*;
import fileUtility.StudentsManagement;
import fileUtility.Student;


public class ReadingRoomPane extends JPanel implements ActionListener {
    static final int hapX = 32, hapY = 32, titleHeight = 30;
    static final int comLength = 32;

    static ImageIcon seat = new ImageIcon(filePath.imagePath + "chair.gif");
    static ImageIcon floor = new ImageIcon(filePath.imagePath + "floor.jpg");
    static ImageIcon girl = new ImageIcon(filePath.imagePath + "girl.gif");
    static ImageIcon boy = new ImageIcon(filePath.imagePath + "boy.gif");
    static ImageIcon door = new ImageIcon(filePath.imagePath + "door.jpg");
    static ImageIcon window = new ImageIcon(filePath.imagePath + "window.jpg");
    static ImageIcon book = new ImageIcon(filePath.imagePath + "book.gif");
    static ImageIcon desk = new ImageIcon(filePath.imagePath + "desk.gif");
    static ImageIcon wall = new ImageIcon(filePath.imagePath + "wall.jpg");
    static ImageIcon me = new ImageIcon(filePath.imagePath + "me.png");
    static ImageIcon friend = new ImageIcon(filePath.imagePath + "friend.png");
    static ImageIcon all[] = {girl, seat, window, door, floor, book, desk, wall,
                             boy};

    JComponent com[][];

    int width = 850, height = 1000;
    private boolean needToRePaint = false;


    ReadingRoom r;
    JLabel title = new JLabel("阅览室");
    JButton goBack = new JButton("返回");
    public static Frame f;
    public ReadingRoomPane() {

        try {
            r = new ReadingRoom(filePath.file + "readingRoom2.txt");
            jbInit();
            this.draw();
        } catch (Exception ex) {
            ex.printStackTrace();
        }

    }

    public ReadingRoomPane(ReadingRoom r, Frame f) {
        this.r = r;
        title.setText(r.name);
        this.f = f;
        try {
            jbInit();
            this.draw();
        } catch (Exception ex) {
            ex.printStackTrace();
        }

    }

    public ReadingRoomPane(ReadingRoom r) {
        this.r = r;
        title.setText(r.name);
        try {
            jbInit();
            this.draw();
        } catch (Exception ex) {
            ex.printStackTrace();
        }

    }


    public static void main(String[] args) {
        ReadingRoomPane graphicpane = new ReadingRoomPane();
    }


    private void jbInit() throws Exception {
        this.setBackground(SystemColor.inactiveCaption);
        this.setAutoscrolls(true);
        this.setBorder(null);
        this.setLayout(null);
        title.setForeground(new Color(0, 76, 255));

        this.add(title);
        title.setBorder(null);
        title.setFont(new java.awt.Font("隶书", Font.PLAIN, 40));
        title.setBounds(150, 5, 600, 40);
        title.setHorizontalAlignment(title.CENTER);
        title.setBackground(this.getBackground());
        title.setOpaque(true);

        this.add(goBack);
        goBack.setFont(new java.awt.Font("隶书", Font.PLAIN, 28));
        goBack.setBounds(5, 5, 90, 40);
        goBack.setForeground(Color.MAGENTA);
        goBack.addActionListener(new goBackListner());

//        Thread t=new Thread(this);
//        t.start();

//        setPreferredSize(new Dimension(900,700));

    }

    public Dimension getPreferredSize() {
        return new Dimension(width, height);
    }

    void draw() {
        com = new JComponent[r.map.length][r.map[0].length];
//        r.print();
        for (int i = 0; i < r.map.length; i++) {
            for (int j = 0; j < r.map[i].length; j++) {
                if (r.map[i][j] >= 0) {
                    if (f.stu != null && r.map[i][j] == f.stu.serial) {
                        com[i][j] = new JButton(me);
                        com[i][j].setToolTipText("自己");
                    } else {
                        Student stuTemp = StudentsManagement.students[r.map[i][
                                          j]];
                        boolean isBoy = stuTemp.isBoy;
                        if (isBoy) {
                            com[i][j] = new JButton(boy);
                            com[i][j].setToolTipText(stuTemp.name);
                        } else {
                            com[i][j] = new JButton(girl);
                            com[i][j].setToolTipText(stuTemp.name);
                        }
                    }
                } else {
                    switch (r.map[i][j]) {
                    case -1:
                        com[i][j] = new JButton(seat);
                        ((JButton) com[i][j]).addActionListener(this);
                        com[i][j].setToolTipText("空座位");
                        break;
                    case -8:
                        continue;
                    default:
                        com[i][j] = new JLabel(all[ -r.map[i][j]]);
                    }
                }
                this.add(com[i][j]);
                com[i][j].setBorder(null);
                com[i][j].setBounds(hapX + comLength * j,
                                    titleHeight + hapY + comLength * i,
                                    comLength, comLength);

            }
        }

        width = 2 * hapX + comLength * r.map[0].length;
        height = 2 * hapY + comLength * r.map.length + titleHeight;

    }

    public boolean changeIcon(int serial, Icon icon) {
//        System.out.println("changeIcon 0" + "Serial =" + serial);
//        r.print();
        for (int i = 0; i < r.map.length; i++) {
            for (int j = 0; j < r.map[0].length; j++) {
//                System.out.println(r.map[i][j]);


                if (r.map[i][j] == serial) {
//                    System.out.println("changeIcon");
                    ((JButton) com[i][j]).setIcon(icon);
                    ((JButton) com[i][j]).setDisabledIcon(icon);
                    return true;
                }

            }
        }

        return false;

    }


    public void setNeedToRepaint(boolean b) {
        needToRePaint = b;
    }

    public boolean isNeedToRepaint() {
        return needToRePaint;
    }

    public void actionPerformed(ActionEvent e) {
        Point p = ((JButton) e.getSource()).getLocation();
//        System.out.println(p.getX() + "     " + p.getY());
        int x = (((int) p.getX()) - hapX) / comLength;
        int y = (((int) p.getY()) - hapY - titleHeight) / comLength;
        new EnsureSeatDialog(r, x, y); /** @todo  */

//        r.map[y][x]=Frame.stu.serial;
//        System.out.println(r.map[y][x]);
    }

    public void changeIcon(int i, int j, boolean seatSelected, boolean isBoy) {
        if (!seatSelected) {
            ((JButton) com[i][j]).setIcon(seat);
            ((JButton) com[i][j]).setEnabled(true);
        } else {

            ((JButton) com[i][j]).setEnabled(false);
            if (isBoy) {
                ((JButton) com[i][j]).setDisabledIcon(boy);
            } else {
                ((JButton) com[i][j]).setDisabledIcon(girl);
            }
        }
    }

    class goBackListner implements ActionListener {
        public void actionPerformed(ActionEvent e) {
            if (f != null) {
                f.changeToNavigationPanel();
            }
            try {
                this.finalize();
            } catch (Throwable ex) {
            }
        }

    }


//        public void paint(Graphics g) {
//        g.setPaintMode();
//        g.setColor(Color.blue);
//        g.fillRect(10, 10, 20, 20);
//        g.fill3DRect(800, 10, 40, 49, true);
//
//
////        this.remove(bb);
//       // bb=new JButton("");
//      //  this.add(bb);
//
//
//        width = 840;
//        height = this.getHeight();
//        setPreferredSize(new Dimension(width,height));
//    }

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -