20. 数字逻辑门(AND门)
摘要:本文展示了一个数字逻辑AND门的实现,使用ArkUI框架构建交互界面。通过两个可点击的输入圆点(Input A和Input B)控制输入状态,当且仅当两个输入都为高电平时,输出圆点显示绿色表示逻辑"1"。界面包含门电路符号、实时状态显示和逻辑值文字说明,直观演示了与门"全1出1"的基本特性。
·
10. 数字逻辑门(AND门)
场景:演示与门逻辑,只有两个输入都为高电平时,输出才为高。
核心逻辑:简单的状态判断与颜色反馈。
@Entry
@Component
struct LogicGateAND {
@State inputA: boolean = false
@State inputB: boolean = false
build() {
Column({ space: 40 }) {
Text('AND Gate 与门').fontSize(24)
Row({ space: 50 }) {
// Input A
Column() {
Text('Input A')
Circle()
.width(40)
.height(40)
.fill(this.inputA ? Color.Green : Color.Gray)
.onClick(() => this.inputA = !this.inputA)
}
// Gate Symbol
Text('&').fontSize(40).borderWidth(2).padding(10)
// Output
Column() {
Text('Output')
Circle()
.width(40)
.height(40)
.fill((this.inputA && this.inputB) ? Color.Green : Color.Gray)
}
}
// Input B below A
Column() {
Text('Input B')
Circle()
.width(40)
.height(40)
.fill(this.inputB ? Color.Green : Color.Gray)
.onClick(() => this.inputB = !this.inputB)
}
Text(`逻辑: ${this.inputA && this.inputB ? '1 (TRUE)' : '0 (FALSE)'}`)
.fontSize(20)
.fontWeight(FontWeight.Bold)
}
.width('100%')
.height('100%')
.justifyContent(FlexAlign.Center)
}
}
更多推荐


所有评论(0)