小白学java——做一个歌手比赛系统(一)

来源:互联网 发布:阿里云公网ip访问不了 编辑:程序博客网 时间:2024/06/18 05:08
       

 歌手比赛系统

对一次歌手比赛的成绩进行管理,功能要求1、输入每个选手的数据包括号、姓名、十个评委的成绩,根据输入计算出总成绩和平均成绩(去掉最高分,去掉最低分)2、显示主菜单如下:1)输入选手数据 2)评委打分 3)成绩排序(按平均分)4数据查询  5)追加学生数据 6)写入数据文件7)退出系统。

这学期的大作业,要求必须用gui界面和数据库,第一次写CSDN,第一次在网上发表文章,有些忐忑呢

 

由于老师讲得比较快加上自己平时练得不够,对我来说完全是从0开始,从页面布局等等,从网上看了一些代码以及看书,现在只做出来了基本的界面,数据库还没连上。


主界面中间留的空间是想插入一个表格,数据都在表格中,按了成绩排序时就会按照成绩从高到低排序,当添加了数据时可以在表格中看到


 代码:

public class SingerManage extends JFrame implements ActionListener{
 JPanel jp1, jp2,jp3;
 JLabel jl1,jl2;
 JButton jb1, jb2, jb3, jb4,jb5,jb6;
 JTable jt = null;
 JScrollPane jsp = null;
 JTextField jtf;
 JTable jt2 = null;
 JScrollPane jsp2 = null;
 
 Connection conn = null;
 PreparedStatement ps = null;
 
 
 public SingerManage(){
  jp1 = new JPanel();
  jtf = new JTextField(10);
  jb1 = new JButton("数据查询");
  jb1.addActionListener(this);
  jl2 = new JLabel("欢迎进入歌手管理系统!");
  
  jp3=new JPanel();
  jl1 = new JLabel("请输入选手数据:");
  
  jp1.add(jl2);
  
  jp3.add(jl1);
  jp3.add(jtf);
  jp3.add(jb1);
  
  jp2 = new JPanel();
  jb2 = new JButton("成绩排序");
  jb2.addActionListener(this);
  jb3 = new JButton("追加数据");
  jb3.addActionListener(this);
  jb4 = new JButton("写入数据文件");
  jb4.addActionListener(this);
  jb5 = new JButton("评委评分");
  jb5.addActionListener(this);
  jb6 = new JButton("退出系统");
  jb6.addActionListener(this);
  
  jp2.add(jb2);
  jp2.add(jb3);
  jp2.add(jb4);
  jp2.add(jb5);
  jp2.add(jb6);
  
  //jt = new JTable(singer);
  jsp = new JScrollPane(jt);
  
  this.add(jsp);
  this.add(jp1, "North");
  this.add(jp2, "South");
  this.add(jp3,"Center");
  
  this.setTitle("歌手管理系统");
  this.setSize(400, 300);
  this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  this.setVisible(true);
  setSize(500,400);
  this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  setVisible(true);
 }
 
 public void actionPerformed(ActionEvent e) {
   if(e.getSource()=="数据查询"){
   /*singer=new SingerModel();
  
   jt.setModel(singer);*/
  }else if(e.getSource()==jb3){
   SingerAdd add=new SingerAdd();
  }else if(e.getSource()==jb5){
      Judge jud=new Judge();
  }else if(e.getSource()=="成绩排序"){
   
  }else if(e.getSource()=="写入数据文件"){
   
  }else if(e.getSource()=="退出系统"){
   
  }
 }
 public static void main(String[] args) {
  // TODO Auto-generated method stub
  SingerManage demo = new SingerManage();
 }
 

按了评委评分之后:

在这里的界面设计是碰到了一些问题,因为BorderLayout布局只有东、西、南、北、中五种布局,无法同时出现三列。后来看了一些文章,改成了用JPanel的嵌套组织组件,在JFrame中的ContenPane对象,可以使用Container类的getContenPane()方法。

代码:

public class Judge extends JFrame implements ActionListener  {
 JPanel jp1,jp2,jp3,jp4,jp5;
 JLabel jl1, jl2,jl3,jl4;
 JButton jb1, jb2,jb3;
 JTextField jf1, jf2,jf3,jf4;
 JFrame frame=new JFrame();
 Container contentPane=frame.getContentPane();//获得放置组件的容器对象
 //contentPane.setLayout(new GridLayout(1,2));
 @SuppressWarnings("deprecation")
 public Judge(){
  jl1 = new JLabel("请输入选手姓名");
  jl2 = new JLabel("请输入选手编号");
  jl3=new JLabel("请十个评委评分");
  jb2=new JButton("得分");
  jb2.addActionListener(this);
  
  jf1 = new JTextField(10);
  jf2 = new JTextField(10);
  jf3 = new JTextField(10);
  jf4=new JTextField(10);
  //jf4.setEditable(false);
  
  jb1 = new JButton("Random");
  jp1 = new JPanel();
  jp2 = new JPanel();
  jp3 = new JPanel();
  jp5= new JPanel();
  
  jp1.add(jl1);
  jp1.add(jl2);
  jp1.add(jb2);
  
  jp2.add(jf3);
  jp2.add(jf1);
  jp2.add(jf2);
  
  jp3.add(jl3);
  jp3.add(jf4);
  jp3.add(jb1);
  
  
  
  contentPane.setLayout(new GridLayout(2,1));//布局2行1列
  jp1.setLayout(new GridLayout(3, 1));//面板布局3行1列
  jp2.setLayout(new GridLayout(3, 1));//
  jp3.setLayout(new GridLayout(3, 1));//
  jp5.setLayout(new GridLayout(1, 1));//
  
  jp5.add(jp1);//将面板1加入到面板5中
  jp5.add(jp2);//
  jp5.add(jp3);//
  
  contentPane.add(jp5);//将面板5放入框架容器
  
 
  jb1.addActionListener(this);
  
  frame.pack();
  frame.setTitle("评委评分");
  frame.setSize(450,200);
  frame.show();
  
  
  
 }
 public void actionPerformed(ActionEvent e) {
  double n1=Double.parseDouble(jf1.getText());
 
  
  if(e.getSource()==jb1){
   
  }else if(e.getSource()==jb2){
   jf4.setText(n1+"");
   frame.show();
  }
 }

}


 按了追加数据之后:


 代码:

public class SingerAdd extends JDialog implements ActionListener  {
 JPanel jp1,jp2,jp3;
 JLabel jl1, jl2,jl3;
 JButton jb1, jb2;
 JTextField jf1, jf2,jf3;
public SingerAdd(){
  
  
  jl1 = new JLabel("姓名");
  jl2 = new JLabel("编号");
  jl3 =new JLabel("得分");
  
  jf1 = new JTextField();
  jf2 = new JTextField();
  jf3 = new JTextField();
  
  jb1 = new JButton("添加");
  jb2 = new JButton("取消");
  
  jp1 = new JPanel();
  jp2 = new JPanel();
  jp3 = new JPanel();
  
  jp1.setLayout(new GridLayout(4, 1));
  jp2.setLayout(new GridLayout(4, 1));
  
  jp1.add(jl1);
  jp1.add(jl2);
  jp1.add(jl3);
  
  jp2.add(jf1);
  jp2.add(jf2);
  jp2.add(jf3);
  jp3.add(jb1);
  jp3.add(jb2);
  
  this.add(jp1, BorderLayout.WEST);
  this.add(jp2, BorderLayout.CENTER);
  this.add(jp3, BorderLayout.SOUTH);
  
  jb1.addActionListener(this);
  
  this.setTitle("追加数据");
  this.setSize(300, 200);
  this.setVisible(true);

  }





阅读全文
'); })();
0 0
原创粉丝点击
热门IT博客
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 火腿肠保质期 狗能吃火腿肠吗 青椒炒火腿肠 玉米炒火腿肠 青椒火腿肠 玉米粒炒火腿肠 狗狗火腿肠 火腿肠馒头卷 火腿肠炒辣椒 火腿肠炒胡萝卜 火腿肠怎么剥皮 怀孕吃火腿肠 猫能不能吃火腿肠 火腿肠怎么做 火腿肠的做法大全 煎火腿肠 火腿肠怎么炒好吃 狗狗可以吃火腿肠吗 火腿肠的危害 坐月子能吃火腿肠吗 怀孕能吃火腿肠吗 狗狗能吃火腿肠吗 火腿肠制作过程 小狗能吃火腿肠吗 自制火腿肠的做法大全 鸡蛋炒火腿肠 火腿肠是怎么做出来的 双汇火腿肠的危害 玉米火腿肠的危害 火腿肠的热量 火腿肠怎么炒 火腿肠炒什么好吃家常菜 火腿肠是什么做的 火腿肠怎么切好看 炸火腿肠的做法 双汇火腿肠死人肉做的 火腿肠的炒法 火腿肠怎么做的 火腿肠怎么炸好吃 鸡蛋火腿肠炒饭 火腿肠炒饭怎么做