Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.*;
- import java.awt.event.*;
- import javax.swing.*;
- public class DancingWithTheCriminals
- {
- static JFrame frm=new JFrame("犯人在跳舞");
- static JPanel palPlayers[]=new JPanel[8],
- palSkill[]=new JPanel[4];
- static JButton btnStart=new JButton("Start"),
- btnScore=new JButton("Score"),
- btnExit=new JButton("Exit"),
- btnYes=new JButton("YES"),
- btnNo=new JButton("NO"),
- btnBack=new JButton("Back"),
- btnPageup=new JButton(),
- btnPagedown=new JButton(),
- btnSkip=new JButton("Skip"),
- btnReady=new JButton("Ready?"),
- btnGo=new JButton("GO!"),
- btnSkipYes=new JButton("YES"),
- btnSkipNo=new JButton("NO"),
- btnOK=new JButton("OK");
- static JLabel labTutorial=new JLabel(),
- labSequence[]=new JLabel[8],
- labRound=new JLabel("Round",JLabel.CENTER),
- labCardOut=new JLabel(),
- labCards[]=new JLabel[32],
- labOK=new JLabel("OK",JLabel.CENTER),
- labSkill[]=new JLabel[4];
- static JDialog dlgExit=new JDialog(frm,"Exit",true),
- dlgSkip=new JDialog(frm,"Skip",true);
- static ImageIcon ImgTutorial[]=new ImageIcon[6];
- static Container cp=frm.getContentPane();
- static CardLayout card=new CardLayout();
- static int index=0, //當前顯示的圖
- sequence=0; //顯示當前玩家
- static boolean cardChoose[]=new boolean[4], //判斷卡片是否被選取
- cardUsed[]=new boolean[4], //判斷卡片是否已使用
- OKClicked=false; //判斷OK按鈕是否按下
- public static void main(String args[])
- {
- JPanel palMain=new JPanel(),
- palExit=new JPanel(),
- palScore=new JPanel(),
- palTutorial=new JPanel(),
- palButton=new JPanel(),
- palSkip=new JPanel(),
- palGame=new JPanel(),
- palGameTop=new JPanel(),
- palGameCenter=new JPanel(),
- palGameBottom=new JPanel(),
- palOK=new JPanel(); //****//
- JLabel labBackground=new JLabel(),
- labMainTitle=new JLabel("Title",JLabel.CENTER),
- labAskExit=new JLabel("Are You Sure?",JLabel.CENTER),
- labScoreTitle=new JLabel("Score",JLabel.CENTER),
- labTutorialTitle=new JLabel("Tutorial",JLabel.CENTER),
- labAskSkip=new JLabel("Are You Sure?",JLabel.CENTER),
- labPlayer=new JLabel();
- Font fontS=new Font("Segoe Script",Font.ITALIC+Font.BOLD,96),
- fontSs=new Font("Segoe Script",Font.ITALIC+Font.BOLD,48),
- fontS2=new Font("SketchFlow Print",Font.BOLD,30),
- fontK=new Font("Kristen ITC",Font.BOLD,45),
- fontKs=new Font("Kristen ITC",Font.BOLD,35),
- fontKss=new Font("Kristen ITC",Font.BOLD,25);
- ImageIcon Imgbg=new ImageIcon("image/Background.jpg"),
- ImgPgUp=new ImageIcon("image/PageUp.jpg"),
- ImgPgDn=new ImageIcon("image/PageDown.jpg");
- //-----------------------------------------------------------------------------------------------------
- //設定初值
- ImgTutorial[0]=new ImageIcon("image/Tutorial0.jpg");
- ImgTutorial[1]=new ImageIcon("image/Tutorial1.jpg");
- ImgTutorial[2]=new ImageIcon("image/Tutorial2.jpg");
- ImgTutorial[3]=new ImageIcon("image/Tutorial3.jpg");
- ImgTutorial[4]=new ImageIcon("image/Tutorial4.jpg");
- ImgTutorial[5]=new ImageIcon("image/Tutorial5.jpg");
- for(int k=0;k<4;k++)
- {
- cardChoose[k]=false;
- }
- //-----------------------------------------------------------------------------------------------------
- //視窗設置
- frm.setSize(1200,750);
- frm.setLocationRelativeTo(null);
- frm.setResizable(false);
- frm.setVisible(true);
- frm.setLayout(null);
- //Container設置
- cp.setLayout(card);
- ((JPanel)cp).setOpaque(false);
- //-----------------------------------------------------------------------------------------------------
- //背景
- labBackground.setIcon(Imgbg);
- labBackground.setBounds(0,0,1200,750);
- //add
- frm.getLayeredPane().add(labBackground, new Integer(Integer.MIN_VALUE));
- //-----------------------------------------------------------------------------------------------------
- //主畫面
- palMain.setLayout(null);
- palMain.setBounds(0,0,1200,750);
- palMain.setOpaque(false); //將panel設為透明化
- //標題
- labMainTitle.setFont(fontS);
- labMainTitle.setBounds(150,50,900,250);
- //labMainTitle.setForeground(Color.orange); //設定字型顏色
- //Start按鈕
- btnStart.setFont(fontKs);
- btnStart.setBounds(450,460,300,60);
- btnStart.setBorderPainted(true); //設定按鈕去邊框
- btnStart.setContentAreaFilled(false); //設定按鈕背景透明
- //Score按鈕
- btnScore.setFont(fontKs);
- btnScore.setBounds(450,530,300,60);
- btnScore.setBorderPainted(false);
- btnScore.setContentAreaFilled(false);
- //Eixt按鈕
- btnExit.setFont(fontKs);
- btnExit.setBounds(450,600,300,60);
- btnExit.setBorderPainted(false);
- btnExit.setContentAreaFilled(false);
- //add
- palMain.add(labMainTitle);
- palMain.add(btnStart);
- palMain.add(btnScore);
- palMain.add(btnExit);
- cp.add(palMain,"Main");
- //-----------------------------------------------------------------------------------------------------
- //成績畫面
- palScore.setLayout(null);
- palScore.setBounds(0,0,1200,750);
- palScore.setOpaque(false);
- //標題
- labScoreTitle.setFont(fontSs);
- labScoreTitle.setBounds(300,50,600,50);
- //回上一頁按鈕
- btnBack.setBounds(500,600,200,70);
- btnBack.setFont(fontKs);
- btnBack.setContentAreaFilled(false);
- //add
- palScore.add(labScoreTitle);
- palScore.add(btnBack);
- cp.add(palScore,"Score");
- //-----------------------------------------------------------------------------------------------------
- //簡介畫面
- palTutorial.setLayout(null);
- palTutorial.setBounds(0,0,1200,750);
- palTutorial.setOpaque(false);
- //標題
- labTutorialTitle.setFont(fontSs);
- labTutorialTitle.setBounds(300,50,600,50);
- //內容
- labTutorial.setOpaque(true);
- labTutorial.setBounds(150,130,900,450);
- labTutorial.setIcon(ImgTutorial[0]);
- //上一頁按鈕
- btnPageup.setIcon(ImgPgUp);
- btnPageup.setBounds(35,300,80,80);
- btnPageup.setVisible(false);
- btnPageup.setBorderPainted(false);
- btnPageup.setContentAreaFilled(false);
- //下一頁按鈕
- btnPagedown.setIcon(ImgPgDn);
- btnPagedown.setBounds(1085,300,80,80);
- btnPagedown.setBorderPainted(false);
- btnPagedown.setContentAreaFilled(false);
- //Skip按鈕
- btnSkip.setFont(fontKs);
- btnSkip.setBounds(950,25,150,60);
- btnSkip.setBorderPainted(false);
- btnSkip.setContentAreaFilled(false);
- //遊戲開始按鈕
- //按鈕面板
- palButton.setLayout(null);
- palButton.setBounds(500,600,200,90);
- palButton.setOpaque(false);
- //Ready按鈕
- btnReady.setFont(fontKs);
- btnReady.setBounds(0,20,200,70);
- btnReady.setContentAreaFilled(false);
- btnReady.setVisible(false);
- //Go按鈕
- btnGo.setFont(fontKs);
- btnGo.setBounds(0,20,200,70);
- btnGo.setContentAreaFilled(false);
- btnGo.setVisible(false);
- //add
- palButton.add(btnReady);
- palButton.add(btnGo);
- palTutorial.add(labTutorialTitle);
- palTutorial.add(labTutorial);
- palTutorial.add(btnSkip);
- palTutorial.add(btnPageup);
- palTutorial.add(btnPagedown);
- palTutorial.add(palButton);
- cp.add(palTutorial,"Tutorial");
- //-----------------------------------------------------------------------------------------------------
- //遊戲畫面
- palGame.setLayout(null);
- palGame.setBounds(0,0,1200,750);
- palGame.setOpaque(false);
- //Top
- palGameTop.setLayout(null);
- palGameTop.setBounds(0,0,1200,100);
- palGameTop.setOpaque(false);
- //回合數
- labRound.setBounds(0,15,250,50);
- labRound.setFont(fontKss);
- labRound.setOpaque(true);
- labRound.setBackground(Color.white);
- //出牌順序&玩家頭像們
- for(int k=0;k<8;k++)
- {
- palPlayers[k]=new JPanel();
- palPlayers[k].setLayout(null);
- palPlayers[k].setBounds(570+75*k,15,70,90);
- if(k==0)
- {
- palPlayers[k].setBackground(Color.orange);
- }
- else
- {
- palPlayers[k].setBackground(Color.white);
- }
- labSequence[k]=new JLabel();
- labSequence[k].setBounds(0,0,70,70);
- labSequence[k].setOpaque(true);
- labSequence[k].setBackground(Color.pink);
- }
- //Center
- palGameCenter.setBounds(0,150,1200,300);
- palGameCenter.setOpaque(false);
- //出牌區
- labCardOut.setBounds(450,100,150,180);
- labCardOut.setFont(fontS);
- labCardOut.setOpaque(false);
- //Bottom
- palGameBottom.setLayout(null);
- palGameBottom.setBounds(0,450,1200,300);
- palGameBottom.setOpaque(false);
- //所有&所持卡牌
- for(int k=0;k<4;k++)
- {
- labCards[k]=new JLabel();
- labCards[k].setBounds(15*(k+1)+150*k,55,150,180);
- labCards[k].setOpaque(true);
- labCards[k].setBackground(Color.green);
- }
- //卡牌功能
- for(int k=0;k<4;k++)
- {
- palSkill[k]=new JPanel();
- palSkill[k].setLayout(null);
- palSkill[k].setVisible(false);
- palSkill[k].setBounds(15*(k+1)+150*k,355,150,150);
- palSkill[k].setBackground(Color.yellow);
- labSkill[k]=new JLabel();
- labSkill[k].setBounds(10,10,130,130);
- labSkill[k].setOpaque(true);
- labSkill[k].setBackground(Color.pink);
- }
- //確定按鈕
- palOK.setLayout(null);
- palOK.setBounds(800,100,100,100);
- palOK.setOpaque(false);
- btnOK.setBounds(0,0,100,100);
- btnOK.setFont(fontKs);
- btnOK.setContentAreaFilled(false);
- btnOK.setVisible(false);
- labOK.setBounds(800,100,100,100);
- labOK.setFont(fontKs);
- labOK.setForeground(Color.red);
- //自己的頭像
- labPlayer.setBounds(1025,75,150,150);
- labPlayer.setOpaque(true);
- labPlayer.setBackground(Color.pink);
- //add
- palGameTop.add(labRound);
- for(int k=0;k<8;k++)
- {
- palPlayers[k].add(labSequence[k]);
- palGameTop.add(palPlayers[k]);
- }
- palGameCenter.add(labCardOut);
- palOK.add(btnOK);
- for(int k=0;k<4;k++)
- {
- palGameBottom.add(labCards[k]);
- }
- palGameBottom.add(labPlayer);
- palGameBottom.add(labOK);
- palGameBottom.add(palOK);
- for(int k=0;k<4;k++)
- {
- palSkill[k].add(labSkill[k]);
- palGame.add(palSkill[k]);
- }
- palGame.add(palGameTop);
- palGame.add(palGameCenter);
- palGame.add(palGameBottom);
- cp.add(palGame,"Game");
- //-----------------------------------------------------------------------------------------------------
- //其他畫面
- //離開遊戲
- //對話框
- dlgExit.setLayout(null);
- dlgExit.setSize(600,300);
- dlgExit.setLocationRelativeTo(null);
- dlgExit.setVisible(false);
- dlgExit.setResizable(false);
- //面板
- palExit.setLayout(null);
- palExit.setBounds(0,0,600,300);
- //詢問標籤
- labAskExit.setBounds(100,50,400,50);
- labAskExit.setFont(fontK);
- //按鈕
- btnYes.setBounds(100,180,150,50);
- btnYes.setFont(fontKs);
- btnYes.setContentAreaFilled(false);
- btnNo.setBounds(350,180,150,50);
- btnNo.setFont(fontKs);
- btnNo.setContentAreaFilled(false);
- //add
- palExit.add(labAskExit);
- palExit.add(btnYes);
- palExit.add(btnNo);
- dlgExit.add(palExit);
- //跳過教學
- //對話框
- dlgSkip.setLayout(null);
- dlgSkip.setSize(600,300);
- dlgSkip.setLocationRelativeTo(null);
- dlgSkip.setVisible(false);
- dlgSkip.setResizable(false);
- //面板
- palSkip.setLayout(null);
- palSkip.setBounds(0,0,600,300);
- //詢問標籤
- labAskSkip.setBounds(100,50,400,50);
- labAskSkip.setFont(fontK);
- //按鈕
- btnSkipYes.setBounds(100,180,150,50);
- btnSkipYes.setFont(fontKs);
- btnSkipYes.setContentAreaFilled(false);
- btnSkipNo.setBounds(350,180,150,50);
- btnSkipNo.setFont(fontKs);
- btnSkipNo.setContentAreaFilled(false);
- //add
- palSkip.add(labAskSkip);
- palSkip.add(btnSkipYes);
- palSkip.add(btnSkipNo);
- dlgSkip.add(palSkip);
- //-----------------------------------------------------------------------------------------------------
- //Listener設定
- frm.addWindowListener(new winClose());
- btnYes.addActionListener(new winClose());
- btnNo.addActionListener(new winClose());
- btnPageup.addActionListener(new imageChange());
- btnPagedown.addActionListener(new imageChange());
- btnStart.addMouseListener(new btnSelect());
- btnScore.addMouseListener(new btnSelect());
- btnExit.addMouseListener(new btnSelect());
- btnBack.addMouseListener(new btnSelect());
- btnSkip.addMouseListener(new btnSelect());
- btnSkipYes.addMouseListener(new btnSelect());
- btnSkipNo.addMouseListener(new btnSelect());
- btnReady.addMouseListener(new btnSelect());
- btnGo.addMouseListener(new btnSelect());
- btnOK.addMouseListener(new btnSelect());
- for(int k=0;k<4;k++)
- {
- labCards[k].addMouseListener(new Cards());
- }
- //-----------------------------------------------------------------------------------------------------
- card.show(cp,"Main");
- }
- static class btnSelect extends MouseAdapter //按鈕選擇
- {
- public void mouseEntered(MouseEvent e)
- {
- JButton btn=(JButton)e.getSource();
- if(btn==btnStart)
- {
- btnStart.setBorderPainted(true);
- btnScore.setBorderPainted(false);
- btnExit.setBorderPainted(false);
- }
- if(btn==btnScore)
- {
- btnScore.setBorderPainted(true);
- btnStart.setBorderPainted(false);
- btnExit.setBorderPainted(false);
- }
- if(btn==btnExit)
- {
- btnExit.setBorderPainted(true);
- btnStart.setBorderPainted(false);
- btnScore.setBorderPainted(false);
- }
- if(btn==btnSkip)
- {
- btnSkip.setBorderPainted(true);
- }
- if(btn==btnReady)
- {
- btnReady.setVisible(false);
- btnGo.setVisible(true);
- }
- }
- public void mouseExited(MouseEvent e)
- {
- JButton btn=(JButton)e.getSource();
- if(btn==btnSkip)
- {
- btnSkip.setBorderPainted(false);
- }
- if(btn==btnGo)
- {
- btnReady.setVisible(true);
- btnGo.setVisible(false);
- }
- }
- public void mouseClicked(MouseEvent e)
- {
- JButton btn=(JButton)e.getSource();
- if(btn==btnStart)
- {
- card.show(cp,"Tutorial");
- }
- if(btn==btnScore)
- {
- card.show(cp,"Score");
- }
- if(btn==btnBack)
- {
- card.show(cp,"Main");
- }
- if(btn==btnExit)
- {
- dlgExit.setVisible(true);
- }
- if(btn==btnSkip)
- {
- dlgSkip.setVisible(true);
- }
- if(btn==btnSkipYes)
- {
- dlgSkip.setVisible(false);
- card.show(cp,"Game");
- }
- if(btn==btnSkipNo)
- {
- dlgSkip.setVisible(false);
- }
- if(btn==btnGo)
- {
- card.show(cp,"Game");
- }
- if(btn==btnOK)
- {
- if(cardChoose[0]==true)
- {
- labCards[0].setBounds(15,55,150,180);
- labCards[0].setBackground(Color.black);
- labCardOut.setOpaque(true);
- labCardOut.setBackground(Color.white);
- labCardOut.setText("0");
- }
- if(cardChoose[1]==true)
- {
- labCards[1].setBounds(15*2+150,55,150,180);
- labCards[1].setBackground(Color.black);
- labCardOut.setOpaque(true);
- labCardOut.setBackground(Color.white);
- labCardOut.setText("1");
- }
- if(cardChoose[2]==true)
- {
- labCards[2].setBounds(15*3+150*2,55,150,180);
- labCards[2].setBackground(Color.black);
- labCardOut.setOpaque(true);
- labCardOut.setBackground(Color.white);
- labCardOut.setText("2");
- }
- if(cardChoose[3]==true)
- {
- labCards[3].setBounds(15*4+150*3,55,150,180);
- labCards[3].setBackground(Color.black);
- labCardOut.setOpaque(true);
- labCardOut.setBackground(Color.white);
- labCardOut.setText("3");
- }
- OKClicked=true;
- btnOK.setVisible(false);
- labOK.setVisible(true);
- //palPlayers[sequence%8].setBackground(Color.white);
- //sequence++;
- //palPlayers[sequence%8].setBackground(Color.orange);
- }
- }
- }
- static class imageChange implements ActionListener //遊戲教學換頁
- {
- public void actionPerformed(ActionEvent e)
- {
- JButton btn=(JButton)e.getSource();
- if(btn==btnPageup&&index>0)
- {
- index--;
- }
- if(btn==btnPagedown&&index<5)
- {
- index++;
- }
- if(index==0)
- {
- btnPageup.setVisible(false);
- }
- else
- {
- btnPageup.setVisible(true);
- }
- if(index==5)
- {
- btnPagedown.setVisible(false);
- btnReady.setVisible(true);
- btnSkip.setVisible(false);
- }
- else
- {
- btnPagedown.setVisible(true);
- btnReady.setVisible(false);
- btnSkip.setVisible(true);
- }
- labTutorial.setIcon(ImgTutorial[index]);
- }
- }
- static class Cards extends MouseAdapter //卡片選擇
- {
- public void mouseEntered(MouseEvent e)
- {
- JLabel lab=(JLabel)e.getSource();
- if(lab==labCards[0])
- {
- palSkill[0].setVisible(true);
- }
- if(lab==labCards[1])
- {
- palSkill[1].setVisible(true);
- }
- if(lab==labCards[2])
- {
- palSkill[2].setVisible(true);
- }
- if(lab==labCards[3])
- {
- palSkill[3].setVisible(true);
- }
- }
- public void mouseExited(MouseEvent e)
- {
- JLabel lab=(JLabel)e.getSource();
- if(lab==labCards[0])
- {
- palSkill[0].setVisible(false);
- }
- if(lab==labCards[1])
- {
- palSkill[1].setVisible(false);
- }
- if(lab==labCards[2])
- {
- palSkill[2].setVisible(false);
- }
- if(lab==labCards[3])
- {
- palSkill[3].setVisible(false);
- }
- }
- public void mouseClicked(MouseEvent e)
- {
- JLabel lab=(JLabel)e.getSource();
- if(OKClicked==false)
- {
- if(lab==labCards[0])
- {
- labCards[0].setBounds(15*1,40,150,180);
- if(cardChoose[0]==false)
- {
- cardChoose[0]=true;
- btnOK.setVisible(true);
- labOK.setVisible(false);
- }
- else
- {
- cardChoose[0]=false;
- labCards[0].setBounds(15,55,150,180);
- btnOK.setVisible(false);
- labOK.setVisible(true);
- }
- cardChoose[1]=cardChoose[2]=cardChoose[3]=false;
- labCards[1].setBounds(15*2+150*1,55,150,180);
- labCards[2].setBounds(15*3+150*2,55,150,180);
- labCards[3].setBounds(15*4+150*3,55,150,180);
- }
- if(lab==labCards[1])
- {
- labCards[1].setBounds(15*2+150*1,40,150,180);
- if(cardChoose[1]==false)
- {
- cardChoose[1]=true;
- btnOK.setVisible(true);
- labOK.setVisible(false);
- }
- else
- {
- cardChoose[1]=false;
- labCards[1].setBounds(15*2+150*1,55,150,180);
- btnOK.setVisible(false);
- labOK.setVisible(true);
- }
- cardChoose[0]=cardChoose[2]=cardChoose[3]=false;
- labCards[0].setBounds(15,55,150,180);
- labCards[2].setBounds(15*3+150*2,55,150,180);
- labCards[3].setBounds(15*4+150*3,55,150,180);
- }
- if(lab==labCards[2])
- {
- labCards[2].setBounds(15*3+150*2,40,150,180);
- if(cardChoose[2]==false)
- {
- cardChoose[2]=true;
- btnOK.setVisible(true);
- labOK.setVisible(false);
- }
- else
- {
- cardChoose[2]=false;
- labCards[2].setBounds(15*3+150*2,55,150,180);
- btnOK.setVisible(false);
- labOK.setVisible(true);
- }
- cardChoose[1]=cardChoose[0]=cardChoose[3]=false;
- labCards[1].setBounds(15*2+150*1,55,150,180);
- labCards[0].setBounds(15,55,150,180);
- labCards[3].setBounds(15*4+150*3,55,150,180);
- }
- if(lab==labCards[3])
- {
- labCards[3].setBounds(15*4+150*3,40,150,180);
- if(cardChoose[3]==false)
- {
- cardChoose[3]=true;
- btnOK.setVisible(true);
- labOK.setVisible(false);
- }
- else
- {
- cardChoose[3]=false;
- labCards[3].setBounds(15*4+150*3,55,150,180);
- btnOK.setVisible(false);
- labOK.setVisible(true);
- }
- cardChoose[1]=cardChoose[2]=cardChoose[0]=false;
- labCards[1].setBounds(15*2+150*1,55,150,180);
- labCards[2].setBounds(15*3+150*2,55,150,180);
- labCards[0].setBounds(15,55,150,180);
- }
- }
- }
- }
- static class winClose extends WindowAdapter implements ActionListener //關閉視窗
- {
- public void windowClosing(WindowEvent e)
- {
- frm.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
- }
- public void actionPerformed(ActionEvent e)
- {
- JButton btn=(JButton)e.getSource();
- if(btn==btnYes)
- {
- frm.dispose();
- }
- if(btn==btnNo)
- {
- dlgExit.setVisible(false);
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment