[java]代码库
package com.wybu.cn;
/**
* 管理界面设计
*/
import javax.swing.*;
import java.awt.BorderLayout;
import java.awt.event.*;
import java.util.Arrays;
import java.util.Vector;
import java.sql.*;
public class StuduntManagerDemo extends JFrame implements ActionListener{
JTable jt;
JScrollPane jsp;
JPanel jp1,jp2,jp3;
JButton jb1,jb2,jb3,jb4;
JLabel jl;
JTextField jtf;
MyModelDemo ms;
public static void main(String[] args) {
// TODO Auto-generated method stub
new StuduntManagerDemo();
System.out.println("dant ");
}
public StuduntManagerDemo() {
//处理中间的ScorllPanel
System.out.println("开始");
ms=new MyModelDemo();
jt=new JTable(ms);
//jt.setModel(ms);
jsp=new JScrollPane(jt);
//处理北部
jp1=new JPanel();
jl=new JLabel("请输入你要查询的姓名:");
jtf=new JTextField(10);
jb1=new JButton("查询");
jb1.addActionListener(this);
jp1.add(jl);
jp1.add(jtf);
jp1.add(jb1);
//处理南部
jp2=new JPanel();
jb2=new JButton("添加");
jb2.addActionListener(this);
jb3=new JButton("修改");
jb3.addActionListener(this);
jb4=new JButton("删除");
jb4.addActionListener(this);
jp2.add(jb2);
jp2.add(jb3);
jp2.add(jb4);
this.add(jp1,new BorderLayout().NORTH);
this.add(jsp);
this.add(jp2,new BorderLayout().SOUTH);
this.setSize(400, 300);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setVisible(true);
}
@Override
public void actionPerformed(ActionEvent e) {
if(e.getSource()==jb1){
String str=this.jtf.getText();
ms=new MyModelDemo(str);
this.jt.setModel(ms);
System.out.println("查询成功");
}else if(e.getSource()==jb2){
DialogDemo dd=new DialogDemo(this,"添加组件", true);
ms=new MyModelDemo();
this.jt.setModel(ms);
}else if(e.getSource()==jb3){
int rownum=this.jt.getSelectedRow();
if(rownum==-1){
JOptionPane.showConfirmDialog(this, "请选定一行");
}else{
ms=new MyModelDemo();
new Dialog1Demo(this, "修改信息",true,rownum,ms);
ms=new MyModelDemo();
this.jt.setModel(ms);
System.out.println(rownum);}
}else if(e.getSource()==jb4){
int i=this.jt.getSelectedRow();
if(i==-1){
JOptionPane.showConfirmDialog(this, "请选定一行");
}else{
ms=new MyModelDemo();
new deleteStudentDemo(i,ms);
ms=new MyModelDemo();
this.jt.setModel(ms);
}
}
}
}