package 裁判评分;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;public class caipanJFrame extends JFrame implements ActionListener,qudiaozuigaoyuzuidifen//,WindowListener
{
JPanel p1=newJPanel();
JPanel p2=newJPanel();
JPanel p3=newJPanel();
JLabel b1=new JLabel("裁判人数");
TextField t1=new TextField("",7);
TextField t2=new TextField("",7);
JButton button1=new JButton("平均分");
JButton button2=new JButton("添加");publiccaipanJFrame()
{
super("模拟裁判评分");//this.setBounds(280, 100,1000, 1500);
this.setSize(300, 300);this.setBackground(Color.lightGray);//this.setLayout(new GridLayout(3,1));
this.add(p1,BorderLayout.NORTH);this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);//p1.setLayout(new GridLayout(1,3));
p1.add(b1);
p1.add(t1);
p1.add(button2);this.add(p2,BorderLayout.CENTER);//this.add(p3);
button2.addActionListener(this);
p2.setLayout(newFlowLayout());//p3.setLayout(new GridLayout(1,2));
p3.add(button1);
p3.add(t2);this.add(p3,BorderLayout.SOUTH);
button1.addActionListener(this);//this.addWindowListener(this);
this.setVisible(true);
}public voidactionPerformed(ActionEvent e)
{intn;
n=Integer.parseInt(t1.getText());
JTextField t[]=newJTextField[n];if (e.getSource()==button2)//如果点击添加按钮
{intm;for(m=0;m
{
t[m]=new JTextField("",7);
p2.add(t[m]);this.show(true);
}
}if (e.getSource()==button1)//如果点击平均分按钮
{inti;double shuzhi[]=new double[n];
String pingjunfen;for(i=0;i
{try{
shuzhi[i]= Double.parseDouble(t[i].getText()); //将文本行字符串转换成浮点数
}catch(NumberFormatException nfe)
{
JOptionPane.showMessageDialog(this, t[i].getText()+"字符串不能转换为浮点数请重新输入。");
}
}
pingjunfen=String.valueOf(qudiaozuigaoyuzuidifen(shuzhi));
t2.setText(pingjunfen);
}
}public voidwindowClosing(WindowEvent e)
{
System.exit(0);
}public static voidmain(String arg[])
{newcaipanJFrame();
System.out.println("c");
}public double qudiaozuigaoyuzuidifen(doublea[])
{inti;double zongzhi=0;doublepingjunfen;for(i=0;i
{
zongzhi+=a[i];
}
pingjunfen=zongzhi/a.length;returnpingjunfen;
}
@Overridepublic doublequdiaozuigaoyuzuidifen() {//TODO Auto-generated method stub
return 0;
}
}