Java實現雙色球複式計算

來源:互聯網
上載者:User

今天偶作一雙色球複式投注計算。其實很簡單,計算出組合數即可。介面設計採用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();
   }

}
**************結束

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.