学生信息管理,给分吧。。。。
//
//
package com.lz.db;
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.awt.event.KeyEvent;
import java.io.File;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.Statement;
import java.util.Vector;
import javax.swing.*;
import javax.swing.filechooser.FileFilter;
import javax.swing.table.TableColumn;
public class Student extends JFrame implements ActionListener{
JDesktopPane desktop;
public Student(){
super("学生");
int inset = 50;
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
setBounds(inset, inset,
screenSize.width - inset*2,
screenSize.height - inset*2);
//Set up the GUI.
desktop = new JDesktopPane(); //a specialized layered pane
setContentPane(desktop);
setJMenuBar(createMenuBar());
//Make dragging a little faster but perhaps uglier.
desktop.setDragMode(JDesktopPane.OUTLINE_DRAG_MODE);
}
//
protected JMenuBar createMenuBar() {
JMenuBar menuBar = new JMenuBar();
JMenu menu = new JMenu("数据库操作");
menu.setMnemonic(KeyEvent.VK_D);
menuBar.add(menu);
JMenuItem menuItem;
//
menuItem = new JMenuItem("浏览");
menuItem.setMnemonic(KeyEvent.VK_N);
menuItem.setAccelerator(KeyStroke.getKeyStroke(
KeyEvent.VK_N, ActionEvent.ALT_MASK));
menuItem.setActionCommand("select");
menuItem.addActionListener(this);
menu.add(menuItem);
//
menuItem = new JMenuItem("增加");
menuItem.setMnemonic(KeyEvent.VK_N);
menuItem.setAccelerator(KeyStroke.getKeyStroke(
KeyEvent.VK_N, ActionEvent.ALT_MASK));
menuItem.setActionCommand("insert");
menuItem.addActionListener(this);
menu.add(menuItem);
//
menuItem = new JMenuItem("修改");
menuItem.setMnemonic(KeyEvent.VK_N);
menuItem.setAccelerator(KeyStroke.getKeyStroke(
KeyEvent.VK_N, ActionEvent.ALT_MASK));
menuItem.setActionCommand("update");
menuItem.addActionListener(this);
menu.add(menuItem);
//
menuItem = new JMenuItem("删除");
menuItem.setMnemonic(KeyEvent.VK_N);
menuItem.setAccelerator(KeyStroke.getKeyStroke(
KeyEvent.VK_N, ActionEvent.ALT_MASK));
menuItem.setActionCommand("delete");
menuItem.addActionListener(this);
menu.add(menuItem);
//Set up the second menu item.
menuItem = new JMenuItem("退出");
menuItem.setMnemonic(KeyEvent.VK_Q);
menuItem.setAccelerator(KeyStroke.getKeyStroke(
KeyEvent.VK_Q, ActionEvent.ALT_MASK));
menuItem.setActionCommand("quit");
menuItem.addActionListener(this);
menu.add(menuItem);
menuBar.add(menu);
return menuBar;
}
//React to menu selections.
public void actionPerformed(ActionEvent e) {
if ("new".equals(e.getActionCommand())) { //new
createFrame();
}
else if("select".equals(e.getActionCommand())){
createBrowFrame();
}
else if("insert".equals(e.getActionCommand())){
createInsertFrame();
}
else if("delete".equals(e.getActionCommand())){
createDeleteFrame();
}
else if("update".equals(e.getActionCommand())){
createUpdateFrame();
}
else { //quit
quit();
}
}
//
protected void createUpdateFrame(){
UpdateFrame frame=new UpdateFrame();
frame.setVisible(true);
desktop.add(frame);
try{
frame.setSelected(true);
}catch(Exception e){
}
}
//
protected void createDeleteFrame(){
DeleteFrame frame=new DeleteFrame();
frame.setVisible(true);
desktop.add(frame);
try{
frame.setSelected(true);
}catch(Exception e){
}
}
//
protected void createInsertFrame(){
InsertFrame frame=new InsertFrame();
frame.setVisible(true);
desktop.add(frame);
try{
frame.setSelected(true);
}catch(Exception e){
}
}
protected void createBrowFrame(){
BrowFrame frame=new BrowFrame();
frame.setVisible(true);
desktop.add(frame);
try{
frame.setSelected(true);
}catch(Exception e){
}
}
//Create a new internal frame.
protected void createFrame() {
BrowFrame frame = new BrowFrame();
frame.setVisible(true); //necessary as of 1.3
desktop.add(frame);
try {
frame.setSelected(true);
} catch (java.beans.PropertyVetoException e) {}
}
//Quit the application.
protected void quit() {
System.exit(0);
}
private static void createAndShowGUI() {
//Make sure we have nice window decorations.
JFrame.setDefaultLookAndFeelDecorated(true);
//Create and set up the window.
Student frame = new Student();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//Display the window.
frame.setVisible(true);
}
public static void main(String[] args) {
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
createAndShowGUI();
}
});
}
}
class BrowFrame extends JInternalFrame implements ActionListener{
private JLabel label1,label2,label3;
private JTextField snamefield,snofield,sbirthdayfield;
private JButton okButton;
private JPanel p2;
private DbHelper helper;
//public
public BrowFrame(){
super("BROW" ,
true, //resizable
true, //closable
true, //maximizable
true);//iconifiable
this.setTitle("brow");
setSize(700,300);
String sql;
sql="select * from tblstudent";
helper=new DbHelper();
ResultSet rs=helper.getRs(sql);
ResultSetMetaData md;
int columns=0;
Vector columnNames=new Vector();
Vector data=new Vector();
try{
md=rs.getMetaData();
columns=md.getColumnCount();
int i;
for(i=1;i<=columns;i++){
columnNames.addElement(md.getColumnName(i));
}
while(rs.next()){
Vector row=new Vector(columns);
for(i=1;i<=columns;i++){
row.addElement(rs.getObject(i));
}
data.addElement(row);
}
}catch(Exception e){
}
JTable table=new JTable(data,columnNames);
TableColumn col;
int i;
for(i=0;i
简单是简单,可不是两分钟就能弄出来的,以前有过一些什么记事本之类的程序,可不在这电脑上。自己上网找一个就行了
100不够哦