하는데 안되네요.
어떻게 해야하는 걸까요 ㅜㅜ
GridBagLayoutEx.java
package meth;
import java.util.Scanner;
import java.util.Random;
import java.util.Timer;
import java.util.TimerTask;
import java.awt.*;
class Timera extends TimerTask
{
public int i=3;
@Override
public void run()
{
if(i==0)
{
cancel();
}
else
System.out.println(i--+"초");
}
}
class Timerb extends TimerTask
{
public int i=7;
@Override
public void run()
{
if(i==0)
{
cancel();
}
else
System.out.println(i--+"초");
}
}
public class GridBagLayoutEx extends Frame
{
public GridBagLayoutEx()
{
}
public int GridBagLayoutEx(int num)
{
// 프레임 객체를 생성한다
Frame f = new Frame();
// GridBagLayoutEx 객체를 생성한다
GridBagLayoutEx ex = new GridBagLayoutEx();
ex.init();
// GridBagLayoutEx 객체를 프레임에 추가한다
f.add(ex);
int a, i, j;
int stop=1;
int cnt=0;
int count=0, tcount2=0;
int score=0;
int totalscore=0;
Scanner keyboard=new Scanner(System.in);
if(num==1)
{
System.out.printf("난이도는 '쉬움' 입나다.");
}
else if(num==2)
{
System.out.printf("난이도는 '보통' 입나다.");
}
else if(num==3)
{
System.out.printf("난이도는 '어려움' 입나다.");
}
else if(num==4)
{
System.out.printf("난이도는 '극악' 입나다.");
}
System.out.println("");
System.out.println("-------------------------------------------------------------------------------");
Timer aTimer = new Timer();
aTimer.schedule(new Timera(), 0, 1000);
try
{
Thread.sleep(3000);
}
catch(Exception e)
{
}
aTimer.cancel();
while(stop>0)
{
Random random=new Random();
a=0;
int anssu=0;
if(num==1)
{
a=3;
score=10;
if(count>10)
{
a=5;
score=12;
}
if(count>20)
{
a=7;
score=14;
}
if(count>30)
{
cnt=count/5;
a=9;
a+=cnt-5;
score=16;
score+=cnt-5;
}
anssu=random.nextInt(a)+1;
}
else if(num==2)
{
a=5;
score=12;
if(count>10)
{
a=7;
score=14;
}
if(count>20)
{
a=9;
score=16;
}
if(count>30)
{
cnt=count/5;
a=11;
a+=cnt-5;
score=18;
score+=cnt-5;
}
anssu=random.nextInt(a)+3;
}
else if(num==3)
{
a=7;
score=14;
if(count>5)
{
a=9;
score=16;
}
if(count>15)
{
cnt=count/5;
a=9;
a+=cnt-1;
score=16;
score+=cnt-1;
}
anssu=random.nextInt(a)+5;
}
else if(num==4)
{
a=7;
score=14;
if(count>0)
{
a+=1;
score+=1;
}
anssu=random.nextInt(a)+7;
}
char[] c = new char[anssu];
for(i=0; i<anssu; i++)
{
int munza=random.nextInt(4)+1;
if (munza==1)
c[i] = 'a';
else if (munza==2)
c[i] = 's';
else if (munza==3)
c[i] = 'd';
else if (munza==4)
c[i] = 'f';
}
System.out.println(new String(c));
String b = new String(c);
Timer bTimer = new Timer();
bTimer.schedule(new Timerb(), 0, 1000);
System.out.println("");
String d = keyboard.nextLine();
try
{
Thread.sleep(0);
}
catch(Exception e)
{
}
char ch[] = new char[d.length()];
d.getChars(0,d.length(),ch,0);
if(b.length() > d.length())
{
System.out.println("-------------------------------------------------------------------------------");
System.out.printf("게임 오버~~~~!!!\n");
System.out.printf("점수 : %d\n", totalscore);
System.out.println("-------------------------------------------------------------------------------\n\n");
System.exit(0);
}
if(b.length() < d.length())
{
System.out.println("-------------------------------------------------------------------------------");
System.out.printf("게임 오버~~~~!!!\n");
System.out.printf("점수 : %d\n", totalscore);
System.out.println("-------------------------------------------------------------------------------\n\n");
System.exit(0);
}
for(j=0; j<anssu; j++)
{
if(c[j]==ch[j])
{
System.out.println("-------------------------------------------------------------------------------");
totalscore+=score;
count++;
}
else
{
System.out.println("-------------------------------------------------------------------------------");
System.out.printf("게임 오버~~~~!!!\n");
System.out.printf("점수 : %d\n", totalscore);
System.out.println("-------------------------------------------------------------------------------\n\n");
System.exit(0);
}}
bTimer.cancel();
}
return 0;
}
protected void makebutton(String name,GridBagLayout gridbag,GridBagConstraints c)
{
Button button = new Button(name);
gridbag.setConstraints(button, c);
add(button);
}
public void init()
{
// GridBagLayout 객체를 생성한다
GridBagLayout gridbag = new GridBagLayout();
// GridBagConstraints 객체를 생성한다
GridBagConstraints c = new GridBagConstraints();
// 레이아웃 관리자를 GridBagLayout 으로 설정한다
setLayout(gridbag);
// fill 필드에 컴포넌트를 좌우로 확장하도록 값을 설정한다
c.fill = GridBagConstraints.BOTH;
// 컴포넌트가 차지할 수 있는 수평 영역의 비율을 설정한다
c.weightx = 1.0;
GridBagLayoutEx lay = new GridBagLayoutEx();
c.gridwidth = GridBagConstraints.REMAINDER;
makebutton("버튼1", gridbag, c);
c.gridwidth = GridBagConstraints.REMAINDER;
makebutton(b, gridbag, c);
c.gridwidth = GridBagConstraints.REMAINDER; <-이부분이요[b]
makebutton("버튼3", gridbag, c);
c.gridwidth = GridBagConstraints.REMAINDER;
makebutton("버튼4", gridbag, c);
setSize(300, 200);
setVisible(true);
setTitle("GridBagLayout");
}
}
SunbalryeokGame.java
import java.util.Scanner;
import meth.GridBagLayoutEx;
class SunbalryeokGame
{
public static void main(String[] args)
{
Scanner sc=new Scanner(System.in);
System.out.println("순발력게임");
System.out.println("이게임은 제한시간내에 랜덤으로 나오는 알파벳을 순서대로");
System.out.println("틀리지 않게 입력하는 게임입니다.");
System.out.println("-------------------------------------------------------------------------------");
System.out.println("난이도는 세가지로 1.'쉬움', 2.'보통', 3.'어려움', 4.'극악' 으로 나뉩니다.");
System.out.println("-------------------------------------------------------------------------------");
System.out.println("난이도를 정해주십시오");
int nan=sc.nextInt();
System.out.println("-------------------------------------------------------------------------------");
GridBagLayoutEx call=new GridBagLayoutEx();
if(nan>0 && nan<5)
{
switch(nan)
{
case 1 :
{
call.GridBagLayoutEx(1);
}
case 2 :
{
call.GridBagLayoutEx(2);
}
case 3 :
{
call.GridBagLayoutEx(3);
}
case 4 :
{
call.GridBagLayoutEx(4);
}
}
}
else
{
System.out.println("난이도 입력이 잘못되어 종료합니다.");
System.out.println("-------------------------------------------------------------------------------");
System.exit(0);
}
}
}
뭐가 잘못된건지 지적해주시면 감사하겠습니다.