📄 pj_eth.java
字号:
package prapare_manager;
import java.sql.*;
import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import javax.swing.*;
import user.quanxian;
import java.sql.DriverManager;
public class pj_eth extends JFrame implements ActionListener,ItemListener
{
private static final long serialVersionUID = -7700451926035976789L;
JPanel cp;
int i1=0,i2=0;//复选框选择记录
JScrollPane jsp = new JScrollPane();
ImageIcon icon=new ImageIcon("picture/12.jpg");
JLabel tp=new JLabel(icon,JLabel.CENTER);
Object[][] rowData=new Object[100][5];
String[] columnNames = {
"编号","姓名","性别","参赛项目","学院"};
JTable jT1 = new JTable(rowData, columnNames) ;
JLabel j1=new JLabel("编号:");
JLabel j2=new JLabel("姓名: ");
JLabel j3=new JLabel("性别:");
JLabel j4=new JLabel("参赛项目:");
JLabel j5=new JLabel("学院:");
JComboBox cbx1=new JComboBox();
JComboBox cbx2=new JComboBox();
JComboBox cbx3=new JComboBox();
JButton b1=new JButton("添 加");
JButton b2=new JButton("删 除");
JButton b3=new JButton("查 询");
JButton b5=new JButton("刷 新");
JButton b6=new JButton("返回");
JCheckBox cb1=new JCheckBox("学 院",false);
JCheckBox cb2=new JCheckBox("项 目",false);
JTextField jt1=new JTextField(16);
JTextField jt2=new JTextField(16);
public pj_eth()
{try{Init();if(new quanxian().get_quanxian()==2){b2.setEnabled(false);b1.setEnabled(false);}
}catch (Exception err){err.printStackTrace();}}
public void Init() throws Exception{
cp=(JPanel)this.getContentPane();
cp.setLayout(null);
this.setSize(760,540);
this.setTitle("运动员参赛表");
b1.setBounds(600,20,85,30);
b1.setFont(new java.awt.Font("Dialog",0,15));
b1.addActionListener(this);
cp.add(b1);
b2.setBounds(600,70,85,30);
b2.setFont(new java.awt.Font("Dialog",0,15));
b2.addActionListener(this);
cp.add(b2);
b3.setBounds(600,120,85,30);
b3.setFont(new java.awt.Font("Dialog",0,15));
b3.addActionListener(this);
cp.add(b3);
b5.setBounds(600,170,85,30);
b5.setFont(new java.awt.Font("Dialog",0,15));
b5.addActionListener(this);
cp.add(b5);
b6.setBounds(600,220,85,30);
b6.setFont(new java.awt.Font("Dialog",0,15));
b6.addActionListener(this);
cp.add(b6);
cb1.setBounds(570,340,60,30);
cb1.setBackground(new Color(255,255,255));
cb1.addItemListener(this);
cp.add(cb1,null);
cb2.setBounds(630,340,60,30);
cb2.setBackground(new Color(255,255,255));
cb2.addItemListener(this);
cp.add(cb2,null);
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("jdbc:odbc:yundonghui","sa","123");
Statement ps=con.createStatement();
ResultSet rs1=null;
rs1=ps.executeQuery("select * from 学院名称表");
while(rs1.next()){cbx1.addItem(rs1.getString(1));}
ResultSet rs2=null;
rs2=ps.executeQuery("select * from 项目表");
while(rs2.next()){cbx2.addItem(rs2.getString(1));}
}
catch(Exception err){err.printStackTrace();JOptionPane.showMessageDialog(null,"数据库连接出错!");}
j1.setBounds(30,340,60,30);
j1.setForeground(new Color(255,0,0));
j1.setFont(new java.awt.Font("Dialog",0,15));
cp.add(j1,null);
jt1.setBounds(90,340,80,30);
jt1.setFont(new java.awt.Font("Dialog",0,15));
cp.add(jt1,null);
j2.setBounds(290,340,80,30);
j2.setFont(new java.awt.Font("Dialog",0,16));
j2.setForeground(new Color(255,0,0));
cp.add(j2,null);
jt2.setBounds(360,340,100,30);
jt2.setFont(new java.awt.Font("Dialog",0,15));
cp.add(jt2,null);
j3.setBounds(30,400,60,30);
j3.setForeground(new Color(255,0,0));
j3.setFont(new java.awt.Font("Dialog",0,15));
cp.add(j3,null);
cbx3.setBounds(90,400,80,30);
cbx3.setFont(new java.awt.Font("Dialog",0,10));
cbx3.addItem("男");
cbx3.addItem("女");
cp.add(cbx3,null);
j4.setBounds(290,400,80,30);
j4.setForeground(new Color(255,0,0));
j4.setFont(new java.awt.Font("Dialog",0,15));
cp.add(j4,null);
cbx2.setBounds(360,400,100,30);
cbx2.setFont(new java.awt.Font("Dialog",0,10));
cp.add(cbx2,null);
j5.setBounds(500,400,80,30);
j5.setForeground(new Color(255,0,0));
j5.setFont(new java.awt.Font("Dialog",0,15));
cp.add(j5,null);
cbx1.setBounds(570,400,120,30);
cbx1.setFont(new java.awt.Font("Dialog",0,10));
cp.add(cbx1,null);
jsp.setBounds(6,0,540,305);
jsp.getViewport().add(jT1,null);
cp.add(jsp);
tp.setSize(760,500);
tp.setText("");
cp.add(tp,null);
this.setResizable(false);
this.setLocationRelativeTo(null);
this.setVisible(true);
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
java.sql.Connection con=DriverManager.getConnection("jdbc:odbc:yundonghui","sa","123");
Statement ps=con.createStatement();
ResultSet rs = null;
rs=ps.executeQuery("select * from 运动员参赛表");
jT1.setModel(new javax.swing.table.DefaultTableModel());
Object[][] rowData=new Object[100][5];
String[] columnNames = {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -