⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 guiinit.java

📁 需要平台:Myeclips+Mysql或Myeclips+SQL Server 2
💻 JAVA
字号:
package com.view;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Vector;

import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.table.DefaultTableModel;

import com.control.MethodsAchieve;
import com.model.DBConn;

public class GUIinit extends JFrame implements ActionListener {
	private static Connection conn;

	private Statement sql;

	private ResultSet rs;
	
	private MethodsAchieve ma;
	
	private static DefaultTableModel dm;
	private JTable ta;
	private Vector vt,va;
	private JButton insert,delete,select,renovate,exit,rework;
	private JPanel jp_bt,jp_lb_tf,jp_lb_tf1,jp_lb_tf2,jp_cb,jp_db,jp_cb1,jp_cb2,jp_rb;
	private JLabel name_lb,id_lb,sex_lb,birthday_lb,grade_lb,query_hint,student_info,grade_lb_line;
	private static JTextField name_tf,id_tf,sex_tf,birthday_tf,grade_tf1,grade_tf2;
	private static JCheckBox name_cb,id_cb,sex_cb,grade_cb;
	private static JRadioButton id_rb,name_rb,sex_rb;
	private ButtonGroup rb_group;
	
	public GUIinit(){
		super();
		this.setSize(410, 450);
		this.setDefaultCloseOperation(3);
		conn=DBConn.newIntance();
		ma=new MethodsAchieve(conn);
		vt=new Vector();
		vt.add("学号");
		vt.add("姓名");
		vt.add("性别");
		vt.add("出生日期");
		vt.add("成绩");
		va=new Vector();
		
		dm=new DefaultTableModel(va,vt);
		ta=new JTable(dm);
		this.getContentPane().setLayout(new BorderLayout());
		jp_bt=new JPanel();
		jp_lb_tf=new JPanel(new BorderLayout());
		jp_lb_tf1=new JPanel(new GridLayout(2,4));
		jp_lb_tf2=new JPanel(new FlowLayout(FlowLayout.LEFT));
		//jp_lb_tf=new JPanel();
		jp_rb=new JPanel(new FlowLayout(FlowLayout.LEFT));
		jp_cb1=new JPanel(new FlowLayout(FlowLayout.LEFT));
		jp_cb2=new JPanel(new FlowLayout(FlowLayout.LEFT));
		jp_cb=new JPanel(new BorderLayout());
		jp_db=new JPanel(new BorderLayout());
		//this.getContentPane().setLayout(new GridLayout(4,4));
		//jp_cb=new JPanel();
		
		insert=new JButton("插入");
		delete=new JButton("删除");
		select=new JButton("查询");
		renovate=new JButton("刷新");
		exit=new JButton("退出");
		rework=new JButton("修改");
		
		id_rb=new JRadioButton("按学号");
		name_rb=new JRadioButton("按姓名");
		sex_rb=new JRadioButton("按性别");
		rb_group=new ButtonGroup();
		
		student_info=new JLabel("学生信息管理",JLabel.CENTER);
		student_info.setFont(new Font("隶书",Font.BOLD,25));
		id_lb=new JLabel("              学号");
		name_lb=new JLabel("               姓名");
		sex_lb=new JLabel("              性别");
		birthday_lb=new JLabel("      出生日期");
		grade_lb=new JLabel("             成绩        ");
		query_hint=new JLabel("提示:请先输入字段,再确定删除和查询类型!",JLabel.LEFT);
		query_hint.setForeground(Color.red);
		grade_lb_line=new JLabel("-");
		grade_lb_line.setFont(new Font("",Font.BOLD,20));
		
		
		id_tf=new JTextField(8);
		//id_tf.enable(false);
		name_tf=new JTextField(10);
		sex_tf=new JTextField(2);
		birthday_tf=new JTextField(10);
		grade_tf1=new JTextField(5);
		grade_tf2=new JTextField(5);
		
		id_cb=new JCheckBox("按学号");
		name_cb=new JCheckBox("按姓名");
		sex_cb=new JCheckBox("按性别");
		grade_cb=new JCheckBox("按成绩(范围)");
		
		insert.addActionListener(this);
		delete.addActionListener(this);
		select.addActionListener(this);
		renovate.addActionListener(this);
		rework.addActionListener(this);
		exit.addActionListener(this);
		id_cb.addActionListener(this);
		name_cb.addActionListener(this);
		sex_cb.addActionListener(this);
		grade_cb.addActionListener(this);
		
		jp_lb_tf1.add(id_lb);
		jp_lb_tf1.add(id_tf);
		jp_lb_tf1.add(name_lb);
		jp_lb_tf1.add(name_tf);
		jp_lb_tf1.add(sex_lb);
		jp_lb_tf1.add(sex_tf);
		jp_lb_tf1.add(birthday_lb);
		jp_lb_tf1.add(birthday_tf);
		jp_lb_tf2.add(grade_lb);
		jp_lb_tf2.add(grade_tf1);
		jp_lb_tf2.add(grade_lb_line);
		jp_lb_tf2.add(grade_tf2);
		jp_lb_tf.add(jp_lb_tf1,"North");
		jp_lb_tf.add(jp_lb_tf2,"South");
		//jp_lb_tf.add(id_cb);
		//jp_lb_tf.add(name_cb);
		//jp_lb_tf.add(sex_cb);
		//jp_cb.add(query_hint);
		jp_cb1.add(select);
		jp_cb1.add(id_cb);
		jp_cb1.add(name_cb);
		jp_cb1.add(sex_cb);
		jp_cb1.add(grade_cb);
		
		jp_cb2.add(query_hint);
		
		rb_group.add(id_rb);
		rb_group.add(name_rb);
		rb_group.add(sex_rb);
		
		jp_rb.add(delete);
		jp_rb.add(id_rb);
		jp_rb.add(name_rb);
		jp_rb.add(sex_rb);
		
		jp_bt.add(insert);
		jp_bt.add(rework);
		//jp_bt.add(select);
		jp_bt.add(renovate);
		jp_bt.add(exit);
		
		jp_cb.add(jp_cb1,"Center");
		jp_cb.add(jp_rb,"North");
		jp_cb.add(jp_cb2,"South");
		jp_db.add(student_info,"North");
		jp_db.add(jp_lb_tf,"Center");
		jp_db.add(jp_cb,"South");
		
		//this.getContentPane().add(jp_lb_tf,"North");
		this.getContentPane().add(jp_db,"North");
		//this.getContentPane().add(jp_cb);
		this.getContentPane().add(new JScrollPane(ta),"Center");
		this.getContentPane().add(jp_bt,"South");
		this.setVisible(true);
	}
	public void actionPerformed(ActionEvent e) {
		if(e.getSource()==renovate){
			va.clear();
			try {
				sql=conn.createStatement();
				sql.execute("select * from student");
				rs=sql.executeQuery("select * from student");
				while(rs.next()){
					int id=rs.getInt(1);
					String name=rs.getString(2);
					String sex=rs.getString(3);
					String birthday=rs.getString(4);
					float grade=rs.getFloat(5);
					Vector vl=new Vector();
					vl.add(id);
					vl.add(name);
					vl.add(sex);
					vl.add(birthday);
					vl.add(grade);
					dm.addRow(vl);
					
				}
				ta.repaint();
			} catch (SQLException e1) {
				
				e1.printStackTrace();
			}
		}		
		if(e.getSource()==rework){
			va.clear();
			ma.ReworkStudent();
		}
		if(e.getSource()==delete){
			va.clear();
			/*int rc=dm.getRowCount()-1;
			if(rc!=0){
				while(rc>0){
					dm.removeRow(rc);
					rc--;
				}
			}*/
			
		}
		if(e.getSource()==select){
			va.clear();
			ma.QueryStudent();
			
		}
		if(e.getSource()==insert){
			va.clear();
			ma.AddStudent();
		}
		if(e.getSource()==exit){
			try {
				conn.close();
			} catch (SQLException e1) {
				
				e1.printStackTrace();
			}
			System.exit(0);
		}
			
	}
	
	
	public static Connection getConn() {
		return conn;
	}
	public Statement getSql() {
		return sql;
	}
	public ResultSet getRs() {
		return rs;
	}
	public static DefaultTableModel getDm() {
		return dm;
	}
	public JTable getTa() {
		return ta;
	}
	public Vector getVt() {
		return vt;
	}
	public Vector getVa() {
		return va;
	}
	public JButton getInsert() {
		return insert;
	}
	public JButton getDelete() {
		return delete;
	}
	public JButton getSelect() {
		return select;
	}
	public JButton getUpdate() {
		return renovate;
	}
	public JButton getExit() {
		return exit;
	}
	public JButton getRework() {
		return rework;
	}
	public JPanel getJp_bt() {
		return jp_bt;
	}
	public JPanel getJp_lb_tf() {
		return jp_lb_tf;
	}
	public JPanel getJp_lb_tf1() {
		return jp_lb_tf1;
	}
	public JPanel getJp_lb_tf2() {
		return jp_lb_tf2;
	}
	public JPanel getJp_cb() {
		return jp_cb;
	}
	public JPanel getJp_db() {
		return jp_db;
	}
	public JPanel getJp_cb1() {
		return jp_cb1;
	}
	public JPanel getJp_cb2() {
		return jp_cb2;
	}
	public JPanel getJp_rb() {
		return jp_rb;
	}
	public JLabel getName_lb() {
		return name_lb;
	}
	public JLabel getId_lb() {
		return id_lb;
	}
	public JLabel getSex_lb() {
		return sex_lb;
	}
	public JLabel getBirthday_lb() {
		return birthday_lb;
	}
	public JLabel getGrade_lb() {
		return grade_lb;
	}
	public JLabel getQuery_hint() {
		return query_hint;
	}
	public JLabel getStudent_info() {
		return student_info;
	}
	public JLabel getGrade_lb_line() {
		return grade_lb_line;
	}
	public static String getName_tf() {
		return name_tf.getText();
	}
	public static String getId_tf() {
		return id_tf.getText();
	}
	public static JTextField getId_tff() {
		return id_tf;
	}
	public static String getSex_tf() {
		return sex_tf.getText();
	}
	public static String getBirthday_tf() {
		return birthday_tf.getText();
	}
	public static String getGrade_tf1() {
		return grade_tf1.getText();
	}
	public static String getGrade_tf2() {
		return grade_tf2.getText();
	}
	public static JCheckBox getName_cb() {
		return name_cb;
	}
	public static JCheckBox getId_cb() {
		return id_cb;
	}
	public static JCheckBox getSex_cb() {
		return sex_cb;
	}
	public static JCheckBox getGrade_cb() {
		return grade_cb;
	}
	public static JRadioButton getId_rb() {
		return id_rb;
	}
	public static JRadioButton getName_rb() {
		return name_rb;
	}
	public static JRadioButton getSex_rb() {
		return sex_rb;
	}
	public ButtonGroup getRb_group() {
		return rb_group;
	}
	
		
}


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -