java转成图形界面_java,关于图形界面的

该博客介绍了一个使用Java Swing库创建的图形界面裁判评分系统。程序包含一个JFrame,面板分为三部分,用于输入裁判人数、添加裁判分数及显示平均分。用户可以输入裁判数量,然后逐个添加分数,点击'平均分'按钮计算并显示所有裁判的平均得分。此外,程序还实现了错误处理,当输入无法转换为浮点数时会提示用户重新输入。
摘要由CSDN通过智能技术生成

67c0467549fe8ad325a1b37ced28d1eb.pngpackage 裁判评分;

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;

}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值