void Menu_key_set(void) { key1 = Get_Key_1(); key2 = Get_Key_2(); key3 = Get_Key_3(); key4 = Get_Key_4(); if(key1 == 1) { func_index=table[func_index].up;//按键next按下后的索引号 OLED_Clear(); } if(key2 == 2) { func_index=table[func_index].down; OLED_Clear(); } if(key3 == 3) { func_index=table[func_index].enter;//按键next按下后的索引号 OLED_Clear(); } current_operation_index=table[func_index].current_operation;//执行当前索引号所对应的功能函数。 (*current_operation_index)();//执行当前操作函数 }添加什么函数可以检测按键松手
时间: 2023-12-06 12:39:49 浏览: 22
你可以添加一个函数来检测按键是否松开,例如:
```c
int Is_Key_Released(int key) {
switch(key) {
case 1: return Get_Key_1() == 0;
case 2: return Get_Key_2() == 0;
case 3: return Get_Key_3() == 0;
case 4: return Get_Key_4() == 0;
default: return 0;
}
}
```
然后在 `Menu_key_set` 函数中添加以下代码:
```c
if(Is_Key_Released(1)) {
// 按键 1 松开
}
if(Is_Key_Released(2)) {
// 按键 2 松开
}
if(Is_Key_Released(3)) {
// 按键 3 松开
}
if(Is_Key_Released(4)) {
// 按键 4 松开
}
```
这样就可以检测按键是否松开了。
相关问题
void Menu_key_set(void) { key1 = Get_Key_1(); key2 = Get_Key_2(); key3 = Get_Key_3(); key4 = Get_Key_4(); if(key1 == 1) { func_index=table[func_index].up;//按键next按下后的索引号 OLED_Clear(); } if(key2 == 2) { func_index=table[func_index].down; OLED_Clear(); } if(key3 == 3) { func_index=table[func_index].enter;//按键next按下后的索引号 OLED_Clear(); } current_operation_index=table[func_index].current_operation;//执行当前索引号所对应的功能函数。 (*current_operation_index)();//执行当前操作函数 }添加什么函数可以检测按键松手,请添加进原函数
可以添加一个检测按键松手的函数,例如:
```
int Get_Key_Release(void)
{
int key_release = 0;
if(Get_Key_1() == 0 && Get_Key_2() == 0 && Get_Key_3() == 0 && Get_Key_4() == 0)
{
key_release = 1;
}
return key_release;
}
```
然后在 `Menu_key_set()` 函数中添加相应的代码来检测按键是否松手,例如:
```
void Menu_key_set(void)
{
key1 = Get_Key_1();
key2 = Get_Key_2();
key3 = Get_Key_3();
key4 = Get_Key_4();
if(key1 == 1)
{
func_index = table[func_index].up;
OLED_Clear();
}
if(key2 == 2)
{
func_index = table[func_index].down;
OLED_Clear();
}
if(key3 == 3)
{
func_index = table[func_index].enter;
OLED_Clear();
}
current_operation_index = table[func_index].current_operation;
(*current_operation_index)();
while(!Get_Key_Release()); // 等待按键松手
}
```
这样就可以在每次按键操作后等待按键松手,避免出现误操作。
CREATE TABLE Reader ( reader_id INT, name VARCHAR(50), gender VARCHAR(10), birthdate DATE, phone VARCHAR(20), PRIMARY KEY (reader_id) ); CREATE TABLE Book ( book_id INT, title VARCHAR(100), author VARCHAR(50), publisher VARCHAR(50), publish_date DATE, price DECIMAL(8,2), PRIMARY KEY (book_id) ); CREATE TABLE Borrow ( borrow_id INT, reader_id INT, book_id INT, borrow_date DATE, return_date DATE, status INT, PRIMARY KEY (borrow_id), FOREIGN KEY (reader_id) REFERENCES Reader(reader_id), FOREIGN KEY (book_id) REFERENCES Book(book_id) ); CREATE TABLE Library ( library_id INT, book_id INT, quantity INT, PRIMARY KEY (library_id), FOREIGN KEY (book_id) REFERENCES Book(book_id) ); CREATE TABLE Category ( category_id INT, category_name VARCHAR(50), PRIMARY KEY (category_id) ); CREATE TABLE Admin ( admin_id INT, name VARCHAR(50), gender VARCHAR(10), phone VARCHAR(20), PRIMARY KEY (admin_id) );用Java连接上面数据库用户名root密码as101213数据库名books创建一个图书借阅系统的框架编程、实现UI重点实现程序的用户界面(UI),用户界面UI推荐使用SWING开发,界面务求美观,具有基本的菜单功能。
好的,下面是一个简单的图书借阅管理系统的Java框架代码,使用了JDBC连接MySQL数据库,并使用了Swing开发用户界面:
```java
import java.sql.*;
import javax.swing.*;
public class LibrarySystem extends JFrame {
private Connection con;
private Statement stmt;
private ResultSet rs;
public LibrarySystem() {
super("图书借阅管理系统");
setSize(800, 600);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLocationRelativeTo(null);
// 创建菜单栏
JMenuBar menuBar = new JMenuBar();
setJMenuBar(menuBar);
// 创建“读者管理”菜单
JMenu readerMenu = new JMenu("读者管理");
menuBar.add(readerMenu);
// 创建“借书管理”菜单
JMenu borrowMenu = new JMenu("借书管理");
menuBar.add(borrowMenu);
// 创建“还书管理”菜单
JMenu returnMenu = new JMenu("还书管理");
menuBar.add(returnMenu);
// 创建“图书管理”菜单
JMenu bookMenu = new JMenu("图书管理");
menuBar.add(bookMenu);
// 创建“系统设置”菜单
JMenu systemMenu = new JMenu("系统设置");
menuBar.add(systemMenu);
// 连接数据库
try {
Class.forName("com.mysql.jdbc.Driver");
con = DriverManager.getConnection("jdbc:mysql://localhost:3306/books", "root", "as101213");
stmt = con.createStatement();
} catch (Exception e) {
JOptionPane.showMessageDialog(null, "连接数据库失败:" + e.getMessage(), "错误", JOptionPane.ERROR_MESSAGE);
System.exit(0);
}
setVisible(true);
}
public static void main(String[] args) {
new LibrarySystem();
}
}
```
以上代码实现了一个基本的用户界面,并且连接了MySQL数据库。你可以根据需要添加菜单项并实现对应的功能。
当然,由于时间和篇幅的限制,以上代码仅为一个简单的示例,并没有实现具体的功能。如果需要更详细的代码,请提供更具体的需求,我会尽力提供帮助。