日期:2014-05-20 浏览次数:20644 次
public void goodsShow()
{
Graphics g1=panel[1].getGraphics();
panel[1].setBackground(Color.white);
g1.setColor(Color.red);
System.out.println("商品数为:"+flag);
for(int i=0;i<flag;i++)
{
g1.fillRect(40*i, 0, 35, 40);
}
}
import java.awt.Color;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
public class MainFrame extends JFrame implements ActionListener{
private JPanel[] panel=new JPanel[3];
private DrawThread[] draw;
private JButton button1,button2,button3;
private JLabel label6;
static int flag=0;
public MainFrame()
{
setTitle("欢迎来到java世界");
setSize(1300,600);
draw=new DrawThread[3];
draw[0]=new DrawThread(100,80,0);
draw[1]=new DrawThread(400,280,1);
draw[2]=new DrawThread(700,480,2);
Font f1=new Font("宋体",Font.BOLD+Font.ITALIC,25);
Font f2=new Font("宋体",Font.BOLD+Font.HANGING_BASELINE,20);
button1=new JButton("开始生产");
button2=new JButton("开始消费");
button3=new JButton("退出");
JLabel label1=new JLabel("生产者-消费者 演示实验");
JLabel label2=new JLabel("生产者");
JLabel label3=new JLabel("缓冲池");
JLabel label4=new JLabel("消费者");
JLabel label5=new JLabel("制作人 韩旭辉");
JLabel label6=new JLabel("");
for(int i=0;i<panel.length;i++)
panel[i]=new JPanel();
label1.setFont(f1);
label5.setFont(f1);
label2.setFont(f2);
label3.setFont(f2);
label4.setFont(f2);
label6.setFont(f2);
label1.setBounds(900, 40, 400, 30);
label2.setBounds(20, 90, 80, 20);
label3.setBounds(320, 290, 80, 20);
label4.setBounds(620, 490, 80, 20);
label5.setBounds(100, 520, 400, 30);
label6.setBounds(420, 240, 400, 30);
panel[0].setBounds(100, 80, 300, 40);
panel[0].setBackground(Color.white);
panel[1].setBounds(400, 280, 320, 40);
panel[1].setBackground(Color.white);
panel[2].setBounds(700, 480, 300, 40);
panel[2].setBackground(Color.white);
button1.setBounds(520, 85, 100, 30);
button2.setBounds(1120, 485, 100, 30);
button3.setBounds(1160, 120, 100, 30);
button1.addActionListener(this);
button2.addActionListener(this);
button3.addActionListener(this);
Container contentPane = getContentPane();
contentPane.setLayout(null);
contentPane.add(label1);
contentPane.add(label2);
contentPane.add(label3);
contentPane.add(label4);
contentPane.add(label5);
contentPane.add(label6);
contentPane.add(panel[0]);
contentPane.add(panel[1]);
contentPane.add(panel[2]);
contentPane.add(button1);
contentPane.add(button2);
contentPane.add(button3);