简单学生管理信息系统源代码

简单学生管理信息系统源代码
简单学生管理信息系统源代码

package xsgl;

import java.awt.*; import java.awt.event.*; import java.sql.*; import java.util.*; import javax.swing.*; import java.util.Vector; import javax.swing.table.* import java.awt.event.*; public class Xsglxt

接口 ActionListener extends JFrame implements { ActionListener // 继承 JFrame 并实现

JPanel mb1, mb2; JLabel bq1 ;

JTextField wbk1;

JButton an1, an2, an3 , an4; JTable bg1 ; JScrollPane

Xsxx xsxx2 ;

// 定义表格对象

化。 gd1; // 定义 Xsxx 类的一个对象 xsxx2

public static

{

Xsglxt xs=

}

public Xsglxt() void main(String[] args)

new Xsglxt(); //XSGLXT 构造方法,用于对象初始

mb1=new JPanel();

bq1 =new JLabel( " 请输入姓名 " ); wbk1 =new JTextField(10); an1 =new JButton( "查询"); an1 .addActionListener( this ); an1 .setActionCommand(

"chaxun"

mb1.add( bq1); mb1.add( wbk1 ); );

mb1.add( // 对按钮 1添加监听

// 设置按钮 1的监听信息 an1);

mb2=new JPanel();

an2 =new JButton( "添加");

an2 .addActionListener( this ); an2 .setActionCommand( "tianjia" an3 =new JButton( "修改");

an3 .addActionListener( this ); an3 .setActionCommand( "xiugai" an4 =new JButton( "删除");

an4 .addActionListener( this ); an4 .setActionCommand( "shanchu"

);

);

);

mb2.add( an2); mb2.add( an3); mb2.add( an4); xsxx2 =new Xsxx(); bg1 =new JTable( xsxx2 );

gd1 =new JScrollPane(

bg1);

.add( gd1);

.add( mb1, "North"

.add( mb2, "South"

String xingming= this . wbk1 .getText().trim();

// 将本窗口的文本框 1中文本取出,

忽略前后空格后赋给变量 xingming

String sql= "select * from xuesheng where xingming='"

+xingming+ "'"

//将SQL 语句赋给String 类型变量sql

//将String 类型变量sql 作为参数NEW-个

bg1 .setModel( xsxx2 );

// 将表 bg1 的数据模型设为 newModel ,并向其注

册以获取来自新数据模型的侦听器通知。

}

else {

Tianjia tj= new Tianjia( this

xsxx2 =new Xsxx(); //无

参数传递的 NEW 个Xsxx 类的对象xsxx2 bg1.setModel( xsxx2 );

int ii= this . bg1 .getSelectedRow();

// 使用 getSelectedRow() 方法返回第一个选定

JOptionPane. showMessageDialog (this , " 请选中要修改的行 " ); // 显示一个

错误对话框

return

}

new Xiugai( this , " 修改学生信息 ", true , xsxx2 ,ii);

this this this this this this } public

.setTitle( " 学生管理系统 " ); .setSize(500,400); .setLocation(201,181); .setResizab le( false ); .setDefaultCloseOperation(JFrame. .setVisible( true );

EXIT_ON_CLOSE);

void actionPerformed(ActionEvent e) 抽象方法 // 实现接口 ActionListener 中的

actionPerformed { if (e.getActionCommand().equals( "chaxun" (是不是查询按钮)

{

"chaxun" )) // 判断监听到的组件信息是不是

this this this ); );

xsxx2 =new Xsxx(sql); Xsxx 类的对象 xsxx2

if (e.getActionCommand().equals(

"tianjia" ))

, " 添加学生信息 " , true );

} else

{

if (e.getActionCommand().equals( "xiugai" ))

行的索引;如果没有选定的行,则返回

-1

i f

{

(ii==-1)

相关主题
相关文档
最新文档