实训二 博客二
成员:郭美晴:16012109
邹彤:16012107
郜硕:16012106
张文竹:16012116
git地址:https://gitee.com/hlxwzyyyyzyq/events


第一步建立udp代码
第二步数据库连接
第三步图形界面构思
将三步布组合起来,一个游戏就制作完成了
团队分工:郜硕负责udp的代码部分
张文竹负责数据库的建立
邹彤负责图形界面的部分
郭美晴负责写博客
个人贡献分:
张文竹: 8
郭美晴: 10
邹彤: 9
郜硕: 7
代码:
游戏代码
import java.awt.event.MouseEvent;
import java.util.Scanner;
public class B {
public static void main(String args[])
{
Scanner in=new Scanner(System.in); //使用Scanner类定义对象
double numn[][] = new double [100][100];
double goal[] = new double [100];
double gan[] = new double [100];
double max=0,min=100;
double sum=0,G=0;
System.out.println("请输入人数");
double nump=in.nextDouble(); //接收float型数据
System.out.println("请输入游戏次数");
double numg=in.nextDouble(); //接收float型数
for(int h=0;h<nump;h++){
goal[h]=0;
gan[h]=0;
}
for(int s=0;s<numg;s++)
{
System.out.println("游戏开始");
for(int k=0;k<nump;k++) {
System.out.println("玩家输入");
double num = in.nextDouble(); //接收float型数据
numn[s][k]=num;
}
for(int j=0;j<nump;j++)
{
sum+=numn[s][j];
}
G=(sum/nump)*0.618;//求G值
double dif=0;
for(int qq=0;qq<nump;qq++){//求分数
dif=Math.abs(numn[s][qq]-G);
goal[qq]=dif;
}
for(int f=0;f<nump;f++)
{
if(max<goal[f])
max=goal[f];
if(min>goal[f])
min=goal[f];
}
for(int th=0;th<nump;th++)
{
if(goal[th]==min)
gan[th]=gan[th]+nump;
if(goal[th]==max)
gan[th]=gan[th]-2;
}
for(int tt=0;tt<nump;tt++)
{
System.out.println(gan[tt]);
}
}
}
}
登录界面:
import java.awt.event.ActionListener;
import javax.swing.JTextField;
import javax.swing.JFrame;
import java.awt.Color;
import javax.swing.JPanel;
import javax.swing.JButton;
import javax.swing.JLabel;
import java.awt.Font;
import javax.swing.JOptionPane;
import javax.swing.JPasswordField;
import java.awt.event.ActionEvent;
public class A extends JFrame{
public JPanel pnluser;
public JLabel lbluserLogIn;
public JLabel lbluserName;
public JLabel lbluserPWD;
public JTextField txtName;
public JPasswordField pwdPwd;
public JButton btnSub;
public JButton btnReset;
public A(){
pnluser = new JPanel();
lbluserLogIn = new JLabel();
lbluserName = new JLabel();
lbluserPWD = new JLabel();
txtName = new JTextField();
pwdPwd = new JPasswordField();
btnSub = new JButton();
btnReset = new JButton();
userInit();
}
public void userInit(){
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);//关闭框架的同时结束程序
this.setSize(700,500);//框架长700,宽500
this.setResizable(false);//框架不可以改变大小
this.setTitle("黄金点");//框架标题
this.pnluser.setLayout(null);//面板布局管理
this.pnluser.setBackground(Color.pink);//面板背景颜色
this.lbluserLogIn.setText("来了老弟!");//标签标题
this.lbluserLogIn.setFont(new Font("宋体",Font.BOLD | Font.ITALIC,25));//标签字体
this.lbluserLogIn.setForeground(Color.blue);//标签字体颜色
this.lbluserName.setText("账号:");
this.lbluserPWD.setText("密 码:");
this.btnSub.setText("登录");
this.btnReset.setText("注册");
this.lbluserLogIn.setBounds(300,20,200,80);//设置标签坐标及长宽高
this.lbluserName.setBounds(250,100,70,30);
this.lbluserPWD.setBounds(250,150,70,30);
this.txtName.setBounds(300,100,140,30);
this.pwdPwd.setBounds(300,150,140,30);
this.btnSub.setBounds(365,200,70,30);
this.btnSub.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e){
btnsub_ActionEvent(e);
}
}
);
this.btnReset.setBounds(260,200,70,30);
this.btnReset.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e){
btnreset_ActionEvent(e);
}
}
);
this.pnluser.add(lbluserLogIn);
this.pnluser.add(lbluserName);
this.pnluser.add(lbluserPWD);
this.pnluser.add(txtName);
this.pnluser.add(pwdPwd);
this.pnluser.add(btnSub);
this.pnluser.add(btnReset);
this.add(pnluser);
this.setVisible(true);
}
public void btnsub_ActionEvent(ActionEvent e){
String name = txtName.getText();
String pwd = String.valueOf(pwdPwd.getPassword());
if(name.equals("")){
JOptionPane.showMessageDialog(null,"请输入账号","错误",JOptionPane.ERROR_MESSAGE);
return;
}else if (pwd.equals("")){
JOptionPane.showMessageDialog(null,"请输入密码","错误",JOptionPane.ERROR_MESSAGE);
return;
}else if(true){
this.dispose();
}
}
public void btnreset_ActionEvent(ActionEvent e){
txtName.setText("");
pwdPwd.setText("");
}
public static void main(String[] args){
new A();
}
}
运行截图:


总结:这次的实训任务到这里就结束了,我们四个各司其职,虽然并没有到达预期的结果,但是我们都做到了最大的努力,而且1+1+1+1>4,只一个人的思维是不会有太大的成果,集思广益,团队合作才是最棒的
浙公网安备 33010602011771号