자바클래스 하나추가해주세요ㅠㅠ
다인
import java.awt.*;
import java.awt.event.*;
import java.util.*;
public class kk extends Frame implements ActionListener{
private Panel pn1,pn2,pn3;
private Button b[];
private Button result,reset;
private TextField textTF[];
private TextArea textA;
private Color c;
private int buttonCount; //버튼 누르는 횟수 : 3자리
private int totalChance; //총 맞출수 있는 기회 :5회
private int strike,ball;
private int ranNum[]; //랜덤 수
private int inputNum[]; //버튼으로 받아들이는 수
private boolean duplicate[]; //중복 체크 변수
private boolean success;
public kk(){// 생성자
success=false;
inputNum=new int[3];
duplicate= new boolean[9];
ranNum=new int[3];
c=new Color(230,230,255);
setBackground(Color.gray);
setLayout(new BorderLayout(2,3));
pn1=new Panel();
pn1.setBackground(Color.gray);
pn1.setLayout(new GridLayout(1,3,10,2));
textTF= new TextField[3];
for(int i=0;i3;i++){
textTF[i]=new TextField(4);
textTF[i].setBackground(c);
pn1.add(textTF[i]);
textTF[i].setEnabled(false);
}
result=new Button(확인);
result.setEnabled(false);
result.addActionListener(this);
result.setActionCommand(result);
pn1.add(result);
add(North,pn1);
pn2=new Panel();
pn2.setBackground(Color.gray);
pn2.setLayout(new GridLayout(3,3,2,2));
b=new Button[9];
for(int i=0;i9;i++){
b[i]=new Button(+(i+1));
b[i].addActionListener(this);
pn2.add(b[i]);
}
add(Center,pn2);
pn3=new Panel();
pn3.setBackground(Color.gray);
pn3.setLayout(new FlowLayout());
textA= new TextArea(4,30);
textA.setBackground(c);
textA.setEnabled(false);
pn3.add(textA);
reset= new Button(재시도);
reset.addActionListener(this);
reset.setEnabled(false);
pn3.add(reset);
add(South,pn3);
addWindowListener(new WindowHandler());
makeRandom();
pack();
setVisible(true);
}
public class WindowHandler extends WindowAdapter implements WindowListener{
public void windowClosing(WindowEvent e){
setVisible(false);
dispose();
System.exit(0);
}
}
public void makeRandom(){//랜덤 수 정하기
Random rand = new Random();
int num;
for(int i=0;i9;i++)
duplicate[i]=true;
for(int i=0;i3;){// 중복 체크
num=rand.nextInt(9);
if(duplicate[num]){
ranNum[i]=num+1;
duplicate[num]=false;
i++;
}
}
}
public void resultM(){// 확인?
for(int i=0;itextTF.length;i++){
textTF[i].setText();
}
for(int i=0;ib.length;i++){
b[i].setEnabled(true);
result.setEnabled(false);
}
totalChance++;
check();
if(totalChance==8 && !success) {
textA.append(기회 초과!! 실패!!\n);
success=false;
reGame();
}
}
public void reGame(){// 재시도 ?
reset.setEnabled(true);
result.setEnabled(false);
for(int i=0;ib.length;i++){
b[i].setEnabled(false);
}
}
public void check(){// 랜덤수와 입력된 수 비교
for(int i=0;i3;i++){
for(int j=0;j3;j++){
if(i==j && inputNum[i]==ranNum[j])strike++;
else if(inputNum[i]==ranNum[j])ball++;
}
}
if(strike==3){
textA.append(이겼네요!! 추카 !! \n);
success=true;
reGame();
}else {
textA.append(inputNum[0]+ +inputNum[1]+ +inputNum[2]+ =
+strike+ 스트라이크 +ball+볼\n);
}
strike=ball=0;
}
public void resetM(){//재경기 셋팅
makeRandom();
totalChance=buttonCount=0;
for(int i=0;ib.length;i++){
if(i3)textTF[i].setText();
b[i].setEnabled(true);
}
textA.setText();
result.setEnabled(false);
reset.setEnabled(false);
}
public void actionPerformed(ActionEvent ae){
String performB = ae.getActionCommand();
if(performB.equals(result)){
resultM();
}
else if(performB.equals(재시도)){
resetM();
}
else{
int i = Integer.parseInt(performB);
inputNum[buttonCount]=i;
b[i-1].setEnabled(false);
textTF[buttonCount].setText(ae.getActionCommand());
if(buttonCount==2) {
for(i=0;ib.length;i++){
b[i].setEnabled(false);
result.setEnabled(true);
}
buttonCount=0;
}
else buttonCount++;
}
}
public static void main(String args[]){
new kk();
}
}지금 클래스 2개잇는건맞죠ㅠㅠ?
하나만 더 만들어주세요ㅠㅠ
아니면 지금있는걸로 3개클래스로 나눠주세요
정말 진심으로부탁드립니당
번호 | 제 목 | 글쓴이 | 날짜 |
---|---|---|---|
2696094 | exe 파일 | 제철 | 2025-05-26 |
2696043 | 제이쿼리 .scroll() 관련 질문드립니다 | 이거이름임 | 2025-05-26 |
2695984 | 마크업상으로 하단에 있으나 우선적으로 이미지파일을 다운로드받는 방법 (1) | 들꿈 | 2025-05-25 |
2695934 | tr 속성값 (9) | 새 | 2025-05-25 |
2695905 | ASP로 개발됐을 때 css가 달라져요 ㅠㅠ (4) | 슬아라 | 2025-05-24 |
2695878 | form을 이용한 다른 페이지로 넘기는 방법을 알려주세요 (1) | 핫파랑 | 2025-05-24 |
2695844 | 저기 암호화 및 복호화 프로그램.. 만들어볼려는대 (2) | 한빛 | 2025-05-24 |
2695814 | [질문] PDA에서 애플릿이 가능한가요? (1) | 봄시내 | 2025-05-24 |
2695785 | 웹 설정 도와줄분 | 화이트캣 | 2025-05-23 |
2695730 | 갑자기 기억이 안나는데 accesskey 속성.. | 빛나라 | 2025-05-23 |
2695702 | [질문] Java 버전 차이에 의한 오류?!! (2) | 검사 | 2025-05-23 |
2695672 | 자바 임베디드 쪽으로 배우고 싶은데요..질문이요.. (1) | 뽀그리 | 2025-05-22 |
2695647 | 헉! 이클립스(v3.1)에서 발생되는 널포인트 익셉션? ;;; (3) | 아빠몬 | 2025-05-22 |
2695586 | IFRAME 캐싱 질문 | 봄나비 | 2025-05-22 |
2695498 | [질문]실행가능한 jar파일.. 정말 이해가 안가네요... ㅡㅜ;; | 터1프한렩 | 2025-05-21 |
2695468 | 자바랑 이클립스에서요.. | 스킬 | 2025-05-21 |
2695375 | Mysql 연동하는 자바 질문있습니다. | 아리솔 | 2025-05-20 |
2695319 | 파워포인트 파일을 저장할 수 있을까요? | 시윤 | 2025-05-19 |
2695289 | [질문]Tween 값의 정도를 알고 싶습니다. | 타마 | 2025-05-19 |
2695238 | c 와 c++의 시작 (10) | ChocoHoilc | 2025-05-18 |