?? main.java
字號:
package com.gui3;import java.awt.*;import java.awt.event.*;import javax.swing.*;public class Main implements ActionListener{ private JFrame frame; private Container contentPane; private JButton vipBtn,normBtn; private JLabel mainLbl,vipLbl,normLbl; private Data vipData,normData; public Main() { frame=new JFrame("Main"); frame.setBounds(250,300,500,300); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); contentPane=frame.getContentPane(); (new Worker(1,"1號VIP柜臺")).go(); (new Worker(2,"2號普通柜臺")).go(); (new Worker(3,"3號普通柜臺")).go(); vipData=new Data(); normData=new Data(); initGUI(); } public void initGUI() { contentPane.setLayout(new BorderLayout()); mainLbl=new JLabel(); contentPane.add(mainLbl,BorderLayout.CENTER); vipLbl=new JLabel(); normLbl=new JLabel(); JPanel p1=new JPanel(new FlowLayout()); p1.add(vipLbl); p1.add(normLbl); vipBtn=new JButton("vip用戶取號"); normBtn=new JButton("普通用戶取號"); JPanel p2=new JPanel(new FlowLayout()); p2.add(vipBtn); p2.add(normBtn); JPanel p=new JPanel(new GridLayout(2,1)); p.add(p1); p.add(p2); contentPane.add(p,BorderLayout.SOUTH); vipBtn.addActionListener(this); normBtn.addActionListener(this); } public void actionPerformed(ActionEvent e) { if(e.getSource()==vipBtn) { vipData.add(); //vipData.print(); vipLbl.setText("您的號碼為vip:"+vipData.getLast()+"號"); } if(e.getSource()==normBtn) { normData.add(); //normData.print(); normLbl.setText("您的號碼為普通業(yè)務:"+normData.getLast()+"號"); } } public void go() { frame.setVisible(true); } public class Worker implements ActionListener { private JFrame frame; private Container contentPane; private JButton startBtn,nextBtn,stopBtn; private JLabel informLbl; private int id; public Worker(int id,String title) { this.id=id; frame=new JFrame(title); frame.setBounds(100+300*(id-1),100,300,200); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); contentPane=frame.getContentPane(); initGUI(); } public void initGUI() { contentPane.setLayout(new BorderLayout()); informLbl=new JLabel(); contentPane.add(informLbl,BorderLayout.CENTER); startBtn=new JButton("開始受理"); nextBtn=new JButton("下一位顧客"); stopBtn=new JButton("停止受理"); nextBtn.setEnabled(false); stopBtn.setEnabled(false); JPanel p=new JPanel(new FlowLayout()); p.add(startBtn); p.add(nextBtn); p.add(stopBtn); contentPane.add(p,BorderLayout.SOUTH); startBtn.addActionListener(this); nextBtn.addActionListener(this); stopBtn.addActionListener(this); } /*public void actionPerformed(ActionEvent e) { if(e.getSource()==startBtn||e.getSource()==nextBtn) { startBtn.setEnabled(false); nextBtn.setEnabled(true); stopBtn.setEnabled(true); if(id==1) { if(vipData.getFirst()==-1) { informLbl.setText("暫無排隊!"); mainLbl.setText("VIP柜臺暫無排隊!"); } else { informLbl.setText("正在辦理VIP:"+vipData.getFirst()+"號"); vipData.remove(); vipData.print(); if(vipData.getFirst()==-1) mainLbl.setText("VIP柜臺暫無排隊!"); else mainLbl.setText("請VIP"+vipData.getFirst()+"號到VIP柜臺辦理"); } } if(id==2||id==3) { if(vipData.size()<=3) { if(normData.getFirst()==-1) { informLbl.setText("暫無排隊!"); mainLbl.setText(id+"號普通柜臺暫無排隊!"); } else { informLbl.setText("正在辦理普通:"+normData.getFirst()+"號"); normData.remove(); normData.print(); if(normData.getFirst()==-1) mainLbl.setText(id+"號普通柜臺暫無排隊!"); else mainLbl.setText("請普通"+normData.getFirst()+"號到"+id+"號柜臺辦理"); } } else { if(vipData.getFirst()==-1) { informLbl.setText("暫無排隊!"); mainLbl.setText("VIP柜臺暫無排隊!"); } else { informLbl.setText("正在辦理VIP:"+vipData.getFirst()+"號"); vipData.remove(); vipData.print(); if(vipData.getFirst()==-1) mainLbl.setText("VIP柜臺暫無排隊!"); else mainLbl.setText("請VIP"+vipData.getFirst()+"號到VIP柜臺辦理"); } } } } if(e.getSource()==nextBtn) { } if(e.getSource()==stopBtn) { startBtn.setEnabled(true); nextBtn.setEnabled(false); stopBtn.setEnabled(false); } }*/ public void actionPerformed(ActionEvent e) { if(e.getSource()==startBtn||e.getSource()==nextBtn) { startBtn.setEnabled(false); nextBtn.setEnabled(true); stopBtn.setEnabled(true); if(id==1&&vipData.size()>0) { mainLbl.setText("請VIP"+vipData.getFirst()+"號到VIP"+id+"號柜臺辦理!"); informLbl.setText("正在辦理VIP"+vipData.getFirst()+"號貴客!"); vipData.remove(); } if(id!=1&&normData.size()>0&&vipData.size()<=3) { mainLbl.setText("請普通"+normData.getFirst()+"號到VIP"+id+"號柜臺辦理!"); informLbl.setText("正在辦理普通"+normData.getFirst()+"號普通客戶!"); normData.remove(); } if(id!=1&&vipData.size()>3) { mainLbl.setText("請VIP"+vipData.getFirst()+"號到"+id+"號柜臺辦理!"); informLbl.setText("正在辦理VIP"+vipData.getFirst()+"號貴客!"); vipData.remove(); } } if(e.getSource()==stopBtn) { startBtn.setEnabled(true); nextBtn.setEnabled(false); stopBtn.setEnabled(false); } } public void go() { frame.setVisible(true); } } public static void main(String args[]) { (new Main()).go(); }}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -