기금넷 공식사이트 - 복권 조회 - JAVA36 Selection 7 복권 프로그램의 "그래픽 창 구현"을 요청하세요
JAVA36 Selection 7 복권 프로그램의 "그래픽 창 구현"을 요청하세요
java.awt.Color 가져오기;
java.awt.Container 가져오기;
java.awt.GridLayout 가져오기;
가져오기 java.awt.event.ActionEvent;
java.awt.event.ActionListener 가져오기;
java.util.ArrayList 가져오기;
java.util 가져오기. 반복자;
java.util.List 가져오기;javax.swing.JButton 가져오기;
javax.swing.JComboBox 가져오기;
javax.swing.JFrame 가져오기 ;
javax.swing.JPanel 가져오기;
javax.swing.JTextField 가져오기;공용 클래스 Caipiao{
비공개 JFrame f;
개인 컨테이너 c;
개인 JComboBox cbox;
개인 JButton b;
개인 JTextField tf;
개인 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.setRessible(false);
f.setBounds(500,200,300,100);
f.setVisible(true);
}
클래스 ButtonActionListener가 ActionListener를 구현합니다.{
public void actionPerformed(A
ctionEvent e){
String s=(String)cbox.getSelectedItem();
System.out.println("큰 승리를 기원합니다!");
int x=Integer.parseInt(s.substring(0,s.indexOf("select")));
int y=Integer.parseInt(s.substring(s.indexOf(" select" ")+1,s.length()));
tf.setText("");
ArrayList
for(int i=0;i 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 tf.setText( tf.getText()+getMin(al)+" "); al.remove(getMin(al)); } } p> } public static Object getMin(목록 목록){ int min=Integer.parseInt(list.get(0)+""); for(객체 o:list){ if(Integer.parseInt(o+"") min=Integer.parseInt(o+"") ; } } 최소 반환; } public static void main(String[] args) { new Caipiao(); } }