改错。okBtn.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { // TODO Auto-generated method stub student a =new student(); String newpassword=pField.getText(); int c = 0; if (newpassword.equals("")) { JOptionPane.showMessageDialog(null, "新密码不能为空", "warning", JOptionPane.PLAIN_MESSAGE); } else { c = studentDao.studentUpdate(newpassword); if (c == 1) { JOptionPane.showMessageDialog(null, "更新记录成功", "成功", JOptionPane.PLAIN_MESSAGE); } } } });

时间: 2024-03-24 22:37:45 浏览: 20
改错后的代码如下: ``` okBtn.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { // TODO Auto-generated method stub String newpassword = pField.getText(); int c = 0; if (newpassword.equals("")) { JOptionPane.showMessageDialog(null, "新密码不能为空", "warning", JOptionPane.PLAIN_MESSAGE); } else { studentDao studentDao = new studentDao(); c = studentDao.studentUpdate(newpassword); if (c == 1) { JOptionPane.showMessageDialog(null, "更新记录成功", "成功", JOptionPane.PLAIN_MESSAGE); } } } }); ``` 修改说明: 1. 在 actionPerformed 方法中实例化了 studentDao 对象,以便调用其方法。 2. 将 `student a = new student();` 改为 `studentDao studentDao = new studentDao();`,以便正确创建 studentDao 对象。 3. 将 `String newpassword = pField.getText();` 的位置移到了 `studentDao` 实例化前面,以便在执行更新操作前获取用户输入的新密码。

相关推荐

java这段代码private void CreateMainWindow(){ this.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); WindowBar = new JMenuBar(); this.setJMenuBar(WindowBar); this.setTitle("停车场管理系统"); int WindowHeight = 300; int WindowWidth = 400; Dimension Screen = Toolkit.getDefaultToolkit().getScreenSize(); int ScreenWidth = Screen.width; int ScreenHeight = Screen.height; this.setResizable(false); this.setLayout(null); this.setBounds((ScreenWidth-WindowWidth)/2,(ScreenHeight-WindowHeight)/2,WindowWidth,WindowHeight); jLabelTitle = new JLabel(); getContentPane().add(jLabelTitle); jLabelTitle.setText("欢迎进入"); jLabelTitle.setBounds(130, 50, 141, 30); //jLabelTitle.setLocation(100, 20); jLabelTitle.setFont(new java.awt.Font("宋体",1,20)); jLabelTitle.setHorizontalAlignment(SwingConstants.CENTER); jLabel = new JLabel(); getContentPane().add(jLabel); getContentPane().add(jLabelTitle); jLabel.setText("停车场信息管理系统"); jLabel.setBounds(50, 100, 300, 30); jLabel.setFont(new java.awt.Font("宋体",1,30)); jLabel.setHorizontalAlignment(SwingConstants.CENTER); notMenu = new JMenu("管理模式"); UserMenu = new JMenu("信息管理"); TypeMenu = new JMenu("车位管理"); WindowBar.add(UserMenu); WindowBar.add(notMenu); WindowBar.add(TypeMenu); JMenuItem AddItem ,DeleteItem,ChangeItem,QueryItem; AddItem = new JMenuItem("添加"); DeleteItem = new JMenuItem("删除"); ChangeItem = new JMenuItem("修改"); QueryItem = new JMenuItem("查询"); notMenu.add(AddItem); notMenu.add(DeleteItem); notMenu.add(ChangeItem); notMenu.add(QueryItem); AddItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { // TODO Auto-generated method stub //MainWindow.this.setVisible(false); AddFrame add = new AddFrame(); add.setVisible(true); } }); QueryItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { // TODO Auto-generated method stub //MainWindow.this.setVisible(false); QueryFrame query = new QueryFrame(); query.setVisible(true); } }); }怎么设置点击按钮打开另一个窗口,该如何修改

package 软件本科9班小罗; import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.beans.Statement; import java.sql.*; import javax.swing.*; public class Java06 extends JFrame implements ActionListener{ JButton Button; JLabel s1; JTextField text; JTextArea ta; Connection conn; java.sql.Statement stat1; java.sql.Statement stat2; ResultSet rs1,rs2; public Java06() { super("中英文查询"); Button=new JButton("查询"); Button.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { chazhao(); } }); s1=new JLabel("输入要查询的单词:"); text =new JTextField("word",20); ta = new JTextArea("工作",7,36); JPanel panel=new JPanel(); panel.add(s1); panel.add(text); panel.add(Button); JPanel panel2=new JPanel(); panel2.add(ta); Container con=getContentPane(); con.add(panel,BorderLayout.NORTH); con.add(panel2); setSize(400,200); } public void chazhao() { String i; try { Class.forName("com.mysql.jdbc.Driver");//加载连接驱动; conn=DriverManager.getConnection("jdbc:mysql://localhost:3306/sys?serverTimezone=UTC", "root", "123456"); } catch (ClassNotFoundException e) { // TODO Auto-generated catch block System.out.println("加载驱动失败"); } catch (SQLException e) { System.out.println("获取连接失败"); } String sql1="select 中文 from book where 英文="+"\""+text+"\""; String sql2="select 英文 from book where 中文="+"\""+text+"\""; try { stat1=conn.createStatement(); rs1=stat1.executeQuery(sql1); stat2=conn.createStatement(); rs2=stat2.executeQuery(sql2); while(rs1.next()) { System.out.println(rs1.getString("中文")); } while (rs2.next()) { System.out.println(rs2.getString("英文")); } } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } } public static void main(String[] args) { new Java06().setVisible(true); } @Override public void actionPerformed(ActionEvent e) { // TODO Auto-generated method stub if(e.getSource()==Button) { String text=ta.getText(); ta.setText(text);; } } }这个代码中哪里有错呀,运行不了,还连接不成数据库

帮我改写的能运行起来package com.swingtest; import java.awt.Container; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.*; import javax.swing.table.DefaultTableModel; public class StudentManger extends JFrame implements ActionListener { JLabel lstname = new JLabel("学生姓名: "); JTextField tf_name = new JTextField(12); JLabel lmajor = new JLabel("专业"); JTextField tf_major = new JTextField(); JButton btnOK = new JButton("添加"); JButton btnDelete = new JButton("删除"); JButton btnQuit = new JButton("退出"); JTable table; DefaultTableModel model; public void studentManger(String name) { // TODO Auto-generated constructor stub JLabel welcome = new JLabel(name +",欢迎登录!"); setTitle("学生管理"); setSize(400,400); welcome.setBounds(50,20,200,20); lstname.setBounds(50,20,200,20); tf_name.setBounds(150,50,100,20); lmajor.setBounds(50,80,100,20); tf_major.setBounds(150,80,100,20); btnOK.setBounds(80,110,60,20); btnDelete.setBounds(150,110,60,20); btnQuit.setBounds(220,110,60,20); Container c = getContentPane(); JPanel panel = new JPanel(); panel.setLayout(null); panel.add(welcome); panel.add(lstname); panel.add(tf_name); panel.add(lmajor); panel.add(tf_major); panel.add(btnOK); panel.add(btnDelete); panel.add(btnQuit); String[] colName = {"姓名","专业"}; model = new DefaultTableModel(colName,0); table = new JTable(model); JScrollPane scrollPane = new JScrollPane(table); c.setLayout(new SpringLayout()); c.add(panel); c.add(scrollPane); setLocationRelativeTo(null); setVisible(true); btnOK.addActionListener(this); btnDelete.addActionListener(this); btnQuit.addActionListener(this); } @Override public void actionPerformed(ActionEvent e) { // TODO Auto-generated method stub Object ob = e.getSource(); if(ob == btnQuit) { System.exit(0); }else if(ob ==btnOK) { String[] stuInfo = {tf_name.getText(),tf_major.getText()}; model.addRow(stuInfo); tf_name.setText(""); tf_major.setText(""); }else if(ob == btnDelete) { if(table.getSelectedRow()<0) { JOptionPane.showMessageDialog(null,"请在表格中选中要删除的行");} else { model.removeRow(table.getSelectedRow()); } }} public static void main(String[] args) { new StudentManger(); } }

import java.awt.; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import java.util.ArrayList; import java.util.List; import javax.swing.; public class Tf extends JFrame { private static final long serialVersionUID = -9207842705924169844L; private static final int width = 500; private static final int height = 500; private MyPanel panel = new MyPanel(); JButton cButton; JPanel panel1; public Tf() { super(); setTitle("三点作图"); setSize(width, height); setLayout(new BorderLayout()); add(panel, BorderLayout.CENTER); panel1 = new JPanel(); cButton = new JButton("清除"); panel1.add(cButton); cButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { panel.repaint(); } }); getContentPane().add(panel); getContentPane().add(panel1, "South"); setLocation((int) (Toolkit.getDefaultToolkit().getScreenSize().getWidth() - width) / 2, (int) (Toolkit.getDefaultToolkit().getScreenSize().getHeight() - height) / 2); setDefaultCloseOperation(EXIT_ON_CLOSE); setVisible(true); setResizable(true); } public static void main(String[] args) { new Tf(); } class MyPanel extends JPanel { private static final long serialVersionUID = -701381909057737726L; private List pl = new ArrayList(); Graphics g; public MyPanel() { super(); setBackground(Color.WHITE); try { addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { // TODO Auto-generated method stub pl.add(e.getPoint()); if (pl.size() == 3) { draw(); pl.clear(); } } }); } catch (Exception e) { System.out.println("捕获异常: " + e); } } private void draw() { if (g == null) g = getGraphics(); try { g.drawLine(pl.get(0).x, pl.get(0).y, pl.get(1).x, pl.get(1).y); g.drawLine(pl.get(1).x, pl.get(1).y, pl.get(2).x, pl.get(2).y); g.drawLine(pl.get(0).x, pl.get(0).y, pl.get(2).x, pl.get(2).y); } catch (Exception e) { System.out.println("捕获异常:" + e); } } } }在这段代码上增加一个保存按钮来保存画完的三角形

最新推荐

recommend-type

新建文本文档.txt

新建文本文档
recommend-type

开源Git gui工具Fork

开源Git gui工具Fork,CSDN能找到教程,但是资料不多,推荐用Tortoise
recommend-type

zigbee-cluster-library-specification

最新的zigbee-cluster-library-specification说明文档。
recommend-type

管理建模和仿真的文件

管理Boualem Benatallah引用此版本:布阿利姆·贝纳塔拉。管理建模和仿真。约瑟夫-傅立叶大学-格勒诺布尔第一大学,1996年。法语。NNT:电话:00345357HAL ID:电话:00345357https://theses.hal.science/tel-003453572008年12月9日提交HAL是一个多学科的开放存取档案馆,用于存放和传播科学研究论文,无论它们是否被公开。论文可以来自法国或国外的教学和研究机构,也可以来自公共或私人研究中心。L’archive ouverte pluridisciplinaire
recommend-type

MATLAB柱状图在信号处理中的应用:可视化信号特征和频谱分析

![matlab画柱状图](https://img-blog.csdnimg.cn/3f32348f1c9c4481a6f5931993732f97.png) # 1. MATLAB柱状图概述** MATLAB柱状图是一种图形化工具,用于可视化数据中不同类别或组的分布情况。它通过绘制垂直条形来表示每个类别或组中的数据值。柱状图在信号处理中广泛用于可视化信号特征和进行频谱分析。 柱状图的优点在于其简单易懂,能够直观地展示数据分布。在信号处理中,柱状图可以帮助工程师识别信号中的模式、趋势和异常情况,从而为信号分析和处理提供有价值的见解。 # 2. 柱状图在信号处理中的应用 柱状图在信号处理
recommend-type

HSV转为RGB的计算公式

HSV (Hue, Saturation, Value) 和 RGB (Red, Green, Blue) 是两种表示颜色的方式。下面是将 HSV 转换为 RGB 的计算公式: 1. 将 HSV 中的 S 和 V 值除以 100,得到范围在 0~1 之间的值。 2. 计算色相 H 在 RGB 中的值。如果 H 的范围在 0~60 或者 300~360 之间,则 R = V,G = (H/60)×V,B = 0。如果 H 的范围在 60~120 之间,则 R = ((120-H)/60)×V,G = V,B = 0。如果 H 的范围在 120~180 之间,则 R = 0,G = V,B =
recommend-type

JSBSim Reference Manual

JSBSim参考手册,其中包含JSBSim简介,JSBSim配置文件xml的编写语法,编程手册以及一些应用实例等。其中有部分内容还没有写完,估计有生之年很难看到完整版了,但是内容还是很有参考价值的。
recommend-type

"互动学习:行动中的多样性与论文攻读经历"

多样性她- 事实上SCI NCES你的时间表ECOLEDO C Tora SC和NCESPOUR l’Ingén学习互动,互动学习以行动为中心的强化学习学会互动,互动学习,以行动为中心的强化学习计算机科学博士论文于2021年9月28日在Villeneuve d'Asq公开支持马修·瑟林评审团主席法布里斯·勒菲弗尔阿维尼翁大学教授论文指导奥利维尔·皮耶昆谷歌研究教授:智囊团论文联合主任菲利普·普雷教授,大学。里尔/CRISTAL/因里亚报告员奥利维耶·西格德索邦大学报告员卢多维奇·德诺耶教授,Facebook /索邦大学审查员越南圣迈IMT Atlantic高级讲师邀请弗洛里安·斯特鲁布博士,Deepmind对于那些及时看到自己错误的人...3谢谢你首先,我要感谢我的两位博士生导师Olivier和Philippe。奥利维尔,"站在巨人的肩膀上"这句话对你来说完全有意义了。从科学上讲,你知道在这篇论文的(许多)错误中,你是我可以依
recommend-type

MATLAB柱状图在数据分析中的作用:从可视化到洞察

![MATLAB柱状图在数据分析中的作用:从可视化到洞察](https://img-blog.csdnimg.cn/img_convert/1a36558cefc0339f7836cca7680c0aef.png) # 1. MATLAB柱状图概述** 柱状图是一种广泛用于数据可视化的图表类型,它使用垂直条形来表示数据中不同类别或组别的值。在MATLAB中,柱状图通过`bar`函数创建,该函数接受数据向量或矩阵作为输入,并生成相应的高度条形。 柱状图的优点在于其简单性和易于理解性。它们可以快速有效地传达数据分布和组别之间的比较。此外,MATLAB提供了广泛的定制选项,允许用户调整条形颜色、
recommend-type

已知自动控制原理中通过更高的频率特征来评估切割频率和库存——相位稳定。确定封闭系统的稳定性。求Wcp 和ψ已知W(p)=30•(0.1p+1)•(12.5p+1)/p•(10p+1)•(0.2p+1)•(p+1)

根据相位稳定的定义,我们需要找到一个频率 Wcp,使得相位满足 -ψ = -180°,即 ψ = 180°。此时系统的相位裕度为 0°,系统处于边缘稳定状态。 首先,我们需要将 W(p) 表示成极点和零点的形式。将分母和分子分别因式分解,得到: W(p) = 30 • (0.1p+1) • (12.5p+1) / [p • (10p+1) • (0.2p+1) • (p+1)] = 375p/(p+1) - 3750/(10p+1) + 750p/(0.2p+1) - 3750p/(10p+1) + 150p/(p+1) + 30 因此,系统的极点为 -1、-0.1、-0.2、