📄 shujuku.java
字号:
b1.setFont(new Font("确定",Font.BOLD,12));
b1.setForeground(Color.blue);
dialogPane.add(b1);
b1.addActionListener(this);//为两个按钮添加事件监听器
dialog.setBounds(100,90,500,90);
dialog.setBackground(Color.black);//背景颜色
//dialog.show();
dialog.setVisible(true);
}
public void actionPerformed(ActionEvent e)
{
String cmd=e.getActionCommand();//获得事件对象的相关名称
if (cmd.equals("确定"))
{
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");//加载驱动器
Connection con=DriverManager.getConnection("jdbc:odbc:PIMS");//连接数据库
Statement stmt=con.createStatement();//创建对象
//text.w//
label.setText("点击选项,选择要运用的选项即可进行运用,有不懂得可与作者联系,联系方式619");
label.setForeground(Color.GRAY);
label.setFont(new Font("点击选项,选择要运用的选项即可进行运用,有不懂得可与作者联系,联系方式619",Font.BOLD,15));
//dialog.dispose();
stmt.close();
con.close();
}catch(Exception ex){}
}
}
}
class suiji implements ActionListener
{
JDialog dialog;
JTextField tF2=new JTextField();//定义输入框用于输入信息
suiji(JFrame f)
{
dialog=new JDialog(f,"随机点名",true);
Container dialogPane=dialog.getContentPane();
dialogPane.add(new JLabel("学生姓名:",SwingConstants.CENTER));
dialogPane.add(tF2);
dialogPane.setLayout(new GridLayout(2,2));//设计界面图形
JButton b1=new JButton("确定");
dialogPane.add(b1);
JButton b2= new JButton("取消");
dialogPane.add(b2);
b1.addActionListener(this);//为两个按钮添加事件监听器
b2.addActionListener(this);
dialog.setBounds(100,75,200,75);
dialog.setBackground(Color.blue);//背景颜色
dialog.setVisible(true);
}
public void actionPerformed(ActionEvent e)
{
String cmd=e.getActionCommand();//获得事件对象的相关名称
if (cmd.equals("确定"))
{
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");//加载驱动器
Connection con=DriverManager.getConnection("jdbc:odbc:PIMS");//连接数据库
Statement stmt=con.createStatement();//创建语句
ResultSet rs1=null;//定义一个结果对象
rs1=stmt.executeQuery("Select*From xuesheng");
int i=0;
while (rs1.next()) i=i+1;
int ID=(int )Math.abs(Math.random()*(i-1)+1);//使生成的数绝对是正数
String xuehao=String.valueOf(ID).toString();
PreparedStatement pstmt=con.prepareStatement("select 学号,姓名,性别,年龄,专业 from xuesheng where 学号=?");
pstmt.setString(1,xuehao);//执行查找
ResultSet rs=pstmt.executeQuery();
//for(int j=0;j<ID;j++)
//{
// rs.next();
//}
if(rs.next()==false)
{
JOptionPane.showMessageDialog(dialog, "此次生成学生不存在,在再操作一次");
}
else
{
tF2.setText(rs.getString("姓名"));
tF2.setForeground(Color.blue);
}
pstmt.close();
con.close();
stmt.close ();//关闭对象的操作
}catch(Exception ex){}
}
else if(cmd.equals("取消"))
{
dialog.dispose();
}
}
}
class xiugaixuehao implements ActionListener
{
JDialog dialog;
JTextField tF2=new JTextField();//定义输入框用于输入信
JTextField tF6=new JTextField();//定义输入框用于输入信息
xiugaixuehao(JFrame f)
{
dialog=new JDialog(f,"修改学号",true);
Container dialogPane=dialog.getContentPane();
dialogPane.setLayout(new GridLayout(3,2));//设计界面图形
dialogPane.add(new JLabel("在此输入要修改学生的姓名:",SwingConstants.CENTER));
dialogPane.add(tF6);
dialogPane.add(new JLabel("学生学号:",SwingConstants.CENTER));
dialogPane.add(tF2);
JButton b1=new JButton("确定");
dialogPane.add(b1);
JButton b2= new JButton("取消");
dialogPane.add(b2);
b1.addActionListener(this);//为两个按钮添加事件监听器
b2.addActionListener(this);
dialog.setBounds(200,200,400,100);
dialog.setBackground(Color.blue);//背景颜色
//dialog.show();
dialog.setVisible(true);
}
public void actionPerformed(ActionEvent e)
{
String cmd=e.getActionCommand();//获得事件对象的相关名称
if (cmd.equals("确定"))
{
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");//加载驱动器
Connection con=DriverManager.getConnection("jdbc:odbc:PIMS");//连接数据库
PreparedStatement pstmt=con.prepareStatement("update xuesheng set 学号=? where 姓名=?");
pstmt.setString(2,tF6.getText());//执行查找
pstmt.setString(1, tF2.getText());
if(pstmt.executeUpdate()!=1)
{
JOptionPane.showMessageDialog(dialog, "没有此人,请确认后再查");
}
else
{
JOptionPane.showMessageDialog(dialog, "修改成功");
}
pstmt.close();
con.close();
}catch (Exception ex){}
}
else if (cmd.equals("取消"))
{
dialog.dispose();//直接返回主页面
}
}
}
class xiugaixingming implements ActionListener
{
JDialog dialog;
JTextField tF2=new JTextField();//定义输入框用于输入信
JTextField tF6=new JTextField();//定义输入框用于输入信息
xiugaixingming(JFrame f)
{
dialog=new JDialog(f,"修改姓名",true);
Container dialogPane=dialog.getContentPane();
dialogPane.setLayout(new GridLayout(3,2));//设计界面图形
dialogPane.add(new JLabel("在此输入要修改学生的姓名:",SwingConstants.CENTER));
dialogPane.add(tF6);
dialogPane.add(new JLabel("学生新姓名:",SwingConstants.CENTER));
dialogPane.add(tF2);
JButton b1=new JButton("确定");
dialogPane.add(b1);
JButton b2= new JButton("取消");
dialogPane.add(b2);
b1.addActionListener(this);//为两个按钮添加事件监听器
b2.addActionListener(this);
dialog.setBounds(200,200,400,100);
dialog.setBackground(Color.blue);//背景颜色
//dialog.show();
dialog.setVisible(true);
}
public void actionPerformed(ActionEvent e)
{
String cmd=e.getActionCommand();//获得事件对象的相关名称
if (cmd.equals("确定"))
{
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");//加载驱动器
Connection con=DriverManager.getConnection("jdbc:odbc:PIMS");//连接数据库
PreparedStatement pstmt=con.prepareStatement("update xuesheng set 姓名=? where 姓名=?");
pstmt.setString(2,tF6.getText());//执行查找
pstmt.setString(1, tF2.getText());
if(pstmt.executeUpdate()!=1)
{
JOptionPane.showMessageDialog(dialog, "没有此人,请确认后再查");
}
else
{
JOptionPane.showMessageDialog(dialog, "修改成功");
}
pstmt.close();
con.close();
}catch (Exception ex){}
}
else if (cmd.equals("取消"))
{
dialog.dispose();//直接返回主页面
}
}
}
class xiugaizhuanye implements ActionListener
{
JDialog dialog;
JTextField tF2=new JTextField();//定义输入框用于输入信
JTextField tF6=new JTextField();//定义输入框用于输入信息
xiugaizhuanye(JFrame f)
{
dialog=new JDialog(f,"修改专业",true);
Container dialogPane=dialog.getContentPane();
dialogPane.setLayout(new GridLayout(3,2));//设计界面图形
dialogPane.add(new JLabel("在此输入要修改学生的姓名:",SwingConstants.CENTER));
dialogPane.add(tF6);
dialogPane.add(new JLabel("学生新专业:",SwingConstants.CENTER));
dialogPane.add(tF2);
JButton b1=new JButton("确定");
dialogPane.add(b1);
JButton b2= new JButton("取消");
dialogPane.add(b2);
b1.addActionListener(this);//为两个按钮添加事件监听器
b2.addActionListener(this);
dialog.setBounds(200,200,400,100);
dialog.setBackground(Color.blue);//背景颜色
//dialog.show();
dialog.setVisible(true);
}
public void actionPerformed(ActionEvent e)
{
String cmd=e.getActionCommand();//获得事件对象的相关名称
if (cmd.equals("确定"))
{
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");//加载驱动器
Connection con=DriverManager.getConnection("jdbc:odbc:PIMS");//连接数据库
PreparedStatement pstmt=con.prepareStatement("update xuesheng set 专业=? where 姓名=?");
pstmt.setString(2,tF6.getText());//执行查找
pstmt.setString(1, tF2.getText());
if(pstmt.executeUpdate()!=1)
{
JOptionPane.showMessageDialog(dialog, "没有此人,请确认后再查");
}
else
{
JOptionPane.showMessageDialog(dialog, "修改成功");
}
pstmt.close();
con.close();
}catch (Exception ex){}
}
else if (cmd.equals("取消"))
{
dialog.dispose();//直接返回主页面
}
}
}
class xiugainianling implements ActionListener
{
JDialog dialog;
JTextField tF2=new JTextField();//定义输入框用于输入信
JTextField tF6=new JTextField();//定义输入框用于输入信息
xiugainianling(JFrame f)
{
dialog=new JDialog(f,"修改年龄",true);
Container dialogPane=dialog.getContentPane();
dialogPane.setLayout(new GridLayout(3,2));//设计界面图形
dialogPane.add(new JLabel("在此输入要修改学生的姓名:",SwingConstants.CENTER));
dialogPane.add(tF6);
dialogPane.add(new JLabel("学生新年龄:",SwingConstants.CENTER));
dialogPane.add(tF2);
JButton b1=new JButton("确定");
dialogPane.add(b1);
JButton b2= new JButton("取消");
dialogPane.add(b2);
b1.addActionListener(this);//为两个按钮添加事件监听器
b2.addActionListener(this);
dialog.setBounds(200,200,400,100);
dialog.setBackground(Color.blue);//背景颜色
//dialog.show();
dialog.setVisible(true);
}
public void actionPerformed(ActionEvent e)
{
String cmd=e.getActionCommand();//获得事件对象的相关名称
if (cmd.equals("确定"))
{
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");//加载驱动器
Connection con=DriverManager.getConnection("jdbc:odbc:PIMS");//连接数据库
PreparedStatement pstmt=con.prepareStatement("update xuesheng set 年龄=? where 姓名=?");
pstmt.setString(2,tF6.getText());//执行查找
pstmt.setString(1, tF2.getText());
if(pstmt.executeUpdate()!=1)
{
JOptionPane.showMessageDialog(dialog, "没有此人,请确认后再查");
}
else
{
JOptionPane.showMessageDialog(dialog, "修改成功");
}
pstmt.close();
con.close();
}catch (Exception ex){}
}
else if (cmd.equals("取消"))
{
dialog.dispose();//直接返回主页面
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -