成人午夜视频全免费观看高清-秋霞福利视频一区二区三区-国产精品久久久久电影小说-亚洲不卡区三一区三区一区

Java著名代碼網(wǎng)名,Java原名

求java小游戲源代碼

表1. CheckerDrag.java

創(chuàng)新互聯(lián)是一家專業(yè)提供山城企業(yè)網(wǎng)站建設(shè),專注與成都網(wǎng)站設(shè)計(jì)、做網(wǎng)站、HTML5、小程序制作等業(yè)務(wù)。10年已為山城眾多企業(yè)、政府機(jī)構(gòu)等服務(wù)。創(chuàng)新互聯(lián)專業(yè)網(wǎng)站制作公司優(yōu)惠進(jìn)行中。

// CheckerDrag.javaimport java.awt.*;import java.awt.event.*;public class CheckerDrag extends java.applet.Applet{ // Dimension of checkerboard square. // 棋盤上每個小方格的尺寸 final static int SQUAREDIM = 40; // Dimension of checkerboard -- includes black outline. // 棋盤的尺寸 – 包括黑色的輪廓線 final static int BOARDDIM = 8 * SQUAREDIM + 2; // Dimension of checker -- 3/4 the dimension of a square. // 棋子的尺寸 – 方格尺寸的3/4 final static int CHECKERDIM = 3 * SQUAREDIM / 4; // Square colors are dark green or white. // 方格的顏色為深綠色或者白色 final static Color darkGreen = new Color (0, 128, 0); // Dragging flag -- set to true when user presses mouse button over checker // and cleared to false when user releases mouse button. // 拖動標(biāo)記 --當(dāng)用戶在棋子上按下鼠標(biāo)按鍵時設(shè)為true, // 釋放鼠標(biāo)按鍵時設(shè)為false boolean inDrag = false; // Left coordinate of checkerboard's upper-left corner. // 棋盤左上角的左方向坐標(biāo) int boardx; // Top coordinate of checkerboard's upper-left corner. //棋盤左上角的上方向坐標(biāo) int boardy; // Left coordinate of checker rectangle origin (upper-left corner). // 棋子矩形原點(diǎn)(左上角)的左方向坐標(biāo) int ox; // Top coordinate of checker rectangle origin (upper-left corner). // 棋子矩形原點(diǎn)(左上角)的上方向坐標(biāo) int oy; // Left displacement between mouse coordinates at time of press and checker // rectangle origin. // 在按鍵時的鼠標(biāo)坐標(biāo)與棋子矩形原點(diǎn)之間的左方向位移 int relx; // Top displacement between mouse coordinates at time of press and checker // rectangle origin. // 在按鍵時的鼠標(biāo)坐標(biāo)與棋子矩形原點(diǎn)之間的上方向位移 int rely; // Width of applet drawing area. // applet繪圖區(qū)域的寬度 int width; // Height of applet drawing area. // applet繪圖區(qū)域的高度 int height; // Image buffer. // 圖像緩沖 Image imBuffer; // Graphics context associated with image buffer. // 圖像緩沖相關(guān)聯(lián)的圖形背景 Graphics imG; public void init () { // Obtain the size of the applet's drawing area. // 獲取applet繪圖區(qū)域的尺寸 width = getSize ().width; height = getSize ().height; // Create image buffer. // 創(chuàng)建圖像緩沖 imBuffer = createImage (width, height); // Retrieve graphics context associated with image buffer. // 取出圖像緩沖相關(guān)聯(lián)的圖形背景 imG = imBuffer.getGraphics (); // Initialize checkerboard's origin, so that board is centered. // 初始化棋盤的原點(diǎn),使棋盤在屏幕上居中 boardx = (width - BOARDDIM) / 2 + 1; boardy = (height - BOARDDIM) / 2 + 1; // Initialize checker's rectangle's starting origin so that checker is // centered in the square located in the top row and second column from // the left. // 初始化棋子矩形的起始原點(diǎn),使得棋子在第一行左數(shù)第二列的方格里居中 ox = boardx + SQUAREDIM + (SQUAREDIM - CHECKERDIM) / 2 + 1; oy = boardy + (SQUAREDIM - CHECKERDIM) / 2 + 1; // Attach a mouse listener to the applet. That listener listens for // mouse-button press and mouse-button release events. // 向applet添加一個用來監(jiān)聽鼠標(biāo)按鍵的按下和釋放事件的鼠標(biāo)監(jiān)聽器 addMouseListener (new MouseAdapter () { public void mousePressed (MouseEvent e) { // Obtain mouse coordinates at time of press. // 獲取按鍵時的鼠標(biāo)坐標(biāo) int x = e.getX (); int y = e.getY (); // If mouse is over draggable checker at time // of press (i.e., contains (x, y) returns // true), save distance between current mouse // coordinates and draggable checker origin // (which will always be positive) and set drag // flag to true (to indicate drag in progress). // 在按鍵時如果鼠標(biāo)位于可拖動的棋子上方 // (也就是contains (x, y)返回true),則保存當(dāng)前 // 鼠標(biāo)坐標(biāo)與棋子的原點(diǎn)之間的距離(始終為正值)并且 // 將拖動標(biāo)志設(shè)為true(用來表明正處在拖動過程中) if (contains (x, y)) { relx = x - ox; rely = y - oy; inDrag = true; } } boolean contains (int x, int y) { // Calculate center of draggable checker. // 計(jì)算棋子的中心位置 int cox = ox + CHECKERDIM / 2; int coy = oy + CHECKERDIM / 2; // Return true if (x, y) locates with bounds // of draggable checker. CHECKERDIM / 2 is the // radius. // 如果(x, y)仍處于棋子范圍內(nèi)則返回true // CHECKERDIM / 2為半徑 return (cox - x) * (cox - x) + (coy - y) * (coy - y) CHECKERDIM / 2 * CHECKERDIM / 2; } public void mouseReleased (MouseEvent e) { // When mouse is released, clear inDrag (to // indicate no drag in progress) if inDrag is // already set. // 當(dāng)鼠標(biāo)按鍵被釋放時,如果inDrag已經(jīng)為true, // 則將其置為false(用來表明不在拖動過程中) if (inDrag) inDrag = false; } }); // Attach a mouse motion listener to the applet. That listener listens // for mouse drag events. //向applet添加一個用來監(jiān)聽鼠標(biāo)拖動事件的鼠標(biāo)運(yùn)動監(jiān)聽器 addMouseMotionListener (new MouseMotionAdapter () { public void mouseDragged (MouseEvent e) { if (inDrag) { // Calculate draggable checker's new // origin (the upper-left corner of // the checker rectangle). // 計(jì)算棋子新的原點(diǎn)(棋子矩形的左上角) int tmpox = e.getX () - relx; int tmpoy = e.getY () - rely; // If the checker is not being moved // (at least partly) off board, // assign the previously calculated // origin (tmpox, tmpoy) as the // permanent origin (ox, oy), and // redraw the display area (with the // draggable checker at the new // coordinates). // 如果棋子(至少是棋子的一部分)沒有被 // 移出棋盤,則將之前計(jì)算的原點(diǎn) // (tmpox, tmpoy)賦值給永久性的原點(diǎn)(ox, oy), // 并且刷新顯示區(qū)域(此時的棋子已經(jīng)位于新坐標(biāo)上) if (tmpox boardx tmpoy boardy tmpox + CHECKERDIM boardx + BOARDDIM tmpoy + CHECKERDIM boardy + BOARDDIM) { ox = tmpox; oy = tmpoy; repaint (); } } } }); } public void paint (Graphics g) { // Paint the checkerboard over which the checker will be dragged. // 在棋子將要被拖動的位置上繪制棋盤 paintCheckerBoard (imG, boardx, boardy); // Paint the checker that will be dragged. // 繪制即將被拖動的棋子 paintChecker (imG, ox, oy); // Draw contents of image buffer. // 繪制圖像緩沖的內(nèi)容 g.drawImage (imBuffer, 0, 0, this); } void paintChecker (Graphics g, int x, int y) { // Set checker shadow color. // 設(shè)置棋子陰影的顏色 g.setColor (Color.black); // Paint checker shadow. // 繪制棋子的陰影 g.fillOval (x, y, CHECKERDIM, CHECKERDIM); // Set checker color. // 設(shè)置棋子顏色 g.setColor (Color.red); // Paint checker. // 繪制棋子 g.fillOval (x, y, CHECKERDIM - CHECKERDIM / 13, CHECKERDIM - CHECKERDIM / 13); } void paintCheckerBoard (Graphics g, int x, int y) { // Paint checkerboard outline. // 繪制棋盤輪廓線 g.setColor (Color.black); g.drawRect (x, y, 8 * SQUAREDIM + 1, 8 * SQUAREDIM + 1); // Paint checkerboard. // 繪制棋盤 for (int row = 0; row 8; row++) { g.setColor (((row 1) != 0) ? darkGreen : Color.white); for (int col = 0; col 8; col++) { g.fillRect (x + 1 + col * SQUAREDIM, y + 1 + row * SQUAREDIM, SQUAREDIM, SQUAREDIM); g.setColor ((g.getColor () == darkGreen) ? Color.white : darkGreen); } } } // The AWT invokes the update() method in response to the repaint() method // calls that are made as a checker is dragged. The default implementation // of this method, which is inherited from the Container class, clears the // applet's drawing area to the background color prior to calling paint(). // This clearing followed by drawing causes flicker. CheckerDrag overrides // update() to prevent the background from being cleared, which eliminates // the flicker. // AWT調(diào)用了update()方法來響應(yīng)拖動棋子時所調(diào)用的repaint()方法。該方法從 // Container類繼承的默認(rèn)實(shí)現(xiàn)會在調(diào)用paint()之前,將applet的繪圖區(qū)域清除 // 為背景色,這種繪制之后的清除就導(dǎo)致了閃爍。CheckerDrag重寫了update()來 // 防止背景被清除,從而消除了閃爍。 public void update (Graphics g) { paint (g); }}

JAVA代碼

連連看java源代碼

import javax.swing.*;

import java.awt.*;

import java.awt.event.*;

public class lianliankan implements ActionListener

{

JFrame mainFrame; //主面板

Container thisContainer;

JPanel centerPanel,southPanel,northPanel; //子面板

JButton diamondsButton[][] = new JButton[6][5];//游戲按鈕數(shù)組

JButton exitButton,resetButton,newlyButton; //退出,重列,重新開始按鈕

JLabel fractionLable=new JLabel("0"); //分?jǐn)?shù)標(biāo)簽

JButton firstButton,secondButton; //分別記錄兩次被選中的按鈕

int grid[][] = new int[8][7];//儲存游戲按鈕位置

static boolean pressInformation=false; //判斷是否有按鈕被選中

int x0=0,y0=0,x=0,y=0,fristMsg=0,secondMsg=0,validateLV; //游戲按鈕的位置坐標(biāo)

int i,j,k,n;//消除方法控制

public void init(){

mainFrame=new JFrame("JKJ連連看");

thisContainer = mainFrame.getContentPane();

thisContainer.setLayout(new BorderLayout());

centerPanel=new JPanel();

southPanel=new JPanel();

northPanel=new JPanel();

thisContainer.add(centerPanel,"Center");

thisContainer.add(southPanel,"South");

thisContainer.add(northPanel,"North");

centerPanel.setLayout(new GridLayout(6,5));

for(int cols = 0;cols 6;cols++){

for(int rows = 0;rows 5;rows++ ){

diamondsButton[cols][rows]=new JButton(String.valueOf(grid[cols+1][rows+1]));

diamondsButton[cols][rows].addActionListener(this);

centerPanel.add(diamondsButton[cols][rows]);

}

}

exitButton=new JButton("退出");

exitButton.addActionListener(this);

resetButton=new JButton("重列");

resetButton.addActionListener(this);

newlyButton=new JButton("再來一局");

newlyButton.addActionListener(this);

southPanel.add(exitButton);

southPanel.add(resetButton);

southPanel.add(newlyButton);

fractionLable.setText(String.valueOf(Integer.parseInt(fractionLable.getText())));

northPanel.add(fractionLable);

mainFrame.setBounds(280,100,500,450);

mainFrame.setVisible(true);

}

public void randomBuild() {

int randoms,cols,rows;

for(int twins=1;twins=15;twins++) {

randoms=(int)(Math.random()*25+1);

for(int alike=1;alike=2;alike++) {

cols=(int)(Math.random()*6+1);

rows=(int)(Math.random()*5+1);

while(grid[cols][rows]!=0) {

cols=(int)(Math.random()*6+1);

rows=(int)(Math.random()*5+1);

}

this.grid[cols][rows]=randoms;

}

}

}

public void fraction(){

fractionLable.setText(String.valueOf(Integer.parseInt(fractionLable.getText())+100));

}

public void reload() {

int save[] = new int[30];

int n=0,cols,rows;

int grid[][]= new int[8][7];

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

for(int j=0;j=5;j++) {

if(this.grid[i][j]!=0) {

save[n]=this.grid[i][j];

n++;

}

}

}

n=n-1;

this.grid=grid;

while(n=0) {

cols=(int)(Math.random()*6+1);

rows=(int)(Math.random()*5+1);

while(grid[cols][rows]!=0) {

cols=(int)(Math.random()*6+1);

rows=(int)(Math.random()*5+1);

}

this.grid[cols][rows]=save[n];

n--;

}

mainFrame.setVisible(false);

pressInformation=false; //這里一定要將按鈕點(diǎn)擊信息歸為初始

init();

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

for(int j = 0;j 5;j++ ){

if(grid[i+1][j+1]==0)

diamondsButton[i][j].setVisible(false);

}

}

}

public void estimateEven(int placeX,int placeY,JButton bz) {

if(pressInformation==false) {

x=placeX;

y=placeY;

secondMsg=grid[x][y];

secondButton=bz;

pressInformation=true;

}

else {

x0=x;

y0=y;

fristMsg=secondMsg;

firstButton=secondButton;

x=placeX;

y=placeY;

secondMsg=grid[x][y];

secondButton=bz;

if(fristMsg==secondMsg secondButton!=firstButton){

xiao();

}

}

}

public void xiao() { //相同的情況下能不能消去。仔細(xì)分析,不一條條注釋

if((x0==x (y0==y+1||y0==y-1)) || ((x0==x+1||x0==x-1)(y0==y))){ //判斷是否相鄰

remove();

}

else{

for (j=0;j7;j++ ) {

if (grid[x0][j]==0){ //判斷第一個按鈕同行哪個按鈕為空

if (yj) { //如果第二個按鈕的Y坐標(biāo)大于空按鈕的Y坐標(biāo)說明第一按鈕在第二按鈕左邊

for (i=y-1;i=j;i-- ){ //判斷第二按鈕左側(cè)直到第一按鈕中間有沒有按鈕

if (grid[x][i]!=0) {

k=0;

break;

}

else //K=1說明通過了第一次驗(yàn)證

}

if (k==1) {

linePassOne();

}

}

if (yj){ //如果第二個按鈕的Y坐標(biāo)小于空按鈕的Y坐標(biāo)說明第一按鈕在第二按鈕右邊

for (i=y+1;i=j ;i++ ){ //判斷第二按鈕左側(cè)直到第一按鈕中間有沒有按鈕

if (grid[x][i]!=0){

k=0;

break;

}

else

}

if (k==1){

linePassOne();

}

}

if (y==j ) {

linePassOne();

}

}

if (k==2) {

if (x0==x) {

remove();

}

if (x0x) {

for (n=x0;n=x-1;n++ ) {

if (grid[n][j]!=0) {

k=0;

break;

}

if(grid[n][j]==0 n==x-1) {

remove();

}

}

}

if (x0x) {

for (n=x0;n=x+1 ;n-- ) {

if (grid[n][j]!=0) {

k=0;

break;

}

if(grid[n][j]==0 n==x+1) {

remove();

}

}

}

}

}

for (i=0;i8;i++ ) { //列

if (grid[i][y0]==0) {

if (xi) {

for (j=x-1;j=i ;j-- ) {

if (grid[j][y]!=0) {

k=0;

break;

}

else

}

if (k==1) {

rowPassOne();

}

}

if (xi) {

for (j=x+1;j=i;j++ ) {

if (grid[j][y]!=0) {

k=0;

break;

}

else

}

if (k==1) {

rowPassOne();

}

}

if (x==i) {

rowPassOne();

}

}

if (k==2){

if (y0==y) {

remove();

}

if (y0y) {

for (n=y0;n=y-1 ;n++ ) {

if (grid[i][n]!=0) {

k=0;

break;

}

if(grid[i][n]==0 n==y-1) {

remove();

}

}

}

if (y0y) {

for (n=y0;n=y+1 ;n--) {

if (grid[i][n]!=0) {

k=0;

break;

}

if(grid[i][n]==0 n==y+1) {

remove();

}

}

}

}

}

}

}

public void linePassOne(){

if (y0j){ //第一按鈕同行空按鈕在左邊

for (i=y0-1;i=j ;i-- ){ //判斷第一按鈕同左側(cè)空按鈕之間有沒按鈕

if (grid[x0][i]!=0) {

k=0;

break;

}

else //K=2說明通過了第二次驗(yàn)證

}

}

if (y0j){ //第一按鈕同行空按鈕在與第二按鈕之間

for (i=y0+1;i=j ;i++){

if (grid[x0][i]!=0) {

k=0;

break;

}

else

}

}

}

public void rowPassOne(){

if (x0i) {

for (j=x0-1;j=i ;j-- ) {

if (grid[j][y0]!=0) {

k=0;

break;

}

else

}

}

if (x0i) {

for (j=x0+1;j=i ;j++ ) {

if (grid[j][y0]!=0) {

k=0;

break;

}

else

}

}

}

public void remove(){

firstButton.setVisible(false);

secondButton.setVisible(false);

fraction();

pressInformation=false;

k=0;

grid[x0][y0]=0;

grid[x][y]=0;

}

public void actionPerformed(ActionEvent e) {

if(e.getSource()==newlyButton){

int grid[][] = new int[8][7];

this.grid = grid;

randomBuild();

mainFrame.setVisible(false);

pressInformation=false;

init();

}

if(e.getSource()==exitButton)

System.exit(0);

if(e.getSource()==resetButton)

reload();

for(int cols = 0;cols 6;cols++){

for(int rows = 0;rows 5;rows++ ){

if(e.getSource()==diamondsButton[cols][rows])

estimateEven(cols+1,rows+1,diamondsButton[cols][rows]);

}

}

}

public static void main(String[] args) {

lianliankan llk = new lianliankan();

llk.randomBuild();

llk.init();

}

}

//old 998 lines

//new 318 lines

給段最簡單的java代碼 讓我新手看一下

最簡單的java代碼肯定就是這個了,如下:

public class MyFirstApp

{

public static void main(String[] args)

{

System.out.print("Hello world");

}

}

“hello world”就是應(yīng)該是所有學(xué)java的新手看的第一個代碼了。如果是零基礎(chǔ)的新手朋友們可以來我們的java實(shí)驗(yàn)班試聽,有免費(fèi)的試聽課程幫助學(xué)習(xí)java必備基礎(chǔ)知識,有助教老師為零基礎(chǔ)的人提供個人學(xué)習(xí)方案,學(xué)習(xí)完成后有考評團(tuán)進(jìn)行專業(yè)測試,幫助測評學(xué)員是否適合繼續(xù)學(xué)習(xí)java,15天內(nèi)免費(fèi)幫助來報名體驗(yàn)實(shí)驗(yàn)班的新手快速入門java,更好的學(xué)習(xí)java!

java編碼規(guī)范有哪些?

盡量使用完整的英文描述符,采用適用于相關(guān)領(lǐng)域的術(shù)語,采用大小寫混合使名字可讀。

JAVA代碼規(guī)范:

(1)類名首字母應(yīng)該大寫。字段、方法以及對象(句柄)的首字母應(yīng)小寫。對于所有標(biāo)識符,其中包含的所有單詞都應(yīng)緊靠在一起,而且大寫中間單詞的首字母。例如:

ThisIsAClassName

thisIsMethodOrFieldName

若在定義中出現(xiàn)了常數(shù)初始化字符,則大寫static final基本類型標(biāo)識符中的所有字母。這樣便可標(biāo)志出它們屬于編譯期的常數(shù)。Java包(Package)屬于一種特殊情況:它們?nèi)际切懽帜?,即便中間的單詞亦是如此。對于域名擴(kuò)展名稱,如com,org,net或者edu等,全部都應(yīng)小寫(這也是Java1.1和Java1.2的區(qū)別之一)。

(2)為了常規(guī)用途而創(chuàng)建一個類時,請采取"經(jīng)典形式",并包含對下述元素的定義:equals()

hashCode()

toString()

clone()(implement Cloneable)

implement Serializable

(3)對于自己創(chuàng)建的每一個類,都考慮置入一個main(),其中包含了用于測試那個類的代碼。為使用一個項(xiàng)目中的類,我們沒必要刪除測試代碼。若進(jìn)行了任何形式的改動,可方便地返回測試。這些代碼也可作為如何使用類的一個示例使用。

(4)應(yīng)將方法設(shè)計(jì)成簡要的、功能性單元,用它描述和實(shí)現(xiàn)一個不連續(xù)的類接口部分。理想情況下,方法應(yīng)簡明扼要。若長度很大,可考慮通過某種方式將其分割成較短的幾個方法。這樣做也便于類內(nèi)代碼的重復(fù)使用(有些時候,方法必須非常大,但它們?nèi)詰?yīng)只做同樣的一件事情)。

(5)設(shè)計(jì)一個類時,請?jiān)O(shè)身處地為客戶程序員考慮一下(類的使用方法應(yīng)該是非常明確的)。然后,再設(shè)身處地為管理代碼的人考慮一下(預(yù)計(jì)有可能進(jìn)行哪些形式的修改,想想用什么方法可把它們變得更簡單)。

(6)使類盡可能短小精悍,而且只解決一個特定的問題。下面是對類設(shè)計(jì)的一些建議:

一個復(fù)雜的開關(guān)語句:考慮采用"多形"機(jī)制

數(shù)量眾多的方法涉及到類型差別極大的操作:考慮用幾個類來分別實(shí)現(xiàn)

許多成員變量在特征上有很大的差別:考慮使用幾個類

(7)讓一切東西都盡可能地"私有"-private??墒箮斓哪骋徊糠?公共化"(一個方法、類或者一個字段等等),就永遠(yuǎn)不能把它拿出。若強(qiáng)行拿出,就可能破壞其他人現(xiàn)有的代碼,使他們不得不重新編寫和設(shè)計(jì)。若只公布自己必須公布的,就可放心大膽地改變其他任何東西。在多線程環(huán)境中,隱私是特別重要的一個因素-只有private字段才能在非同步使用的情況下受到保護(hù)。

(8)謹(jǐn)惕"巨大對象綜合癥。對一些習(xí)慣于順序編程思維、且初涉OOP領(lǐng)域的新手,往往喜歡先寫一個順序執(zhí)行的程序,再把它嵌入一個或兩個巨大的對象里。根據(jù)編程原理,對象表達(dá)的應(yīng)該是應(yīng)用程序的概念。

幾個Java小游戲代碼

package reduce;

import java.applet.Applet;

import java.applet.AudioClip;

import java.awt.Dimension;

import java.awt.Font;

import java.awt.Toolkit;

import javax.sound.sampled.AudioFileFormat;

import javax.sound.sampled.AudioSystem;

import javax.swing.JFrame;

import javax.swing.JPanel;

import java.awt.Rectangle;

import javax.swing.BorderFactory;

import javax.swing.JButton;

import javax.swing.JOptionPane;

import javax.swing.JSlider;

import javax.swing.JLabel;

import javax.swing.SwingUtilities;

import javax.swing.UIManager;

import javax.swing.event.ChangeEvent;

import javax.swing.event.ChangeListener;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import java.awt.event.KeyAdapter;

import java.awt.event.KeyEvent;

import java.io.File;

import java.util.Vector;

public class Frame extends JFrame implements Runnable {

JPanel contentPane;

JPanel jPanel1 = new JPanel();

JButton jButton1 = new JButton();

JSlider jSlider1 = new JSlider();

JLabel jLabel1 = new JLabel();

JButton jButton2 = new JButton();

JLabel jLabel2 = new JLabel();

int count = 1, rapidity = 80; // count 當(dāng)前進(jìn)行的個數(shù), rapidity 游標(biāo)的位置

int zhengque = 0, cuowu = 0;

int rush[] = { 10 ,20 ,30 }; //游戲每關(guān)的個數(shù) 可以自由添加.列 { 10 ,20 ,30 ,40,50}

int rush_count = 0; //記錄關(guān)數(shù)

char list[] = { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L',

'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y',

'Z', '1', '2', '3', '4', '5', '6', '7', '8', '9' }; //隨機(jī)出現(xiàn)的數(shù)字 可以自由添加

Vector number = new Vector();

String paiduan = "true";

AudioClip Musci_anjian, Music_shibai, Music_chenggong;

public Frame() {

try {

setDefaultCloseOperation(EXIT_ON_CLOSE);

//-----------------聲音文件---------------------

Musci_anjian = Applet.newAudioClip(new File("sounds//anjian.wav")

.toURL());

Music_shibai = Applet.newAudioClip(new File("sounds//shibai.wav")

.toURL());

Music_chenggong = Applet.newAudioClip(new File(

"sounds//chenggong.wav").toURL());

//---------------------------------------

jbInit();

} catch (Exception exception) {

exception.printStackTrace();

}

}

/**

* Component initialization.

*

* @throws java.lang.Exception

*/

private void jbInit() throws Exception {

contentPane = (JPanel) getContentPane();

contentPane.setLayout(null);

setSize(new Dimension(588, 530));

setTitle("Frame Title");

jPanel1.setBorder(BorderFactory.createEtchedBorder());

jPanel1.setBounds(new Rectangle(4, 4, 573, 419));

jPanel1.setLayout(null);

jButton1.setBounds(new Rectangle(277, 442, 89, 31));

jButton1.setText("開始");

jButton1.addActionListener(new Frame1_jButton1_actionAdapter(this));

jSlider1.setBounds(new Rectangle(83, 448, 164, 21));

jSlider1.setMaximum(100);

jSlider1.setMinimum(1);

jSlider1.setValue(50);

jLabel1.setText("速度");

jLabel1.setBounds(new Rectangle(35, 451, 39, 18));

jButton2.setBounds(new Rectangle(408, 442, 89, 31));

jButton2.setText("結(jié)束");

jButton2.addActionListener(new Frame1_jButton2_actionAdapter(this));

jLabel2.setText("第一關(guān):100個");

jLabel2.setBounds(new Rectangle(414, 473, 171, 21));

contentPane.add(jPanel1);

contentPane.add(jButton2);

contentPane.add(jButton1);

contentPane.add(jSlider1);

contentPane.add(jLabel1);

contentPane.add(jLabel2);

this.addKeyListener(new MyListener());

jButton1.addKeyListener(new MyListener());

jSlider1.addKeyListener(new MyListener());

jSlider1.addChangeListener(new ChangeListener() {

public void stateChanged(ChangeEvent e) {

rapidity = jSlider1.getValue();

}

});

}

public void run() {

number.clear();

zhengque = 0;

cuowu = 0;

paiduan = "true";

while (count = rush[rush_count]) {

try {

Thread t = new Thread(new Tthread());

t.start();

count += 1;

Thread.sleep(1000 + (int) (Math.random() * 2000)); // 生產(chǎn)下組停頓時間

// 最快1快.最慢2秒

} catch (InterruptedException e) {

e.printStackTrace();

}

}

while (true) { // 等待最后一個字符消失

if (number.size() == 0) {

break;

}

}

if (zhengque == 0) { // 為了以后相除..如果全部正確或者錯誤就會出現(xiàn)錯誤. 所以..

zhengque = 1;

}

if (cuowu == 0) {

cuowu = 1;

}

if (paiduan.equals("true")) { // 判斷是否是自然結(jié)束

if (zhengque / cuowu = 2) {

JOptionPane.showMessageDialog(null, "恭喜你過關(guān)了");

rush_count += 1; // 自動加1關(guān)

if (rush_count rush.length) {

if (rapidity 10) { // 當(dāng)速度大于10的時候在-5提加速度.怕速度太快

rapidity -= 5; // 速度自動減10毫秒

jSlider1.setValue(rapidity); // 選擇位置

}

Thread t = new Thread(this);

t.start();

} else {

JOptionPane.showMessageDialog(null, "牛B...你通關(guān)了..");

rush_count = 0;

count = 0;

}

} else {

JOptionPane.showMessageDialog(null, "請?jiān)俳釉賱?);

rush_count = 0;

count = 0;

}

} else {

rush_count = 0;

count = 0;

}

}

public void jButton1_actionPerformed(ActionEvent e) {

Thread t = new Thread(this);

t.start();

}

public void jButton2_actionPerformed(ActionEvent e) {

count = rush[rush_count] + 1;

paiduan = "flase";

}

class Tthread implements Runnable {

public void run() {

boolean fo = true;

int Y = 0, X = 0;

JLabel show = new JLabel();

show.setFont(new java.awt.Font("宋體", Font.PLAIN, 33));

jPanel1.add(show);

X = 10 + (int) (Math.random() * 400);

String parameter = list[(int) (Math.random() * list.length)] + "";

Bean bean = new Bean();

bean.setParameter(parameter);

bean.setShow(show);

number.add(bean);

show.setText(parameter);

while (fo) {

// ---------------------數(shù)字下移--------------------

show.setBounds(new Rectangle(X, Y += 2, 33, 33));

try {

Thread.sleep(rapidity);

} catch (InterruptedException e) {

e.printStackTrace();

}

if (Y = 419) {

fo = false;

for (int i = number.size() - 1; i = 0; i--) {

Bean bn = ((Bean) number.get(i));

if (parameter.equalsIgnoreCase(bn.getParameter())) {

cuowu += 1;

jLabel2.setText("正確:" + zhengque + "個,錯誤:" + cuowu

+ "個");

number.removeElementAt(i);

Music_shibai.play();

break;

}

}

}

}

}

}

class MyListener extends KeyAdapter {

public void keyPressed(KeyEvent e) {

String uu = e.getKeyChar() + "";

for (int i = 0; i number.size(); i++) {

Bean bean = ((Bean) number.get(i));

if (uu.equalsIgnoreCase(bean.getParameter())) {

zhengque += 1;

number.removeElementAt(i);

bean.getShow().setVisible(false);

jLabel2.setText("正確:" + zhengque + "個,錯誤:" + cuowu + "個");

Music_chenggong.play();

break;

}

}

Musci_anjian.play();

}

}

public static void main(String[] args) {

try {

UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());

} catch (Exception exception) {

exception.printStackTrace();

}

Frame frame = new Frame();

Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();

Dimension frameSize = frame.getSize();

if (frameSize.height screenSize.height) {

frameSize.height = screenSize.height;

}

if (frameSize.width screenSize.width) {

frameSize.width = screenSize.width;

}

frame.setLocation((screenSize.width - frameSize.width) / 2,

(screenSize.height - frameSize.height) / 2);

frame.setVisible(true);

}

}

class Frame1_jButton2_actionAdapter implements ActionListener {

private Frame adaptee;

Frame1_jButton2_actionAdapter(Frame adaptee) {

this.adaptee = adaptee;

}

public void actionPerformed(ActionEvent e) {

adaptee.jButton2_actionPerformed(e);

}

}

class Frame1_jButton1_actionAdapter implements ActionListener {

private Frame adaptee;

Frame1_jButton1_actionAdapter(Frame adaptee) {

this.adaptee = adaptee;

}

public void actionPerformed(ActionEvent e) {

adaptee.jButton1_actionPerformed(e);

}

}

class Bean {

String parameter = null;

JLabel show = null;

public JLabel getShow() {

return show;

}

public void setShow(JLabel show) {

this.show = show;

}

public String getParameter() {

return parameter;

}

public void setParameter(String parameter) {

this.parameter = parameter;

}

}

我只有一個打字母小游戲

java設(shè)計(jì)微信賬號類,微信號,手機(jī)號,昵稱怎么寫

1、首先打開《java》這款軟件。

2、其次輸入個人賬號密碼點(diǎn)擊登錄。

3、最后在軟件中輸入微信賬號類,微信號。手機(jī)號。昵稱點(diǎn)擊編寫即可。

本文題目:Java著名代碼網(wǎng)名,Java原名
標(biāo)題網(wǎng)址:http://jinyejixie.com/article12/hsiogc.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供外貿(mào)網(wǎng)站建設(shè)、品牌網(wǎng)站建設(shè)動態(tài)網(wǎng)站、全網(wǎng)營銷推廣自適應(yīng)網(wǎng)站、電子商務(wù)

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

成都定制網(wǎng)站網(wǎng)頁設(shè)計(jì)
固安县| 调兵山市| 左云县| 营山县| 会东县| 崇信县| 临城县| 霍城县| 霍城县| 岐山县| 宜州市| 襄樊市| 浑源县| 濮阳县| 抚宁县| 恩施市| 和林格尔县| 封开县| 祁连县| 秦皇岛市| 菏泽市| 安塞县| 辽宁省| 清丰县| 于田县| 合水县| 黔东| 彩票| 香港 | 且末县| 乐至县| 马关县| 久治县| 三原县| 洛隆县| 勐海县| 雷波县| 云安县| 德安县| 西贡区| 封开县|