求JAVA36选7彩票程序“图形窗口实现”

用户从文本框输入要买彩票的注数N,程序随机产生N注号码并输出,每个号码为七个1~36的随机整数…每注七个号码不能重复…
题目要求啊

import java.awt.Color;
import java.awt.Container;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTextField;public class Caipiao{
private JFrame f;
private Container c;
private JComboBox cbox;
private JButton b;
private JTextField tf;
private JPanel p1;
private JPanel p2;

public Caipiao(){
f=new JFrame("彩票选购系统");
c=f.getContentPane();
c.setLayout(new GridLayout(2,1));

p1=new JPanel();
p2=new JPanel();
p1.setBackground(Color.gray);
cbox=new JComboBox();
cbox.addItem("36选7");
cbox.addItem("15选5");

b=new JButton("开始选取");
tf=new JTextField(25);
tf.setEditable(false);

b.addActionListener(new ButtonActionListener());

p1.add(cbox);
p1.add(b);
p2.add(tf);

c.add(p1);
c.add(p2);

f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setResizable(false);
f.setBounds(500,200,300,100);
f.setVisible(true);

}
class ButtonActionListener implements ActionListener{
public void actionPerformed(ActionEvent e){
String s=(String)cbox.getSelectedItem();
System.out.println("祝您赢大奖!");
int x=Integer.parseInt(s.substring(0,s.indexOf("选")));
int y=Integer.parseInt(s.substring(s.indexOf("选")+1,s.length()));
tf.setText("");
ArrayList<Object> al=new ArrayList<Object>();
for(int i=0;i<y;){
double a=Math.round(100*Math.random());
if(a>0 && a<=x){
if(!al.contains((int)a)){
//System.out.println(a);
al.add((int)a);
i++;
}
}
}
int count=al.size();
for(int i=0;i<count;i++){
tf.setText(tf.getText()+getMin(al)+" ");
al.remove(getMin(al));
}
}
}

public static Object getMin(List list){
int min=Integer.parseInt(list.get(0)+"");
for(Object o:list){
if(Integer.parseInt(o+"")<min){
min=Integer.parseInt(o+"");
}
}
return min;
}

public static void main(String[] args){
new Caipiao();
}
}
温馨提示:答案为网友推荐,仅供参考
第1个回答  2013-07-20
Math.random()就行了,不就是生成7个随机数么
第2个回答  2013-07-20
你是买什么彩票; 福彩还是体彩哦
相似回答