100分 解决java import java.awt.Point;import java.awt.Rectangle;

100分 解决java
import java.awt.Point;
import java.awt.Rectangle;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
public class Dining extends JFrame {
private static final long serialVersionUID = 1L;
private JPanel jContentPane = null;
private JButton jButton = null;
private JScrollPane jScrollPane = null;
private JTextArea jTextArea = null;
/**
* This is the default constructor
*/
static Chopsticks[] stick=new Chopsticks[5];
static Philosopher[] philosopher=new Philosopher[5];
static Thread[] thread=new Thread[5];//五个线程代表五个哲学家
public Dining() {
super();
initialize();
}
/**
* This method initializes this
*
* @return void
*/
private void initialize() {
this.setSize(365,361);
this.setLocation(new Point(240,320));
this.setContentPane(getJContentPane());
this.setTitle("哲学家就餐问题");
}
如何设置入口,使程序能运行
public void run(){
while(true){
eat();//吃东西
try{
Thread.sleep(7000);//睡眠7000毫秒
}catch(InterruptedException e){
e.printStackTrace();
}
think();//思考
try{
Thread.sleep(7000);
}catch(InterruptedException e){
e.printStackTrace();
}
}
}
}
}
紫绶高轩 1年前 已收到1个回答 举报

jerryyeoh 春芽

共回答了14个问题采纳率:85.7% 举报

加一个main方法噻
public static void main(String args[]){
Dining d=new Dining();
d.setVisible(true);
}
这个小程序貌似在讲解线程的同步和死锁
问题很经典,不过如果用银行转账那个来举例应该更容易理解

1年前

10
可能相似的问题
Copyright © 2024 YULUCN.COM - 雨露学习互助 - 16 q. 0.023 s. - webmaster@yulucn.com