今天偶作一雙色球復式投注計算。其實很簡單,計算出組合數即可。界面設計采用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;[email protected];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();
}
}
**************結束