资源简介
读者写者问题图形界面--Java版,有图形界面,有文字提示,逻辑明确、有源代码和jar程序
代码片段和文件信息
package writerreager;
import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.text.SimpleDateFormat;
import java.util.Date;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.Jframe;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JToolBar;
public class WriterReager extends Jframe {
JButton startstopcontinend;
int a=1b=2;
ImageIcon frwdpq;
JLabel[] L;//放图片
JPanel[] LL;
JTextArea[] T;//存放信息
JScrollPane[] S;
public WriterReager(){
r= new ImageIcon(“reader.gif“);
w= new ImageIcon(“writer.gif“);
f = new ImageIcon(“free.gif“);
d = new ImageIcon(“done.gif“);
p = new ImageIcon(“play.png“);
q = new ImageIcon(“quit.png“);
settitle(“Java模拟读者写者问题!“);
setSize(800650);
JPanel panel=new JPanel();
JPanel p2 = new JPanel();
JToolBar TB = new JToolBar();
Container ct=this.getContentPane();
Data db = new Data();
L=new JLabel[7];
LL=new JPanel[7];
T= new JTextArea[7];
S= new JScrollPane[7];
for(int i=1;i<=6;i++) {
L[i]=new JLabel();
LL[i]=new JPanel();
T[i]= new JTextArea();
L[i].setPreferredSize(new Dimension(8370));
T[i].setPreferredSize(new Dimension(5501000));
L[i].setIcon(f);
S[i]= new JScrollPane();
S[i].setPreferredSize(new Dimension(650150));
LL[i].setPreferredSize(new Dimension(65070));
S[i].add(T[i]);
S[i].setViewportView(T[i]);
LL[i].add(S[i]);
}
//读者线程
final reader r1 = new reader(1L[1]T[1]db);
final reader r2 = new reader(2L[2]T[2]db);
final reader r3 = new reader(3L[3]T[3]db);
final reader r4 = new reader(4L[4]T[4]db);
//写者线程
final writer w1 = new writer(1L[5]T[5]db);
final writer w2 = new writer(2L[6]T[6]db);
start = new JButton(“开始“p);
start.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent event)
{
r1.start();
r2.start();
r3.start();
w1.start();
r4.start();
w2.start();
}});
end = new JButton(“结束“q);
end.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent event)
{ System.exit(0);
}});
TB.add(start);
TB.add(end);
add( TBBorderLayout.NORTH);
panel.add(new JLabel(f));
panel.add(new JLabel(“等待中..... “));
panel.add(new JLabel(r));
panel.add(new JLabel(“读者(前4个) “));
panel.add(new JLabel(w));
panel.ad
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 4884 2010-06-07 12:14 读者写者\dist\done.GIF
文件 6682 2010-06-05 23:23 读者写者\dist\free.GIF
文件 3053 2009-11-12 20:09 读者写者\dist\play.png
文件 2969 2009-11-12 20:08 读者写者\dist\quit.png
文件 22197 2010-06-05 16:53 读者写者\dist\reader.gif
文件 1451 2010-06-07 22:36 读者写者\dist\README.TXT
..A.SH. 20480 2010-10-06 20:25 读者写者\dist\Thumbs.db
文件 12455 2010-06-06 00:28 读者写者\dist\writer.gif
文件 12990 2010-06-07 22:36 读者写者\dist\WriterReager.jar
文件 7163 2010-06-08 12:27 读者写者\WriterReager.java
目录 0 2010-10-06 20:29 读者写者\dist
目录 0 2010-10-06 20:29 读者写者
----------- --------- ---------- ----- ----
94324 12
- 上一篇:JAVA实现GUI文件管理器
- 下一篇:安卓 usb 串口通信
评论
共有 条评论