2008년 6월 23일 월요일

Lotto Test


설명이 필요하시면 쪽지 주시고요 ^^.

import java.awt.*;
import java.awt.event.*;
import java.util.Random;
import javax.swing.*;


public class LottoTest extends JFrame
{
JButton b1,b2,b3,b4,b5,b6,b7;
Panel p1,p2;
Label l;

public static void main(String arg[])

{
LottoTest lt = new LottoTest();
lt.display();
}

LottoTest()

{

b1=new JButton(" ");
b2=new JButton(" ");
b3=new JButton(" ");
b4=new JButton(" ");
b5=new JButton(" ");
b6=new JButton(" ");
p1=new Panel(new FlowLayout(50,50,50));
b7=new JButton(" ok ");

b7.addActionListener(new MyEventHandler());//추가하세요.

p2=new Panel(new FlowLayout(50,50,50));
l=new Label("0438115 김성진");
p1.add(b7);
p2.add(l);
addWindowListener(new WindowH());

}

class WindowH extends WindowAdapter

{
public void windowClosing(WindowEvent we)

{
System.exit(0);
}
};


class MyEventHandler implements ActionListener {

public void actionPerformed(ActionEvent e){

Getlotto();

}

}//추가 부분

public void display()

{

setLayout(new FlowLayout());
add(b1);
add(b2);
add(b3);
add(b4);
add(b5);
add(b6);
add(p2);
add(p1);
setSize(400,300);

//pack();

setVisible(true);

}

public void Getlotto() {

// TODO Auto-generated method stub

int num[] = new int[6];

for (int i = 0; i < 6; i++) {

Random ran = new Random();

num[i] = ran.nextInt(45) + 1;

for (int j = 0; j < i; j++) {

if (num[i] == num[j]) {

num[i] = ran.nextInt(46) + 1;

i = i - 1;

break;

}

}

}

for (int i = 0; i < 6; i++) {

switch (i) {

case 0:

b1.setLabel(String.valueOf(num[i]));

break;

case 1:

b2.setLabel(String.valueOf(num[i]));

break;

case 2:

b3.setLabel(String.valueOf(num[i]));

break;

case 3:

b4.setLabel(String.valueOf(num[i]));

break;

case 4:

b5.setLabel(String.valueOf(num[i]));

break;

case 5:

b6.setLabel(String.valueOf(num[i]));

}

}// 추가 부분


}
}



댓글 없음:

댓글 쓰기

-


Sidewinder


World


FishMusic


LaughingBaby