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

📄 proportionpanel.java

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

import java.awt.*;

import javax.swing.*;
import fileUtility.filePath;
import fileUtility.ReadingRoom;
import java.awt.event.MouseListener;
import java.awt.event.MouseEvent;

public class ProportionPanel extends JPanel implements MouseListener {
    static Frame f;

    JLabel totalSeatLabel = new JLabel();
    JLabel impropriatedSeatLabel = new JLabel();
    JLabel remainderSeatLabel = new JLabel();
    JLabel libNameLabel = new JLabel();
    JLabel proportion[];


    ReadingRoom r;
    String libName = "中文样本阅览室";
    int totalSeat = 10, impropriatedSeat = 1;
    int nameLength = 150;
    int redNum = 10;
    static final int comLength = 15, comHetight = 36;
    static final int hapX = 20, hapY = 15;
    static final int num = 36;
    static final ImageIcon red = new ImageIcon(filePath.imagePath + "red.png");
    static final ImageIcon blue = new ImageIcon(filePath.imagePath + "blue.png");
    static final Color normalBackground = new Color(145, 90, 255);
    static final Color mouseEnteredBackground = new Color(49, 106, 197);
//    static final Color mouseEnteredBackground = UIManager.getColor(
//            "CheckBoxMenuItem.selectionBackground");

    final int length = 755;
    final int height = 90;
    public ProportionPanel() {
        try {
            jbInit();
            initProportion();
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }

    public ProportionPanel(String libName, int totalSeat, int impropriatedSeat,
                           ReadingRoom r) {
        this.r = r;
        if (r != null) {
            r.proportionPanel = this;
        }
        this.totalSeat = totalSeat;
        this.impropriatedSeat = impropriatedSeat;
        this.libName = libName;
        try {
            jbInit();
            initProportion();
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }


    /**
     * initProportion
     */
    private void initProportion() {
        proportion = new JLabel[num];
        redNum = impropriatedSeat * num / totalSeat;
        int startX = 2 * hapX + nameLength;

        int i = 0;
        for (; i < redNum; i++) {
            proportion[i] = new JLabel(red);

            this.add(proportion[i]);
            proportion[i].setBorder(null);
            proportion[i].setBounds(startX + comLength * i, hapY,
                                    comLength, comHetight);

        }
        for (; i < num; i++) {
            proportion[i] = new JLabel(blue);
            this.add(proportion[i]);
            proportion[i].setBorder(null);
            proportion[i].setBounds(startX + comLength * i, hapY,
                                    comLength, comHetight);

        }

    }

    void refresh(int changedSeatNumber) {
        impropriatedSeat += changedSeatNumber;
        int temp = impropriatedSeat * num / totalSeat;
        if (temp > redNum) {
            for (int i = redNum; i < temp; i++) {
                proportion[i].setIcon(red);
            }
        } else {
            for (int i = temp; i < redNum; i++) {
                proportion[i].setIcon(blue);
            }
        }
        redNum = temp;
        totalSeatLabel.setText("座位总数:" + totalSeat);
        impropriatedSeatLabel.setText("已占座位数:" + impropriatedSeat);
        remainderSeatLabel.setText("剩余座位数:" + (totalSeat - impropriatedSeat));

    }

    void refresh() {
        refresh(0);
    }


    private void jbInit() throws Exception {
        this.setLayout(null);
        totalSeatLabel.setFont(new java.awt.Font("隶书", Font.PLAIN, 16));
        totalSeatLabel.setForeground(Color.green);
        totalSeatLabel.setText("座位总数:" + totalSeat);
        totalSeatLabel.setBounds(new Rectangle(140, 54, 142, 24));
        impropriatedSeatLabel.setFont(new java.awt.Font("隶书", Font.PLAIN, 16));
        impropriatedSeatLabel.setForeground(Color.red);
        impropriatedSeatLabel.setText("已占座位数:" + impropriatedSeat);
        impropriatedSeatLabel.setBounds(new Rectangle(329, 54, 142, 24));
        remainderSeatLabel.setFont(new java.awt.Font("隶书", Font.PLAIN, 16));
        remainderSeatLabel.setForeground(Color.green);
        remainderSeatLabel.setText("剩余座位数:" + (totalSeat - impropriatedSeat));
        remainderSeatLabel.setBounds(new Rectangle(518, 54, 142, 24));
        libNameLabel.setFont(new java.awt.Font("隶书", Font.PLAIN, 16));
        libNameLabel.setForeground(Color.yellow);
        libNameLabel.setText(libName);
        libNameLabel.setBounds(new Rectangle(hapX, hapY + 5, hapX + 150,
                                             hapY + 20));
        this.setBackground(normalBackground);
        this.setBorder(BorderFactory.createRaisedBevelBorder());
        this.add(libNameLabel);
        this.add(impropriatedSeatLabel);
        this.add(remainderSeatLabel);
        this.add(totalSeatLabel);
        this.setSize(length, height);
        this.setVisible(true);
        addMouseListener(this);
    }

    public static void main(String[] args) throws InterruptedException {
        JFrame ff = new JFrame();
        ff.setSize(800, 600);
        ff.getContentPane().setLayout(null);
        ProportionPanel p = new ProportionPanel("阅览室(一)", 20, 10, null);
        ff.getContentPane().add(p);
        ff.setDefaultCloseOperation(ff.EXIT_ON_CLOSE);
        ff.show();
        Thread.sleep(1000);
        p.impropriatedSeat = 0;
        p.refresh();
    }

    public void mouseClicked(MouseEvent e) {
    }

    public void mouseEntered(MouseEvent e) {
        this.setBackground(mouseEnteredBackground);

    }

    public void mouseExited(MouseEvent e) {
        this.setBackground(normalBackground);
    }

    public void mousePressed(MouseEvent e) {
        this.setBorder(BorderFactory.createLoweredBevelBorder());
    }

    public void mouseReleased(MouseEvent e) {
        this.setBorder(BorderFactory.createRaisedBevelBorder());
        if(f.stu!=null){
            //        System.out.println(f.stu.name);
            /** @todo  */
            f.changeToreadingRoom(r);

        }else{
            new TipsDialog("请先登录");
        }
    }

    static void setFrame(Frame frame){
        f=frame;
    }
}

⌨️ 快捷键说明

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