📄 scoresystemmain.java
字号:
{
JOptionPane.showMessageDialog(this,"请确信是否赛季数据已被打开?");
}
}
else if(e.getActionCommand().equals(" 添加选手 "))
{
if(matchseason==null||currentsports==-1)
addSports();
String no=JOptionPane.showInputDialog("请输入选手代号:");
if(no==null) return;
if(playerdata!=null)
{
String nos[]=new String[playerdata.length];
for(int i=0;i<playerdata.length;i++)
nos[i]=playerdata[i][0].toString();
if(isInSet(no,nos)!=-1)
{
JOptionPane.showMessageDialog(this,"该选手已经存在!!!!");
return;
}
}
revised=true;
Player p=new Player(no);
matchseason.sports[currentsports].addPlayer(p);
showData();
}
else if(e.getActionCommand().equals(" 删除选手 "))
{
if(matchseason!=null&¤tsports!=-1&&tplayer!=null)
{
int ret=tplayer.getSelectedRow();
if(ret!=-1)
{
int ret1=JOptionPane.showConfirmDialog(this,"真的要删除吗?");
if(ret1!=JOptionPane.YES_OPTION) return;
Sports s=matchseason.sports[currentsports];
String no=s.player[ret].no;
s.deletePlayer(ret);
if(s.play!=null)
{
for(int i=0;i<s.play.length;i++)
if(s.play[i].player!=null)
{
int j=isInSet(no,s.play[i].player);
if(j!=-1) s.play[i].deletePlayer(j);
}
}
revised=true;
showData();
}
else
{
JOptionPane.showMessageDialog(this,"请确信在选手表中是否有被选项");
}
}
}
else if(e.getActionCommand().equals("添加花样动作"))
{
if(matchseason==null||currentsports==-1)
addSports();
String name=JOptionPane.showInputDialog("请输入花样名称:");
if(name==null) return;
if(styledata!=null)
{
String names[]=new String[styledata.length];
for(int i=0;i<styledata.length;i++)
names[i]=styledata[i][0].toString();
if(isInSet(name,names)!=-1)
{
JOptionPane.showMessageDialog(this,"该花样已经存在!!!!");
return;
}
}
revised=true;
ProgramStyle p=new ProgramStyle(name);
matchseason.sports[currentsports].addProgramStyle(p);
showData();
}
else if(e.getActionCommand().equals("删除花样动作"))
{
if(matchseason!=null&¤tsports!=-1&&tstyle!=null)
{
int ret=tstyle.getSelectedRow();
if(ret!=-1)
{
int ret1=JOptionPane.showConfirmDialog(this,"真的要删除吗?");
if(ret1!=JOptionPane.YES_OPTION) return;
Sports s=matchseason.sports[currentsports];
String no=s.style[ret].name;
s.deleteProgramStyle(ret);
if(s.play!=null)
{
for(int i=0;i<s.play.length;i++)
{
if(s.play[i].style.equalsIgnoreCase(no))
s.play[i].style="";
}
}
revised=true;
showData();
}
else
{
JOptionPane.showMessageDialog(this,"请确信在花样动作表中是否有被选项");
}
}
}
else if(e.getActionCommand().equals("添加比赛赛程"))
{
if(matchseason==null||matchseason.sports==null||currentsports==-1)
addSports();
String program=JOptionPane.showInputDialog("请输入项目名称:");
if(program==null) return;
String names[];
names=null;
Sports s=matchseason.sports[currentsports];
String style=JOptionPane.showInputDialog("请输入花样名称:");
if(style==null) return;
names=null;
if(styledata!=null)
{
names=new String[styledata.length];
for(int i=0;i<styledata.length;i++)
names[i]=styledata[i][0].toString();
}
if(names!=null&&isInSet(style,names)==-1||styledata==null)
{
ProgramStyle p=new ProgramStyle(style);
s.addProgramStyle(p);
}
revised=true;
Play p=new Play(program,style);
s.addPlay(p);
showData();
}
else if(e.getActionCommand().equals("删除比赛赛程"))
{
if(matchseason!=null&¤tsports!=-1&&tplay!=null)
{
int ret=JOptionPane.showConfirmDialog(this,"真的要删除吗?");
if(ret!=JOptionPane.YES_OPTION) return;
Sports s=matchseason.sports[currentsports];
if(s.play!=null)
{
String name=tplay.getValueAt(tplay.getSelectedRow(),0).toString();
s.deletePlay(tplay.getSelectedRow());
revised=true;
showData();
}
}
else
{
JOptionPane.showMessageDialog(this,"请确信赛季数据是否被打开?");
}
}
else if(e.getActionCommand().equals("修改&查询"))
{
if(matchseason!=null&¤tsports!=-1&&tplay!=null)
{
int i=tplay.getSelectedRow();
if(i!=-1)
{
Play p=matchseason.sports[currentsports].play[i];
int m,n;
String str;
if(p.player==null&&p.netscore==null)
{
str=JOptionPane.showInputDialog(this,"请输入当前赛项有多少名选手");
if(str==null) return;
n=Integer.parseInt(str);
if(n==0) return;
}
else if(p.player==null) n=p.netscore[0].length;
else if(p.netscore==null) n=p.player.length;
else n=p.player.length>p.netscore[0].length?p.player.length:p.netscore[0].length;
if(p.referee==null&&p.netscore==null)
{
str=JOptionPane.showInputDialog(this,"请输入当前赛项有多少名裁判");
if(str==null) return;
m=Integer.parseInt(str);
if(m==0) return;
}
else if(p.referee==null) m=p.netscore.length;
else if(p.netscore==null) m=p.referee.length;
else m=p.referee.length>p.netscore.length?p.referee.length:p.netscore.length;
Object data[][]=new Object[m+1][n+1];
if(p.player!=null)
for(int j=0;j<p.player.length;j++)
data[0][j+1]=p.player[j];
if(p.referee!=null)
for(int j=0;j<p.referee.length;j++)
data[j+1][0]=p.referee[j];
if(p.netscore!=null)
for(int j=0;j<p.netscore.length;j++)
{
if(p.netscore[j]!=null)
for(int k=0;k<p.netscore[j].length;k++)
data[j+1][k+1]=new Double(p.netscore[j][k]).toString();
}
ScoreDlg dlg=new ScoreDlg(this,data,p);
dlg.show();
showData(1);
revised=true;
}
else
{
JOptionPane.showMessageDialog(this,"请确信在赛程表中是否有被选项");
}
}
else
{
JOptionPane.showMessageDialog(this,"请确信赛季数据是否已被打开?");
}
}
}
/////给当前赛季添加运动会
private void addSports()
{
if(matchseason==null)
newFile();
String ret=JOptionPane.showInputDialog(this,"请输入运动会的名称!");
if(ret==null) return;
matchseason.addSports(new Sports(ret));
currentsports=matchseason.sports.length-1;
showData(1);
revised=true;
}
////创建按钮及其它控件
private void createLayout()
{
///////////////////////////////////////////////////////////////////////////////
Box north=Box.createHorizontalBox();
pane.add(north,BorderLayout.NORTH);
north.add(Box.createHorizontalGlue());
JButton lastsports=new JButton("前一个运动会");
north.add(lastsports);
lastsports.addActionListener(this) ;
north.add(Box.createHorizontalGlue());
JButton nextsports=new JButton("下一个运动会");
north.add(nextsports);
nextsports.addActionListener(this) ;
north.add(Box.createHorizontalGlue());
JButton addsports=new JButton("添加运动会");
north.add(addsports);
addsports.addActionListener(this) ;
north.add(Box.createHorizontalGlue());
JButton deletesports=new JButton("删除当前运动会");
north.add(deletesports);
deletesports.addActionListener(this) ;
north.add(Box.createHorizontalGlue());
JButton savesports=new JButton("保存当前运动会");
north.add(savesports);
savesports.addActionListener(this) ;
north.add(Box.createHorizontalGlue());
JButton refresh=new JButton("刷新显示");
north.add(refresh);
refresh.addActionListener(this) ;
north.add(Box.createHorizontalGlue());
////////////////////////////////////////////////////////////////////////////////
Box east=Box.createVerticalBox();
pane.add(east,BorderLayout.EAST);
east.add(Box.createVerticalGlue());
JButton addplayer=new JButton(" 添加选手 ");
east.add(addplayer);
addplayer.addActionListener(this) ;
JButton deleteplayer=new JButton(" 删除选手 ");
east.add(deleteplayer);
deleteplayer.addActionListener(this) ;
east.add(Box.createVerticalGlue());
JButton addstyle=new JButton("添加花样动作");
east.add(addstyle);
addstyle.addActionListener(this) ;
JButton deletestyle=new JButton("删除花样动作");
east.add(deletestyle);
deletestyle.addActionListener(this) ;
east.add(Box.createVerticalGlue());
JButton addplay=new JButton("添加比赛赛程");
east.add(addplay);
addplay.addActionListener(this) ;
JButton deleteplay=new JButton("删除比赛赛程");
east.add(deleteplay);
deleteplay.addActionListener(this) ;
JButton addx=new JButton("修改&查询");
east.add(addx);
addx.addActionListener(this) ;
east.add(Box.createVerticalGlue());
////////////////////////////////////////////////////////////////////////////////
JPanel middle = new JPanel();
pane.add(middle,BorderLayout.CENTER);
middle.setLayout(new BorderLayout()) ;
main = new JPanel();
middle.add(main,BorderLayout.CENTER);
main.setLayout(new GridLayout(3,1));
////////////////////////////////////////////////////////////////////////////////
Box south=Box.createHorizontalBox();
pane.add(south,BorderLayout.SOUTH);
south.add(Box.createHorizontalGlue());
south.add(new JLabel("运动会名称 "));
tfsports=new JTextField("");
south.add(tfsports);
south.add(Box.createHorizontalGlue());
south.add(new JLabel(" 开始日期 "));
tfdate=new JTextField("");
south.add(tfdate);
south.add(Box.createHorizontalGlue());
south.add(new JLabel(" 举行城市 "));
tfplace=new JTextField("");
south.add(tfplace);
south.add(Box.createHorizontalGlue());
}
////创建菜单
private void createMenu()
{
JMenuBar mb=new JMenuBar();
setJMenuBar(mb);
JMenu file=new JMenu("文件");
mb.add(file);
JMenuItem newfile=new JMenuItem("新建赛季数据文件");
file.add(newfile);
newfile.addActionListener(this);
JMenuItem load=new JMenuItem("打开赛季数据文件");
file.add(load);
load.addActionListener(this);
JMenuItem save=new JMenuItem("保存当前赛季数据");
file.add(save);
save.addActionListener(this);
JMenuItem saveas=new JMenuItem("另存当前赛季数据");
file.add(saveas);
saveas.addActionListener(this);
JMenuItem close=new JMenuItem("关闭当前赛季数据");
file.add(close);
close.addActionListener(this);
file.addSeparator();
JMenuItem exit=new JMenuItem("退出");
file.add(exit);
exit.addActionListener(this);
JMenu search=new JMenu("查找");
mb.add(search);
JMenuItem s1=new JMenuItem("查找当前赛季中某花样动作的表演次数");
search.add(s1);
s1.addActionListener(this);
JMenuItem s2=new JMenuItem("查找当前运动会某花样动作中某位选手的净得分");
search.add(s2);
s2.addActionListener(this);
JMenuItem s3=new JMenuItem("查找当前运动会中某位比赛者在所有花样动作上的平均分");
search.add(s3);
s3.addActionListener(this);
search.addSeparator();
JMenuItem s4=new JMenuItem("查找当前赛季中的所有选手");
search.add(s4);
s4.addActionListener(this);
JMenuItem s5=new JMenuItem("查找当前赛季中某比赛项目的所有选手");
search.add(s5);
s5.addActionListener(this);
search.addSeparator();
JMenuItem s6=new JMenuItem("查找某比赛项目中打最低分的裁判");
search.add(s6);
s6.addActionListener(this);
JMenuItem s7=new JMenuItem("查找某花样动作中打最低分的裁判");
search.add(s7);
s7.addActionListener(this);
JMenu help=new JMenu("帮助");
mb.add(help);
JMenuItem about=new JMenuItem("关于ScoreSystem...");
help.add(about);
about.addActionListener(this);
JMenuItem topic=new JMenuItem("帮助主题");
help.add(topic);
topic.addActionListener(this);
}
public ScoreSystemMain()
{
this.addWindowListener(new WindowAdapter(){
public void windowClosing( WindowEvent e )
{
quit();
}});
pane=this.getContentPane();
pane.setLayout(new BorderLayout());
setTitle(fullname);
currentsports=-1;
createLayout();
createMenu();
}
public static void main(String[] args)
{
ScoreSystemMain frame= new ScoreSystemMain();
Dimension screensize = Toolkit.getDefaultToolkit().getScreenSize();
frame.setBounds(0,0,(int)(screensize.getWidth()),(int)(screensize.getHeight())-50);
frame.setVisible(true);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -