德国队vs瑞典逆转-德国vs瑞典
73 2024-10-24
1.ja射击世界杯足球赛成绩统计
ja射击世界杯足球赛成绩统计
import ja.awt.*;
import ja.awt.event.*;
import jax.swing.*;
import jax.swing.event.*;
import jax.swing.table.*;
import ja.sql.*;
public class BrowseJFrame extends JFrame implements ListSelectionListener
{
private DataBaseOperation dboper; //操纵数据库的对象
private String table; //数据库中的表名
private String[] columnNames; //指定表中所有列的中文标题
private String list_column; //表中的列
private String sort_column; //指定排序依据的列
private JList list_group; //列表框,显示分类列的不重复值
private JTable table_team; //表格组件,显示数据库中指定的内容
private DefaultTableModel tableModel; //JTable使用的模式
public BrowseJFrame(DataBaseOperation dboper, String table, String[] columnNames, String list_column, String sort_column) //构造方法,指定表名
{
this.dboper = dboper;
this.table = table;
this.columnNames = columnNames;
this.list_column = list_column;
this.sort_column = sort_column;
this.setSize(640,240); //界面设计
this.setLocation(300,240);
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
JSplitPane splitter_h = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT); //分割窗格,水平分割
this.add(splitter_h);
try
{
String[] groupdata = dboper.selectDistinct(table, list_column); //获得指定列不重复的值
this.list_group = new JList(groupdata);
this.list_group.setSelectedIndex(1); //选中第1项
splitter_h.add(new JScrollPane(this.list_group));
this.list_group.addListSelectionListener(this); //注册选择
tableModel = new DefaultTableModel(columnNames,0); //默认表格模式
this.valueChanged(null); //执行列表框的选择处理程序
this.table_team = new JTable(tableModel);
// this.table_team.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
splitter_h.add(new JScrollPane(table_team));
}
catch(Exception e)
{
e.printStackTrace();
}
this.setVisible(true);
}
public void display(String columnValue)
{
String conditions="";
if(columnValue!=null && !columnValue.equals("全部"))
conditions = this.list_column + " = '"+columnValue+"'";
try
{
dboper.select(this.table, conditions, sort_column, this.tableModel); //查询并显示指定组的数据结果集
}
catch(SQLException sqle)
{
sqle.printStackTrace();
}
}
public void valueChanged(ListSelectionEvent e) //在列表框中选择数据项时触发
{ //在表中查询指定组的数据,将数据结果集显示在表格组件中
String selecteditem = (String)list_group.getSelectedValue();
if(selecteditem!=null)
display(selecteditem);
}
public static void main(String args[])
{
String driver = "com.microsoft.jdbc.sqlserver.SQLServerDriver"; //指定SQL Server JDBC驱动程序
String url = "jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=WorldCup2006"; //指定SQL Server数据库student的URL
String user = "sa"; //指定用户名
String password = "yeheya"; //指定用户口令
try
{
DataBaseOperation dboper = new DataBaseOperation(driver,url,user,password);
String[] team_columnNames={"组别","球队1","球队2","场次","比赛时间","队1进球数","队2进球数"};
BrowseJFrame team_browse = new BrowseJFrame(dboper,"MatchRecord", team_columnNames, "group1", "number");
team_browse.setTitle("第18届世界杯足球赛 小组赛记录表(赛程安排及战况记录)2006年6月9日~7月10日 德国");
}
catch(Exception e)
{
e.printStackTrace();
}
}
}
/*
//小组赛记录表
//小组赛积分榜
String[] team_columnNames={"排名","组别","球队","国旗","场次","胜","平","负","进球","失球","净胜球","积分"};
BrowseJFrame team_browse = new BrowseJFrame(dboper,"TeamScore", team_columnNames, "group1", "rank");
team_browse.setTitle("第18届世界杯足球赛 小组赛积分榜");
public void valueChanged(ListSelectionEvent e) //在列表框中选择数据项时触发
{ //在表中查询指定组的数据,将数据结果集显示在表格组件中
String selecteditem = (String)list_group.getSelectedValue();
String conditions = this.list_column + " = '"+selecteditem+"'";
try
{
dboper.select(this.table, conditions, sort_column, this.dataModel); //查询并显示指定组的数据结果集
}
catch(SQLException sqle)
{
sqle.printStackTrace();
}
}
*/有点东西需要发给你