[原创]配置Dev c++热键实现快速注释

devc++编译器为目前蓝桥杯大赛所统一使用的编译器,对于习惯了Vim和Codeblocks编译器的朋友来说似乎用起来不大习惯,也没有看到关于devC++中的多行迅速注释,新建cpp文件模板这些方便功能的文章,那就自己开动了。


1.新建文档模板

每次新建的main文件使用统一模板,将自己常用的头文件和宏写在里面在比赛中会比较方便,这里教给大家devc++设置template的方法。

找到Devc++安装路径,这里安装在C盘,修改templates文件夹中的ConsoleApp_cpp文件即可。那么之后每次新建的project都会拥有统一自定义的宏。






2.快速注释

在Tools——Configure ShortCuts下可以进行快捷键的设置。

多行注释功能在如图所示的位置,光标选中后直接按下键盘上的快捷键即可。



写这两个功能,如果有需要其他功能的朋友可以留言给卤煮,露珠去研究。

  • 1
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
好的,我可以为您提供一个简单的Java登录页面,并且演示如何用Java连接MySQL数据库并实现商品库存管理。以下是详细步骤: 1. 创建Java项目并添加MySQL连接器 首先,您需要创建一个Java项目,在该项目中添加 MySQL 连接器。您可以在此处下载最新版本的 MySQL Connector/J:https://dev.mysql.com/downloads/connector/j/ 将下载的 JAR 文件添加到您的项目的classpath中。 2. 创建登录页面 在您的 Java 项目中,创建一个登录页面。您可以使用Swing或JavaFX创建登录页面。 下面是一个简单的Swing登录页面示例: ```java import javax.swing.*; import java.awt.*; import java.awt.event.*; public class Login extends JFrame implements ActionListener { JLabel l1, l2, l3; JTextField tf1; JPasswordField pf2; JButton b1, b2; Login() { setTitle("登录"); setSize(300, 200); setLayout(null); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); l1 = new JLabel("用户名:"); l1.setBounds(40, 20, 100, 20); add(l1); tf1 = new JTextField(); tf1.setBounds(150, 20, 100, 20); add(tf1); l2 = new JLabel("密码:"); l2.setBounds(40, 50, 100, 20); add(l2); pf2 = new JPasswordField(); pf2.setBounds(150, 50, 100, 20); add(pf2); b1 = new JButton("登录"); b1.setBounds(40, 100, 80, 30); b1.addActionListener(this); add(b1); b2 = new JButton("取消"); b2.setBounds(150, 100, 80, 30); b2.addActionListener(this); add(b2); } public void actionPerformed(ActionEvent ae) { String uname = tf1.getText(); String pass = pf2.getText(); if (ae.getSource() == b1) { if (uname.equals("admin") && pass.equals("admin")) { JOptionPane.showMessageDialog(this, "登录成功"); dispose(); new InventoryManagement(); } else { JOptionPane.showMessageDialog(this, "用户名或密码错误"); } } else { dispose(); } } public static void main(String[] args) { new Login().setVisible(true); } } ``` 3. 创建商品库存管理页面 创建一个新的 Java 类,名为 InventoryManagement,该类将显示商品库存管理界面。 ```java import javax.swing.*; import java.awt.*; import java.awt.event.*; public class InventoryManagement extends JFrame implements ActionListener { JLabel l1, l2, l3, l4, l5, l6; JTextField tf1, tf2, tf3, tf4, tf5; JButton b1, b2, b3, b4; JTextArea ta; InventoryManagement() { setTitle("商品库存管理"); setSize(500, 400); setLayout(null); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); l1 = new JLabel("商品编号:"); l1.setBounds(20, 20, 100, 20); add(l1); tf1 = new JTextField(); tf1.setBounds(120, 20, 100, 20); add(tf1); l2 = new JLabel("商品名称:"); l2.setBounds(20, 50, 100, 20); add(l2); tf2 = new JTextField(); tf2.setBounds(120, 50, 100, 20); add(tf2); l3 = new JLabel("商品规格:"); l3.setBounds(20, 80, 100, 20); add(l3); tf3 = new JTextField(); tf3.setBounds(120, 80, 100, 20); add(tf3); l4 = new JLabel("商品单价:"); l4.setBounds(20, 110, 100, 20); add(l4); tf4 = new JTextField(); tf4.setBounds(120, 110, 100, 20); add(tf4); l5 = new JLabel("商品数量:"); l5.setBounds(20, 140, 100, 20); add(l5); tf5 = new JTextField(); tf5.setBounds(120, 140, 100, 20); add(tf5); b1 = new JButton("新增"); b1.setBounds(20, 180, 80, 30); b1.addActionListener(this); add(b1); b2 = new JButton("查询"); b2.setBounds(110, 180, 80, 30); b2.addActionListener(this); add(b2); b3 = new JButton("修改"); b3.setBounds(200, 180, 80, 30); b3.addActionListener(this); add(b3); b4 = new JButton("删除"); b4.setBounds(290, 180, 80, 30); b4.addActionListener(this); add(b4); ta = new JTextArea(); ta.setBounds(20, 220, 440, 120); add(ta); setVisible(true); } public void actionPerformed(ActionEvent ae) { String cmd = ae.getActionCommand(); if (cmd.equals("新增")) { addProduct(); } else if (cmd.equals("查询")) { searchProduct(); } else if (cmd.equals("修改")) { updateProduct(); } else if (cmd.equals("删除")) { deleteProduct(); } } private void addProduct() { String id = tf1.getText(); String name = tf2.getText(); String spec = tf3.getText(); double price = Double.parseDouble(tf4.getText()); int quantity = Integer.parseInt(tf5.getText()); try { // 连接数据库 Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/inventory", "root", "password"); // 执行插入语句 PreparedStatement ps = conn.prepareStatement("INSERT INTO products (id, name, spec, price, quantity) VALUES (?, ?, ?, ?, ?)"); ps.setString(1, id); ps.setString(2, name); ps.setString(3, spec); ps.setDouble(4, price); ps.setInt(5, quantity); ps.executeUpdate(); ta.setText("新增商品成功"); } catch (Exception e) { e.printStackTrace(); ta.setText("新增商品失败:" + e.getMessage()); } } private void searchProduct() { String id = tf1.getText(); try { // 连接数据库 Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/inventory", "root", "password"); // 执行查询语句 PreparedStatement ps = conn.prepareStatement("SELECT * FROM products WHERE id = ?"); ps.setString(1, id); ResultSet rs = ps.executeQuery(); if (rs.next()) { tf2.setText(rs.getString("name")); tf3.setText(rs.getString("spec")); tf4.setText(Double.toString(rs.getDouble("price"))); tf5.setText(Integer.toString(rs.getInt("quantity"))); ta.setText(""); } else { ta.setText("没有找到编号为 " + id + " 的商品"); } } catch (Exception e) { e.printStackTrace(); ta.setText("查询商品失败:" + e.getMessage()); } } private void updateProduct() { String id = tf1.getText(); String name = tf2.getText(); String spec = tf3.getText(); double price = Double.parseDouble(tf4.getText()); int quantity = Integer.parseInt(tf5.getText()); try { // 连接数据库 Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/inventory", "root", "password"); // 执行更新语句 PreparedStatement ps = conn.prepareStatement("UPDATE products SET name = ?, spec = ?, price = ?, quantity = ? WHERE id = ?"); ps.setString(1, name); ps.setString(2, spec); ps.setDouble(3, price); ps.setInt(4, quantity); ps.setString(5, id); int result = ps.executeUpdate(); if (result > 0) { ta.setText("修改商品成功"); } else { ta.setText("没有找到编号为 " + id + " 的商品"); } } catch (Exception e) { e.printStackTrace(); ta.setText("修改商品失败:" + e.getMessage()); } } private void deleteProduct() { String id = tf1.getText(); try { // 连接数据库 Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/inventory", "root", "password"); // 执行删除语句 PreparedStatement ps = conn.prepareStatement("DELETE FROM products WHERE id = ?"); ps.setString(1, id); int result = ps.executeUpdate(); if (result > 0) { ta.setText("删除商品成功"); tf1.setText(""); tf2.setText(""); tf3.setText(""); tf4.setText(""); tf5.setText(""); } else { ta.setText("没有找到编号为 " + id + " 的商品"); } } catch (Exception e) { e.printStackTrace(); ta.setText("删除商品失败:" + e.getMessage()); } } public static void main(String[] args) { new InventoryManagement(); } } ``` 4. 创建MySQL数据库 在您的MySQL数据库中,创建一个名为“inventory”的新数据库,并创建一个名为“products”的新表,该表包含以下列: - id:VARCHAR - name:VARCHAR - spec:VARCHAR - price:DOUBLE - quantity:INT ```sql CREATE DATABASE inventory; USE inventory; CREATE TABLE products ( id VARCHAR(10) PRIMARY KEY, name VARCHAR(50), spec VARCHAR(50), price DOUBLE, quantity INT ); ``` 现在您可以编译并运行您的Java程序,以查看它是否可以连接到MySQL数据库并实现商品库存管理了。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值