标题: [基础] 双色球复式计算
ljjk5
元帅
Rank: 1


荣誉会员奖章
UID 46706
精华 1
积分 99426
帖子 49690
威望 554
金币 48489
热心 505
阅读权限 100
注册 2007-2-25
状态 离线
双色球复式计算

今天偶作一双色球复式投注计算。其实很简单,计算出组合数即可。界面设计采用AWT,列表框的值选中之后,激发itemStateChanged事件进行处理。下面是实例:  package study;
import java.awt.*;
import java.awt.event.*;
public class ssq extends Frame //implements ActionListener
{
Label a=new Label("请选择红球和篮球号码:");
Label sta=new Label("谢谢使用世讯通软件!Copyright by Mr.Zhou;firstcoffee@sina.com;OICQ:5129575");
Panel p=new Panel();
Panel p1=new Panel();
TextArea ta = new TextArea();
List h=new List(4);
List l=new List(4);
Button bn=new Button("清除");
   long tmp_count;
   int tmp_r,tmp_b;
public ssq()
{
  super("双色球复式计算");
  setSize(500,310);
  for(int i=7;i<=20;i++)
    {
    h.addItem(String.valueOf(i));
    }
  for(int i=1;i<=16;i++)
    {
    l.addItem(String.valueOf(i));
    }
   
   h.setBackground(Color.ORANGE);
   l.setBackground(Color.blue);
     h.select(0);
     l.select(0);
  p.add(a);
  p.add(h);
  p.add(l);
  p.add(bn);
  p1.add(ta);
  p1.add(sta);
  add("North",p);
  add("Center",p1);

    addWindowListener(new WindowAdapter()
    {
    public void windowClosing(WindowEvent e)
     {
     System.exit(0);
     }

   });
   ta.append("计算结果:"+"
");
   h.addItemListener(new ItemListener()
   {
    public void itemStateChanged(ItemEvent e){
    tmp_r=Integer.parseInt(h.getSelectedItem());
    }
});
   l.addItemListener(new ItemListener()
   {
    public void itemStateChanged(ItemEvent e1){
    tmp_b=Integer.parseInt(l.getSelectedItem());
     print(tmp_r,tmp_b);
}
});
     bn.addActionListener(new ActionListener(){
      public void actionPerformed(ActionEvent e)
{
      ta.setText("计算结果:"+"
");
      }

     }
     );
   
   super.setResizable(false);
   
   
   
   show();


   
}
   
    long count(int x,int y)
    {
     long tmp_count1;  //fdfdfdfdfd
     int a,b;
     long p=1,c=1;
     a=x;b=y;
     for(int i=1;i<=6;i++)
     {
      c=c*i;
     }
     for(int j= (a-5) ;j<=a;j++)
     {
      p=p*j;
     }
     //System.out.println(p);
     tmp_count1=p/c*b;
     return tmp_count1;
    
    }
    void print(int x1,int y1)
    { long tmp_count2;
     tmp_count2=count(x1,y1);
    //System.out.println("tmp_count2="+tmp_count2);
    
    ta.append(tmp_r+"个红球加"+tmp_b+"个蓝球"+"总金额:"+tmp_count2*2+"
");
    }
public static void main(String arg[])
{
  new ssq();
   }

}
**************结束

网友 ljjk5 签名 - 网友社区 ===
顶部
[广告] 免费域名(Free Subdomain) 免费空间(Free hosting) PR查询(Google Pagerank)



当前时区 GMT+8, 现在时间是 2008-10-11 21:07
信产部ICP备案:京ICP备05066424号 北京市公安局网监备案:1101050648号

Powered by Discuz! 5.5.0
清除 Cookies - 联系我们 - 网友俱乐部 - Archiver - WAP