/*import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class Main extends JFrame {
GunThread th;
ChikenThread th1 = new ChikenThread();
SildThread st = new SildThread();
Container c = getContentPane();
JLabel la = new JLabel();
ImageIcon img = new ImageIcon("patrick Chiken Thread.png");
JLabel la1 = new JLabel(img);
JLabel la2 = new JLabel("0");
JLabel las = new JLabel("0");
JButton la3 = new JButton("게임방법");
JButton JL = new JButton("다시시작");
int score=0;
int combo=0;
int time=20;
//private Image background=new ImageIcon("backgroufdrfsdg").getImage();
public Main() {
setTitle("사격 게임");
c.setLayout(null)
c.addKeyListener(new MyKeyListener());
c.setFocusable(true);
c.requestFocus();
c.setBackground(new Color(53,206,80));
c.add(la);
la.setLocation(250,450);
la.setSize(10,10);
la.setBackground(Color.red);
la.setOpaque(true);
c.add(la1);
la1.setLocation(0,0);
la1.setSize(30,30);
// 슬라이드 레이블 초기위치, 사이즈, 크기, 움직이는방향 설정
c.add(las);
las.setLocation(40, 40);
las.setSize(10, 10);
la.setOpaque(true);
c.add(la2);
la2.setLocation(220,230);
la2.setSize(60,40);
la2.setFont(new Font("Impact",Font.PLAIN,30));
c.add(JL);
JL.setLocation(300,400);
JL.setSize(150,50);
JL.addActionListener(new MyActionListener());
JDialog dialog = new JDialog();
dialog.setTitle("사격 게임 방법");
dialog.setLayout(null);
JLabel dla1 = new JLabel("<html>빨간사각형:총=엔터를 눌렀을때 발사,과녁을 10번이상 맞혔을땐 더빨라진다<br><br>닭다리:과녁=오른쪽으로이동(벽에닿으면 왼쪽끝으로 이동)총알한테 10번이상 맞았을때 더빨라진다.<br><br>점수판:총이 과녁에 맞았을때 1증가(연속으로 맞추면 맞춘수만큼 증가)<br><br>보호막:보호막은 과녁을 지킨다.보호막에 총알이 다으면 총알은 원위치로 돌아간다.<br><br> 다시시작:초기화됨</html>");
dla1.setFont(new Font("Gothic",Font.ITALIC,15));
dla1.setLocation(10, 1);
dla1.setSize(450, 300);
dialog.add(dla1);
JButton exit = new JButton("닫기");
exit.setLocation(380,250);
exit.setSize(100,40);
dialog.add(exit);
exit.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
dialog.setVisible(false);
}
});
dialog.setSize(500,350);
dialog.setVisible(false);
c.add(la3);
la3.setSize(150,50);
la3.setLocation(50, 400);
la3.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
dialog.setVisible(true);
}
});
th1.start();
setSize(500,500);
setVisible(true);
}
//public void paint(Graphics g) {//그리는 함수
//la.setBackground(Color.green);//background를 그려줌
//}
class MyKeyListener extends KeyAdapter {
//e.getKeyCode() 엔터 10, 스페이스 32
public void keyPressed(KeyEvent e) {
if((th==null|| th.getState()==Thread.State.TERMINATED) && e.getKeyCode()==10) {//집가서 정리
th = new GunThread();
th.start();
st.start();
}
}
}
class MyActionListener implements ActionListener{
public void actionPerformed(ActionEvent e) {
score=0;
combo=0;
time=20;
la2.setText("0"); //점수판을 0점으로 보이게 리셋
c.setFocusable(true);
c.requestFocus();
}
}
class GunThread extends Thread {
synchronized public void run() {
while(true) {
try {
sleep(time);
}catch (Exception e) {
int x1 = la.getX();
int y = la.getY();
la.setLocation(x1,y -5 );
if(y<0 || la.getY()<=30 && (220<=la1.getX() && la1.getX()<=260) ) {
la.setLocation(250,450);
if(score==10) {
time=10;
}
if(y>0) { //명중
combo++;
score+=combo;
la2.setText(Integer.toString(score) );
}//그 점수만큼 점수얻기
else{
combo=0;
}
return ;
//break; //명중 or 실패
}
}
}
}
class ChikenThread extends Thread {
int jy=20;
public void run() {
while(true) {
try {
sleep(jy);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
int x = la1.getX();
int y = la1.getY();
if(x>=500) la1.setLocation(0, y);
else la1.setLocation(x+5,y);
if(score==10) {
jy=15;
}
}
}
}/*
class sildThread extends Thread {
int yj=20;
public void run() {
while(true) {
try {
sleep(yj);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
//int x = la1.getX();
//int y = la1.getY();
//if(x>=500) la1.setLocation(0, y);
//else la1.setLocation(x+5,y);
int x = la2.getX();
int y = la2.getY();
if(th1 x== ) {
}
}
}
}*//*
class SildThread extends Thread {
synchronized public void run() {
while(true) {
try {
sleep(time);
}catch (Exception e) {
}
int x1 = las.getX();
int y = las.getY();
las.setLocation(x1+5,y);
if(y<0 || las.getY()<=30 && (220<=las.getX() && las.getX()<=260) ) {
las.setLocation(100,250);
}
}
}
}
public static void main(String[] args) {
new Main();
}
}
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class Main extends JFrame {
GunThread th;
ChikenThread th1 = new ChikenThread();
Container c = getContentPane();
JLabel la = new JLabel();
ImageIcon img = new ImageIcon("patrick Chiken Thread.png");
JLabel la1 = new JLabel(img);
JLabel la2 = new JLabel("0");
JButton la3 = new JButton("게임방법");
JButton JL = new JButton("다시시작");
int score=0;
int combo=0;
int time=20;
private Image background=new ImageIcon("backgroufdrfsdg").getImage();
public Main() {
setTitle("사격 게임");
c.setLayout(null);
c.addKeyListener(new MyKeyListener());
c.setFocusable(true);
c.requestFocus();
c.setBackground(new Color(53,206,80));
c.add(la);
la.setLocation(250,450);
la.setSize(10,10);
la.setBackground(Color.red);
la.setOpaque(true);
c.add(la1);
la1.setLocation(0,0);
la1.setSize(30,30);
la1.setOpaque(true);
c.add(la2);
la2.setLocation(220,230);
la2.setSize(60,40);
la2.setFont(new Font("Impact",Font.PLAIN,30));
c.add(JL);
JL.setLocation(300,400);
JL.setSize(15,50);
JL.addActionListener(new MyActionListener());
JDialog dialog = new JDialog();
dialog.setTitle("사격 게임 방법");
dialog.setLayout(null);
JLabel dla1 = new JLabel("<html>빨간사각형:총=엔터를 눌렀을때 발사,과녁을 10번이상 맞혔을땐 더빨라진다<br><br>닭다리:과녁=오른쪽으로이동(벽에닿으면 왼쪽끝으로 이동)총알한테 10번이상 맞았을때 더빨라진다.<br><br>점수판:총이 과녁에 맞았을때 1증가(연속으로 맞추면 맞춘수만큼 증가)<br><br>다시시작:다시시작됨</html>");
dla1.setFont(new Font("Gothic",Font.ITALIC,20));
dla1.setLocation(10, 1);
dla1.setSize(450, 300);
dialog.add(dla1);
JButton exit = new JButton("닫기");
exit.setLocation(380,250);
exit.setSize(100,40);
dialog.add(exit);
exit.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
dialog.setVisible(false);
}
});
dialog.setSize(500,350);
dialog.setVisible(false);
c.add(la3);
la3.setSize(150,50);
la3.setLocation(50, 400);
la3.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
dialog.setVisible(true);
}
});
th1.start();
setSize(500,500);
setVisible(true);
}
//public void paint(Graphics g) {//그리는 함수
//la.setBackground(Color.green);//background를 그려줌
//}
class MyKeyListener extends KeyAdapter {
//e.getKeyCode() 엔터 10, 스페이스 32
public void keyPressed(KeyEvent e) {
if((th==null|| th.getState()==Thread.State.TERMINATED) && e.getKeyCode()==10) {//집가서 정리
th = new GunThread();
th.start();
}
}
}
class MyActionListener implements ActionListener{
public void actionPerformed(ActionEvent e) {
score=0;
combo=0;
time=20;
la2.setText("0"); //점수판을 0점으로 보이게 리셋
c.setFocusable(true);
c.requestFocus();
}
}
class GunThread extends Thread {
synchronized public void run() {
while(true) {
try {
sleep(time);
}catch (Exception e) {
}
int x1 = la.getX();
int y = la.getY();
la.setLocation(x1,y -5 );
if(y<0 || la.getY()<=30 && (220<=la1.getX() && la1.getX()<=260) ) {
la.setLocation(250,450);
if(score==10) {
time=10;
}
if(y>0) { //명중
combo++;
score+=combo;
la2.setText(Integer.toString(score) );
}//그 점수만큼 점수얻기
else{
combo=0;
}
return ;
//break; //명중 or 실패
}
}
}
}
class ChikenThread extends Thread {
int jy=20;
public void run() {
while(true) {
try {
sleep(jy);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
int x = la1.getX();
int y = la1.getY();
if(x>=500) la1.setLocation(0, y);
else la1.setLocation(x+5,y);
if(score==10) {
jy=15;
}
else if(score==100){
jy=10;
}
}
}
}
public static void main(String[] args) {
new Main();
}
} */
/*
문양 : 1~ 8의 랜덤 숫자
카드 : 라벨
1. 처음 블루팀이 먼저 시작한다.
2.(카드는 총 16장이있다) 카드두개를 뒤집어 (마우스로 클릭 하면 그림이나온다)
똑같은 문양이 나오면 1점을 얻고 실패하면 다른 팀턴으로 넘어간다.
(틀렸을경우 다시카드가 뒤집힌다.)
(단 맞췄을경우 맞춘 팀이 다시한다.)
(맞춘카드는 사라진다.)
3.어느 한 팀이 5점을 얻었으경우 블루,레드 팀 승리 라고 뜨고 다시 시작이뜬다.
4.다시 시작을 눌렀을 경우 다시 반복한다.
import java.util.*;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class Main extends JFrame{
int size=55;
JPanel p1 = new JPanel();
JPanel p2 = new JPanel();
JLabel red = new JLabel("RED : ");
JLabel red_score = new JLabel("0");
JLabel blue = new JLabel("BLUE : ");
JLabel blue_score = new JLabel("0");
public Main () {
Container c = getContentPane();
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
c.setLayout(new BorderLayout());
/////////p1
c.add(p1,BorderLayout.NORTH);
make_score_panel();
////////p2
c.add(p2,BorderLayout.CENTER);
make_game_panel();
setSize(300,300);
setVisible(true);
}
void make_score_panel() {
p1.setBackground(Color.orange);
p1.add(red);
p1.add(red_score);
red.setForeground(Color.red);
red_score.setForeground(Color.red);
p1.add(blue);
p1.add(blue_score);
blue.setForeground(Color.blue);
blue_score.setForeground(Color.blue);
}
void make_game_panel() {
p2.setBackground(Color.green);
p2.setLayout(null);
int map[][] = new int[4][4];
for(int i=1;i<=8;i++) {
for(int j=1;j<=2;j++) {
JButton button = new JButton(Integer.toString(i));
button.setFont(new Font("Arial",Font.PLAIN,20));
button.setSize(size, size);
button.addActionListener(new MyActionListener());
int flag=0;
while(flag==0) {
int x = (int)(Math.random()*4);
int y = (int)(Math.random()*4);
if(map[x][y]!=0) flag=0;
else {
map[x][y]=i;
button.setLocation(30+x*size,10+y*size);
flag=1;
}
}
p2.add(button);
button.setBackground(Color.white);
button.setForeground(Color.white);
}
}
}
class MyActionListener implements ActionListener{
public void actionPerformed(ActionEvent e) {
JButton b = (JButton)e.getSource();
b.setForeground(Color.black);//보이기
try {
Thread.sleep(3000); //3초기다리기
} catch (InterruptedException e1) {
e1.printStackTrace();
}
b.setForeground(Color.white); //안보이기
//b.setVisible(false);
}
}
public static void main(String[] args) {
new Main();
}
}
import java.util.*;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class Main extends JFrame {
JPanel lp = new JPanel();
MyPanel lp1 = new MyPanel();
JPanel lp2 = new JPanel();
JTextField tf = new JTextField(10);
int chance = 11;
String answers[] = {"coding", "java", "python", "unity","c","soccer","computer","2023","fifa"};
String answer;
JLabel [] la;
JLabel ch = new JLabel("기회 : 11");
JButton input = new JButton("입력");
JButton reset = new JButton("RESET");
public Main() {
setSize(1000,900);
setTitle("행맨");
setVisible(true);
Container c = getContentPane();
c.setLayout(new BorderLayout());
c.add(lp,BorderLayout.NORTH);
c.add(lp1,BorderLayout.CENTER);
c.add(lp2,BorderLayout.SOUTH);
tf.setText("");
lp2.add(tf);
tf.addKeyListener(new MykeyListener());
lp1.setBackground(Color.white);
lp2.add(input);
input.addActionListener(new MyActionListener());
reset.addActionListener(new MyActionListener());
lp2.add(ch);
int n = answers.length;
answer = answers[(int)(Math.random()*n)];
int len =answer.length();
la = new JLabel[len]; //len개의 JLabel 생성
for(int i=0;i<len;i++)
{
la[i]=new JLabel("_");
la[i].setFont(new Font("Arial",Font.PLAIN,30));
lp.add(la[i]);
}
}
public static void main(String[] args) {
new Main();
}
class MyPanel extends JPanel{
public void paintComponent(Graphics g) {
super.paintComponent(g);
if(chance<=10) g.drawLine(200,800,400,800);
if(chance<=9) g.drawLine(250,200,250,800);
if(chance<=8) g.drawLine(250,200,900,200);
if(chance<=7) g.drawLine(900,200,900,350);
if(chance<=6) g.drawOval(850,350,100,100);
if(chance<=5) g.drawLine(900,450,900,600);
if(chance<=4) g.drawLine(900,500,980,450);
if(chance<=3) g.drawLine(820,450,900,500);
if(chance<=2) g.drawLine(900,600,820,650);
if(chance<=1) g.drawLine(900,600,980,650);
if(chance<=0) g.drawLine(850,250,950,250);
}
}
class MykeyListener extends KeyAdapter {
public void keyPressed(KeyEvent e) {
//tf.setText(tf.getText().substring(0,1));
}
}
class MyActionListener implements ActionListener {
public void actionPerformed (ActionEvent e) {
JButton src = (JButton)e.getSource();
if(src.getText().equals("RESET"))
{
System.out.println("reset");
setContentPane(new Main());
}
if(chance==0) {
lp.add(new JLabel("YOU LOSE....."));
input.setEnabled(false);
return ;
}
String in = tf.getText();
boolean flag = false;
for(int i=0;i<answer.length();i++){
if(in.equals(Character.toString(answer.charAt(i)))){
la[i].setText(in);
flag=true;
repaint();
}
}
if(flag==false&& chance>0) {
chance--;
ch.setText("기회 : "+ chance);
lp1.repaint();
}
boolean end = true;
for(int i=0;i<answer.length();i++){
if(!la[i].getText().equals(Character.toString(answer.charAt(i)))) {
end=false;
break;
}
}
if(end==true) {
lp.add(new JLabel("YOU WIN!!!"));
input.setVisible(false);
lp.add(reset);
return ;
}
}
}
}*/
import java.util.*;
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class Main extends JFrame{
JPanel lp = new JPanel(); //가운데
JPanel lp1 = new JPanel(); //아래
String answers[] = {"a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","x","t","u","v","w","x","y","z"};
int chance = 10;
String score = ("점수");
JLabel ch = new JLabel("기회 : 10");
JTextField tf = new JTextField(10);
void makeLabel() {
JLabel la = new JLabel();
//랜덤 텍스트 설정
la.setText(answers[(int)(Math.random()*24)]);
//랜덤 위치 설정
int x = (int)(Math.random()*1000);
la.setLocation(x, 0);
la.setSize(50, 50);
//패널에 추가
lp.add(la);
}
public Main() throws InterruptedException {
setSize(1000,900);
setVisible(true);
Container c = getContentPane();
c.setLayout(new BorderLayout());
c.add(lp,BorderLayout.CENTER);
lp.setLayout(null);
c.add(lp1,BorderLayout.SOUTH);
tf.addKeyListener(new MyKeyListener());
tf.setFocusable(true);
tf.requestFocus();
lp1.add(tf);
lp1.add(ch);
int sec=0;
while(chance!=0) {
sec++;
if(sec%4==0) makeLabel();
for(int i=0; i<lp.getComponentCount();i++) {
JLabel la = (JLabel)lp.getComponent(i);
la.setLocation(la.getX(), la.getY()+100);
if(la.getY()==900) { //맨 아래오면 삭제
lp.remove(la);
chance--;
ch.setText("기회 :"+chance);
lp1.repaint();
}
}
Thread.sleep(500);
repaint();
}
//chance가 0이되어서 게임이 끝났을때
lp.removeAll();
JLabel end = new JLabel("GAME OVER");
lp.add(end);
end.setSize(100, 100);
end.setLocation(500,500);
}
class MyKeyListener extends KeyAdapter {
public void keyPressed(KeyEvent e) {
//enter키가 눌렸을때
if(e.getKeyCode()==10) {
//텍스트필드에 있는 문자열이 lp패널에 있는 라벨들중에 하나일때
System.out.println(tf.getText());
}
//System.out.println(e.getKeyCode());
}
}
public static void main(String[] args) throws InterruptedException {
new Main ();
}
}