📄 form2.frm
字号:
VERSION 5.00
Begin VB.Form Form2
BorderStyle = 5 'Sizable ToolWindow
Caption = "演示界面"
ClientHeight = 5940
ClientLeft = 60
ClientTop = 285
ClientWidth = 7980
BeginProperty Font
Name = "宋体"
Size = 10.5
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
LinkTopic = "Form2"
MaxButton = 0 'False
MinButton = 0 'False
ScaleHeight = 5940
ScaleWidth = 7980
ShowInTaskbar = 0 'False
StartUpPosition = 3 '窗口缺省
Begin VB.Frame Frame6
Caption = "消费提示"
Height = 975
Left = 4080
TabIndex = 20
Top = 2280
Width = 3615
Begin VB.Label Label14
Height = 615
Left = 120
TabIndex = 21
Top = 240
Width = 3375
End
End
Begin VB.Frame Frame5
Caption = "生产提示"
Height = 975
Left = 240
TabIndex = 18
Top = 2280
Width = 3735
Begin VB.Label Label13
Height = 615
Left = 120
TabIndex = 19
Top = 240
Width = 3495
End
End
Begin VB.Frame Frame1
Caption = "缓冲池"
Height = 1455
Left = 240
TabIndex = 8
Top = 3480
Width = 7455
Begin VB.Label Label1
BackColor = &H00FFC0C0&
BorderStyle = 1 'Fixed Single
Height = 855
Index = 0
Left = 240
TabIndex = 14
Top = 360
Width = 855
End
Begin VB.Label Label1
BackColor = &H00FFC0C0&
BorderStyle = 1 'Fixed Single
Height = 855
Index = 1
Left = 1440
TabIndex = 13
Top = 360
Width = 855
End
Begin VB.Label Label1
BackColor = &H00FFC0C0&
BorderStyle = 1 'Fixed Single
Height = 855
Index = 2
Left = 2640
TabIndex = 12
Top = 360
Width = 855
End
Begin VB.Label Label1
BackColor = &H00FFC0C0&
BorderStyle = 1 'Fixed Single
Height = 855
Index = 3
Left = 3840
TabIndex = 11
Top = 360
Width = 855
End
Begin VB.Label Label1
BackColor = &H00FFC0C0&
BorderStyle = 1 'Fixed Single
Height = 855
Index = 4
Left = 5040
TabIndex = 10
Top = 360
Width = 855
End
Begin VB.Label Label1
BackColor = &H00FFC0C0&
BorderStyle = 1 'Fixed Single
Height = 855
Index = 5
Left = 6240
TabIndex = 9
Top = 360
Width = 855
End
End
Begin VB.Timer Timer3
Left = 7200
Top = 240
End
Begin VB.Frame Frame4
Caption = "满"
Height = 975
Left = 2760
TabIndex = 7
Top = 1080
Width = 2415
Begin VB.Label Label8
BackColor = &H00FFC0FF&
BorderStyle = 1 'Fixed Single
BeginProperty Font
Name = "宋体"
Size = 15
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 495
Left = 240
TabIndex = 16
Top = 360
Width = 1965
End
End
Begin VB.Frame Frame3
Caption = "空"
Height = 975
Left = 240
TabIndex = 6
Top = 1080
Width = 2295
Begin VB.Label Label2
BackColor = &H00FFC0FF&
BorderStyle = 1 'Fixed Single
BeginProperty Font
Name = "宋体"
Size = 15
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 495
Left = 240
TabIndex = 15
Top = 360
Width = 1815
End
End
Begin VB.Timer Timer2
Left = 6720
Top = 240
End
Begin VB.Timer Timer1
Left = 6240
Top = 240
End
Begin VB.CommandButton Command2
Caption = "消费"
Height = 375
Left = 1920
TabIndex = 5
Top = 5040
Width = 1335
End
Begin VB.CommandButton Command4
Caption = "生产"
Height = 375
Left = 240
TabIndex = 4
Top = 5040
Width = 1335
End
Begin VB.CommandButton Command3
Caption = "退出"
Height = 375
Left = 5400
TabIndex = 3
Top = 5040
Width = 1335
End
Begin VB.CommandButton Command11
Caption = "关于"
Height = 375
Left = 3720
TabIndex = 2
Top = 5040
Width = 1215
End
Begin VB.Frame Frame2
Caption = "互斥信号量(mutex)"
Height = 975
Left = 5400
TabIndex = 1
Top = 1080
Width = 2295
Begin VB.Label Label6
BackColor = &H00FFC0FF&
BorderStyle = 1 'Fixed Single
BeginProperty Font
Name = "宋体"
Size = 15
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 495
Left = 240
TabIndex = 17
Top = 360
Width = 1815
End
End
Begin VB.TextBox Text1
BackColor = &H00FFC0C0&
BeginProperty Font
Name = "隶书"
Size = 21.75
Charset = 134
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
ForeColor = &H00FF0000&
Height = 615
Left = 1080
Locked = -1 'True
TabIndex = 0
Text = "生产者-消费者演示界面"
Top = 120
Width = 5175
End
Begin VB.Line Line3
X1 = 0
X2 = 8040
Y1 = 3360
Y2 = 3360
End
Begin VB.Line Line2
X1 = 0
X2 = 7920
Y1 = 840
Y2 = 840
End
Begin VB.Line Line1
X1 = 0
X2 = 8040
Y1 = 2160
Y2 = 2160
End
End
Attribute VB_Name = "Form2"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Dim i, j, k, a As Integer
Dim full As Integer
Dim emputy As Integer
Private Sub Command11_Click()
MsgBox "该软件由林夕梦设计制作;联系方式:cgq@sdau.edu.cn", , "关于"
End Sub
Private Sub Command2_Click() '消费按钮
Command4.Visible = True
If Label6.Caption = "1" Then '判断缓冲池是否为空
If Label8.Caption = "" Then
MsgBox "没有产品可以消费", , "提示"
End If
MsgBox "互斥!不能消费!", , "提示"
Else
Timer2.Interval = 1500 '时钟控件开始
Label6.Caption = "1"
Label14.Caption = "消费者消费了一个产品"
End If
End Sub
Private Sub Command3_Click()
End
'退出按钮
End Sub
Private Sub Command4_Click()
'生产按钮
Label13.Caption = "生产者生产了一个产品,申请一个缓冲池"
'平判断缓冲池是否满
If Val(Label8.Caption) < 6 Then
Timer3.Interval = 1500
Label6.Caption = 1
If Label1(a).BackColor = &HFF& Then
Label14.Caption = "消费者消费了一个产品"
End If
Else
'提示
MsgBox "缓冲池已满", , "提示"
a = 0
j = 0
End If
End Sub
Private Sub Form_Load()
full = 0
emputy = 6 'emputy 理解为"空"的意思
Timer1.Interval = 0
Timer2.Interval = 0
Label2.Caption = 6
Label8.Caption = 0
End Sub
Private Sub Timer1_Timer() '生产过程中的时钟控件
If i > 5 Then '判断缓冲池是否满
MsgBox "缓冲池已满", , "提示"
Label6.Caption = "0"
Timer1.Interval = 0
Else
'不满进行生产
emputy = emputy - 1
full = full + 1
Label1(i).BackColor = &HFF00&
Label6.Caption = 1
Label2.Caption = emputy
Label8.Caption = full
i = i + 1
Label13.Caption = ""
Timer1.Interval = 0
End If
End Sub
Private Sub Timer2_Timer() '消费过程的时钟控件
If Val(Label8.Caption) = 0 Then
'缓冲池是否空
MsgBox "没有产品可供消费", , "提示"
Label6.Caption = 0
Label14.Caption = ""
Timer2.Interval = 0
Else
'不空进行消费
emputy = emputy + 1
full = full - 1
Label1(j).BackColor = &HFF&
j = j + 1
Label14.Caption = ""
Label6.Caption = 0
Label2.Caption = emputy
Label8.Caption = full
Timer2.Interval = 0
End If
End Sub
Private Sub Timer3_Timer() '生产过程的时钟控件
'当前操作的缓冲池后面的缓冲池是否为空,不空指针后移
If Label1(a).BackColor = &HFF00& Then
a = a + 1
If Label1(a).BackColor = &HFF00& Then
a = a + 1
If Label1(a).BackColor = &HFF00& Then
a = a + 1
If Label1(a).BackColor = &HFF00& Then
a = a + 1
End If
End If
End If
Label1(a).BackColor = &HFF00&
a = a + 1
emputy = emputy - 1
full = full + 1
Else
Label1(a).BackColor = &HFF00&
a = a + 1
emputy = emputy - 1
full = full + 1
End If
k = a
Label6.Caption = 0
Label2.Caption = emputy
Label8.Caption = full
Label13.Caption = ""
Timer3.Interval = 0
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -