(一)使用图形化界面完成游戏设计。游戏主题不限,要有増删改查等功能。图形化方法说明:
1、JOptionPane showMessageDialog(parentCompopent //父对话框
message,//显示信息
title, //标题
messageType, //图标类型
icon)/图片如: new ImageIcon("images/皇帝png")
2、Object result=//返回值类型为Object-
JOptionPane. showInputDialog(parentComponent //父对话框
message, //显示信息
title, //标题
messageType. //图标类型
icon,//图片如: new ImageIcon("images/皇帝png")
selectionValues. //输入内容,如以数组形式放入后枚举
initialSelectionValue)//默认输入值
3、音乐
AudioClip sound = Applet .newAudioClip(new File(" sounds背景音乐wav") toURL());
eclipse做一个具有增删改查功能的小游戏
- 写回答
- 好问题 0 提建议
- 追加酬金
- 关注问题
- 邀请回答
-
2条回答 默认 最新
- m0_64824573 2022-06-07 11:24关注
增删改查
public class Genggai implements ActionListener{
Connection con;
Statement stmt;
String sql;
ResultSet rs;
StringBuffer sb = new StringBuffer();JTextField jtf2 = new JTextField("Tom",10); JTextField jtf3 = new JTextField(10); JTextField jtf4 = new JTextField(10); JTextField jtf7 = new JTextField(10); JTextField jtf5 = new JTextField(10); JTextField jtf6 = new JTextField(10); JTextField jtf8 = new JTextField(10); JTextField jtf9 = new JTextField(10); JTextArea jta10 = new JTextArea(50, 40); public void actionPerformed(ActionEvent e) { String str = e.getActionCommand(); if ("查询".equals(str)) { searchEmp(); } else if ("增加".equals(str)) { addEmp(); } else if ("修改".equals(str)) { alterEmp(); } else if ("撤除".equals(str)) { deleteEmp(); } } Genggai() { createGUI(); connectToDataBase(); alterEmp(); } public Connection connectToDataBase() { System.out.println(con); return con; } public void searchEmp() { jta10.setText(""); try { stmt = con.createStatement(); sql = "select * from Mstar where chineseName=" + jtf2.getText().toLowerCase().trim() + "or id=" + jtf3.getText().toLowerCase().trim() + "or engName=" + jtf4.getText().toLowerCase().trim() + "or UNIT=" + jtf5.getText().toLowerCase().trim() + "or TEAM=" + jtf6.getText().toLowerCase().trim() + "or Phone=" + jtf7.getText().toLowerCase().trim() + "or region=" + jtf8.getText().toLowerCase().trim() + "or busStation=" + jtf9.getText().toLowerCase().trim(); stmt.executeQuery(sql); rs = stmt.getResultSet(); ResultSetMetaData meta = rs.getMetaData(); int cols = meta.getColumnCount(); while (rs.next()) { for (int i = 1; i <= cols; i++) { sb.append(" " + meta.getColumnName(i) + " ="); sb.append(rs.getString(i)); } sb.append("\n"); jta10.setText(sb.toString()); } } catch (SQLException e11) { e11.printStackTrace(); } } public void addEmp() { try { stmt = con.createStatement(); sql = "update Mstar values(" + jtf2.getText() + jtf4.getText() + ")"; int i = stmt.getUpdateCount(); if ((jtf2.getText() != null) && (jtf4.getText() != null)) { stmt.executeUpdate(sql); jta10.setText("添加记录成功" + i + "条"); } else { jta10.setText("带*号项为添加记录时不能为空"); } } catch (SQLException e1) { e1.printStackTrace(); } } public void deleteEmp() { searchEmp(); try { stmt = con.createStatement(); sql = "delete from Mstar where chineseName=" + jtf2.getText().toLowerCase().trim() + "or id=" + jtf3.getText().toLowerCase().trim() + "or engName=" + jtf4.getText().toLowerCase().trim() + "or UNIT=" + jtf5.getText().toLowerCase().trim() + "or TEAM=" + jtf6.getText().toLowerCase().trim() + "or Phone=" + jtf7.getText().toLowerCase().trim() + "or region=" + jtf8.getText().toLowerCase().trim() + "or busStation=" + jtf9.getText().toLowerCase().trim(); stmt.executeUpdate(sql); int i = stmt.getUpdateCount(); jta10.setText("撤除操作成功" + i + "条"); } catch (SQLException e) { e.printStackTrace(); } } public void alterEmp() { searchEmp(); sql = "update Mstar set chineseName=" + jtf2.getText().toLowerCase().trim() + "and id=" + jtf3.getText().toLowerCase().trim() + "and engName=" + jtf4.getText().toLowerCase().trim() + "and UNIT=" + jtf5.getText().toLowerCase().trim() + "and TEAM=" + jtf6.getText().toLowerCase().trim() + "and Phone=" + jtf7.getText().toLowerCase().trim() + "and region=" + jtf8.getText().toLowerCase().trim() + "and busStation=" + jtf9.getText().toLowerCase().trim(); int i = 0; try { stmt.executeUpdate(sql); i = stmt.getUpdateCount(); } catch (SQLException e) { e.printStackTrace(); } jta10.setText("修改操作成功" + i + "条"); } public void createGUI() { JFrame jf = new JFrame("员工信息管理系统"); jf.setLayout(new GridLayout(2, 1)); // jf.setLayout(new GridLayout(10,2)); JPanel jp00 = new JPanel(new GridLayout(5, 4)); JPanel jp1 = new JPanel(); JButton jb11 = new JButton("查询"); jb11.addActionListener(this); JButton jb12 = new JButton("增加"); jb12.addActionListener(this); jp1.add(jb11); jp1.add(jb12); jp00.add(jp1); JPanel jp11 = new JPanel(); JButton jb111 = new JButton("修改"); jb111.addActionListener(this); JButton jb112 = new JButton("撤除"); jb112.addActionListener(this); jp11.add(jb111); jp11.add(jb112); jp00.add(jp11); JPanel jp2 = new JPanel(); JLabel jl2 = new JLabel("姓名 * "); jp2.add(jl2); jp2.add(jtf2); jp00.add(jp2); JPanel jp3 = new JPanel(); JLabel jl3 = new JLabel("密码"); jp3.add(jl3); jp3.add(jtf3); jp00.add(jp3); JPanel jp4 = new JPanel(); JLabel jl4 = new JLabel("密码 *"); jp4.add(jl4); jp4.add(jtf4); jp00.add(jp4); JPanel jp5 = new JPanel(); JLabel jl5 = new JLabel("UNIT "); jp5.add(jl5); jp5.add(jtf5); jp00.add(jp5); JPanel jp6 = new JPanel(); JLabel jl6 = new JLabel("确认密码* "); jp6.add(jl6); jp6.add(jtf6); jp00.add(jp6); JPanel jp7 = new JPanel(); JLabel jl7 = new JLabel("手机号 * "); jp7.add(jl7); jp7.add(jtf7); jp00.add(jp7); JPanel jp8 = new JPanel(); JLabel jl8 = new JLabel("区域 "); jp8.add(jl8); jp8.add(jtf8); jp00.add(jp8);
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报
悬赏问题
- ¥15 做个有关计算的小程序
- ¥15 MPI读取tif文件无法正常给各进程分配路径
- ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
- ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
- ¥15 setInterval 页面闪烁,怎么解决
- ¥15 如何让企业微信机器人实现消息汇总整合
- ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
- ¥15 如何用Python爬取各高校教师公开的教育和工作经历
- ¥15 TLE9879QXA40 电机驱动
- ¥20 对于工程问题的非线性数学模型进行线性化