資源簡介
操作系統 睡眠理發師模擬 有界面 ,java寫的。操作系統課程設計。。。。。。。。。。。。。。 有登陸驗證,權限控制
代碼片段和文件信息
package?hairTest;
import?java.awt.*;
import?java.awt.event.*;
import?javax.swing.*;
public?class?HairWindows?extends?Jframe?{
final?JTextField?jtf1?=?new?JTextField(4);
final?JTextField?jtf2?=?new?JTextField(4);
final?JTextField?jtf3?=?new?JTextField(4);
final?JTextArea?jta1?=?new?JTextArea(20?20);
final?JTextArea?jta2?=?new?JTextArea(20?20);
static?LoginSystem?ls;
JPanel?p1?=?new?JPanel(new?FlowLayout(50?30?10));
JPanel?p2?=?new?JPanel(new?GridLayout(1?2?10?10));
public?static?void?main(String[]?args)?{
ls?=?new?LoginSystem();
ls.launchframe();
}
public?void?launchframe()?{???//主界面
this.setLayout(new?BorderLayout());
final?JButton?jbt?=?new?JButton(“開始理發“);
this.add(p1?BorderLayout.NORTH);
p1.setBackground(Color.orange);
this.add(p2?BorderLayout.SOUTH);
p1.add(jtf1);
p1.add(new?JLabel(“人數“));
p1.add(jtf2);
p1.add(new?JLabel(“椅子“));
p1.add(jtf3);
p1.add(new?JLabel(“理發師數“));
p1.add(jbt);
jbt.setBackground(Color.magenta);
jbt.addActionListener(new?ButtonMonitor());
p2.setBackground(Color.BLACK);
p2.add(jta1);
jta1.setBackground(Color.pink);
p2.add(jta2);
jta2.setBackground(Color.lightGray);
this.settitle(“理發店模擬“);
this.setBounds(100?100?600?450);
this.setVisible(true);
this.setDefaultCloseOperation(Jframe.EXIT_ON_CLOSE);
}
/********
?*?監聽開始理發
?*?********/
class?ButtonMonitor?implements?ActionListener?{
int?hairNum?=?0;?//?待理發人數
int?hairSize?=?0;?//?椅子數
int?hairor?=?1;?//?理發師數
public?void?actionPerformed(ActionEvent?e)?{
hairNum?=?Integer.parseInt(jtf1.getText());
hairSize?=?Integer.parseInt(jtf2.getText());
hairor?=?Integer.parseInt(jtf3.getText());
HairShop?hs?=?new?HairShop(hairSize?jta1jta2jtf3);???//構造理發店
createHair?crth?=?new?createHair(hs?hairNum?jta1);???//生產理發者
consumerHair?csuh?=?new?consumerHair(hs?hairNum?jta2);??//生產理發師
new?Thread(crth).start();
for?(int?i?=?0;?i? new?Thread(csuh).start();
}
}
}
}
//登陸驗證
class?LoginSystem?extends?Jframe?implements?Runnable{
private?String?user;
private?String?password;
private?JTextField?tf?=?new?JTextField();
private?JPasswordField?pf?=?new?JPasswordField();
private?JLabel?jlb?=?new?JLabel(“用戶名:“);
private?JLabel?jlb2?=?new?JLabel(“密碼:“);
private?JButton?jbt?=?new?JButton(“登陸“);
????public??boolean?admin?=?false;??//理發師登錄Boolean
????public??boolean?users?=?false;??//理發者登錄Boolean
private?LoginSystem?ls?=?null;
????
????//登陸驗證框
public?void?launchframe(){
this.setLayout(null);
this.add(jlb);
jlb.setBounds(10?20?60?20);
this.add(tf);
tf.setBounds(75?20?100?20);
this.add(jlb2);
jlb2.setBounds(10?60?60?20);
this.add(pf);
pf.setBounds(75?60?100?20);
this.add(jbt);
jbt.setBounds(180?130?60?20);
jbt.addActionListener(new?ActionListener(){
public?void?actionPerformed(Acti
評論
共有 條評論