Java实现双色球复式计算
时间:2011-01-19
今天偶作一双色球复式投注计算。其实很简单,计算出组合数即可。界面设计采用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();
}
}
**************结束
|