📄 querygroupinfo.java
字号:
package com.query;
import com.DBManager.MyDB;
import com.MainFrame;
import com.component.MyFrame;
import java.awt.Dimension;
import java.awt.Rectangle;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.print.PrinterException;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Vector;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextField;
/**
* @author Laiger
*/
public class QueryGroupInfo extends MyFrame implements ActionListener {
private JLabel jLabel1 = null;
private JComboBox jComboBox1 = null;
private JTextField t1 = null;
private JScrollPane jScrollPane = null;
private JTable jTable = null;
private JTextField t2 = null;
private JLabel total = null;
private JButton b1 = null;
private JButton b3 = null;
private JComboBox jComboBox2 = null;
private JTextField t3 = null;
private JButton b2 = null;
private JLabel jLabel4 = null;
private JButton print = null;
/**
* This method initializes
*
*/
public QueryGroupInfo(MainFrame m) {
super(m);
initialize();
}
public QueryGroupInfo() {
super();
initialize();
}
/**
* This method initializes this
*
*/
private void initialize() {
jLabel4 = new JLabel();
jLabel4.setBounds(new Rectangle(428, 252, 33, 28));
jLabel4.setText("排名");
total = new JLabel();
total.setBounds(new Rectangle(241, 258, 50, 20));
total.setText("总分");
jLabel1 = new JLabel();
jLabel1.setBounds(new Rectangle(19, 35, 57, 30));
jLabel1.setText("选择团队");
this.setSize(new Dimension(715, 295));
this.setTitle("查询团队信息");
this.add(jLabel1, null);
this.add(getJComboBox1(), null);
this.add(getT1(), null);
this.add(getJScrollPane(), null);
this.add(getT2(), null);
this.add(total, null);
this.add(getB1(), null);
this.add(getB3(), null);
this.add(getJComboBox2(), null);
this.add(getT3(), null);
this.add(getB2(), null);
this.add(jLabel4, null);
this.add(getPrint(), null);
}
/**
* This method initializes jComboBox1
* @return javax.swing.JComboBox
* @uml.property name="jComboBox1"
*/
private JComboBox getJComboBox1() {
if (jComboBox1 == null) {
jComboBox1 = new JComboBox();
jComboBox1.setBounds(new Rectangle(99, 35, 119, 32));
ResultSet rs=db.executeQuery("select * from groupinfo");
try {
while(rs.next()){
jComboBox1.addItem(rs.getString("groupid").trim());
}
} catch (SQLException e) {
e.printStackTrace();
}
jComboBox1.setSelectedIndex(-1);
jComboBox1.addActionListener(this);
}
return jComboBox1;
}
/**
* This method initializes t1
* @return javax.swing.JTextField
* @uml.property name="t1"
*/
private JTextField getT1() {
if (t1 == null) {
t1 = new JTextField();
t1.setBounds(new Rectangle(221, 35, 106, 33));
t1.setEditable(false);
}
return t1;
}
/**
* This method initializes jScrollPane
* @return javax.swing.JScrollPane
* @uml.property name="jScrollPane"
*/
private JScrollPane getJScrollPane() {
if (jScrollPane == null) {
jScrollPane = new JScrollPane();
jScrollPane.setBounds(new Rectangle(19, 125, 674, 119));
jScrollPane.setViewportView(getJTable());
}
return jScrollPane;
}
/**
* This method initializes jTable
* @return javax.swing.JTable
* @uml.property name="jTable"
*/
private JTable getJTable() {
if (jTable == null) {
jTable = new JTable();
}
return jTable;
}
/**
* This method initializes t2
* @return javax.swing.JTextField
* @uml.property name="t2"
*/
private JTextField getT2() {
if (t2 == null) {
t2 = new JTextField();
t2.setBounds(new Rectangle(310, 251, 95, 32));
t2.setEditable(false);
}
return t2;
}
@Override
public void actionPerformed(ActionEvent e) {
if(jComboBox1.getSelectedIndex()<0){
JOptionPane.showMessageDialog(this,"请先选择团队");
return;
}
if(e.getSource()==jComboBox1){
if(jComboBox1.getSelectedIndex()>-1){
t1.setText(db.getString("select * from groupinfo where groupid="+jComboBox1.getSelectedItem().toString().trim()+"", "name"));
b1.setEnabled(true);
b2.setEnabled(true);
b3.setEnabled(true);
}
}
else if(e.getSource()==b1){
ResultSet rs=db.executeQuery("select * from groupinfo where groupid="+jComboBox1.getSelectedItem().toString().trim()+"");
try {
Vector row,col;
row=new Vector();
col=new Vector();
col.add("团队编号");col.add("团队名");col.add("负责人");col.add("联系电话");col.add("总人数");
while(rs.next()){
Vector v=new Vector();
v.add(rs.getString("groupid"));
v.add(rs.getString("name"));
v.add(rs.getString("principal"));
v.add(rs.getString("phone"));
v.add(rs.getString("athleteAmount"));
row.add(v);
}
jTable=new JTable(row,col);
jScrollPane.setViewportView(jTable);
}
catch (SQLException e1) {
e1.printStackTrace();
}
}
else if(e.getSource()==b2){
String sql="";
ResultSet rs;
sql="select athlete from groupathlete where groupid="+jComboBox1.getSelectedItem().toString().trim()+"";
sql="select distinct * from achievement where athleteid in("+sql+")";
int total=0;
rs=db.executeQuery(sql);
int athleteID=0;
String projectID="";
int a=0;
try {
Vector row,col;
row=new Vector();
col=new Vector();
col.add("成员编号");col.add("成员名");col.add("参加项目");col.add("成绩");col.add("得分");
MyDB d=new MyDB();
d.connectDB();
while(rs.next()){
athleteID=rs.getInt("athleteID");
projectID=rs.getString("projectID");
Vector v=new Vector();
v.add(athleteID);
v.add(d.getString("select * from athlete where id="+athleteID+"", "name"));
v.add(projectID);
v.add(rs.getFloat("achievement"));
total+=rs.getInt("score");
v.add(rs.getInt("score"));
row.add(v);
}
jTable=new JTable(row,col);
jScrollPane.setViewportView(jTable);
t2.setText(total+"");
int p=1;
for(int i=0;i<jComboBox1.getItemCount();i++){
sql="select sum(score) as s from achievement where athleteid in(";
sql+="select athlete from groupathlete where groupid="+jComboBox1.getItemAt(i).toString().trim()+")";
rs=d.executeQuery(sql);
while(rs.next()){
if(total<rs.getInt("s"))
p++;
}
}
t3.setText(p+"");
d.close();
} catch (SQLException e1) {
e1.printStackTrace();
}
}
else if(e.getSource()==b3){
jComboBox2.setVisible(true);
}
}
/**
* @return the b1
* @uml.property name="b1"
*/
private JButton getB1() {
if (b1 == null) {
b1 = new JButton();
b1.setBounds(new Rectangle(332, 37, 122, 31));
b1.setText("团队基本信息");
b1.addActionListener(this);
b1.setEnabled(false);
}
return b1;
}
/**
* This method initializes b3
* @return javax.swing.JButton
* @uml.property name="b3"
*/
private JButton getB3() {
if (b3 == null) {
b3 = new JButton();
b3.setBounds(new Rectangle(591, 37, 87, 29));
b3.setText("项目成绩");
b3.addActionListener(this);
b3.setEnabled(false);
}
return b3;
}
/**
* This method initializes jComboBox2
* @return javax.swing.JComboBox
* @uml.property name="jComboBox2"
*/
private JComboBox getJComboBox2() {
if (jComboBox2 == null) {
jComboBox2 = new JComboBox();
jComboBox2.setBounds(new Rectangle(230, 74, 143, 30));
jComboBox2.setVisible(false);
ResultSet rs=db.executeQuery("select * from project");
try {
while(rs.next()){
jComboBox2.addItem(rs.getString("id").trim());
}
} catch (SQLException e) {
e.printStackTrace();
}
jComboBox2.setSelectedIndex(-1);
jComboBox2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
String sql="";
ResultSet rs;
sql="select athlete from groupathlete where groupid="+jComboBox1.getSelectedItem().toString().trim()+"";
sql="select distinct * from achievement where projectid='"+jComboBox2.getSelectedItem().toString().trim()+"' and athleteid in("+sql+")";
int total=0;
rs=db.executeQuery(sql);
int athleteID=0;
String projectID="";
int a=0;
try {
Vector row,col;
row=new Vector();
col=new Vector();
col.add("成员编号");col.add("成员名");col.add("参加项目");col.add("成绩");col.add("得分");
MyDB d=new MyDB();
d.connectDB();
while(rs.next()){
athleteID=rs.getInt("athleteID");
projectID=rs.getString("projectID");
Vector v=new Vector();
v.add(athleteID);
v.add(d.getString("select * from athlete where id="+athleteID+"", "name"));
v.add(projectID);
v.add(rs.getFloat("achievement"));
total+=rs.getInt("score");
v.add(rs.getInt("score"));
row.add(v);
}
jTable=new JTable(row,col);
jScrollPane.setViewportView(jTable);
t2.setText(total+"");
int p=1;
for(int i=0;i<jComboBox1.getItemCount();i++){
sql="select sum(score) as s from achievement where projectid='"+jComboBox2.getSelectedItem().toString().trim()+"' and athleteid in(";
sql+="select athlete from groupathlete where groupid="+jComboBox1.getItemAt(i).toString().trim();
sql+=")";
rs=d.executeQuery(sql);
while(rs.next()){
if(total<rs.getInt("s"))
p++;
}
}
t3.setText(p+"");
d.close();
} catch (SQLException e1) {
e1.printStackTrace();
}
}
});
}
return jComboBox2;
}
/**
* This method initializes t3
* @return javax.swing.JTextField
* @uml.property name="t3"
*/
private JTextField getT3() {
if (t3 == null) {
t3 = new JTextField();
t3.setBounds(new Rectangle(506, 252, 101, 32));
t3.setEditable(false);
}
return t3;
}
/**
* This method initializes b2
* @return javax.swing.JButton
* @uml.property name="b2"
*/
private JButton getB2() {
if (b2 == null) {
b2 = new JButton();
b2.setBounds(new Rectangle(477, 37, 92, 29));
b2.setText("成绩查询");
b2.addActionListener(this);
b2.setEnabled(false);
}
return b2;
}
/**
* This method initializes print
* @return javax.swing.JButton
* @uml.property name="print"
*/
private JButton getPrint() {
if (print == null) {
print = new JButton();
print.setBounds(new Rectangle(640, 254, 62, 30));
print.setText("打印");
print.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
try {
jTable.print();
} catch (PrinterException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
});
}
return print;
}
} // @jve:decl-index=0:visual-constraint="103,-25"
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -