大連模板網(wǎng)站制作公司廣州網(wǎng)絡(luò)推廣外包
(以下內(nèi)容全部來自上述課程)
1.美化界面
private void initImage() {//路徑分兩種://1.絕對(duì)路徑:從盤符開始寫的路徑 D:\\aaa\\bbb\\ccc.jpg//2.相對(duì)路徑:從當(dāng)前項(xiàng)目開始寫的路徑 aaa\\bbb\\ccc.jpg//添加圖片的時(shí)候,就需要按照二維數(shù)組中管理的數(shù)據(jù)添加圖片//外循環(huán)----把內(nèi)循環(huán)的代碼重復(fù)執(zhí)行4次for (int i = 0; i < 4; i++) {//內(nèi)循環(huán)----表示在一行中放4個(gè)圖片for (int j = 0; j < 4; j++) {//獲取二維數(shù)組中每個(gè)索引對(duì)應(yīng)的數(shù)字int number = arr[i][j];//創(chuàng)建一個(gè)圖片ImageIcon對(duì)象 參數(shù):圖片的路徑(沒加圖片,意思一下得了)//這里的圖片最好命名為數(shù)字ImageIcon icon = new ImageIcon("image\\background\\"+number+".jpg");//創(chuàng)建一個(gè)JLabel對(duì)象(管理容器)JLabel jLabel = new JLabel(icon);//設(shè)置圖片的位置jLabel.setBounds(105*j+83,105*i+134,105,105);//給圖片添加邊框jLabel.setBorder(new BevelBorder(1));//把JLabel對(duì)象添加到界面中this.getContentPane().add(jLabel);//添加一次后number自增1,表示下一次加載后面一張圖片}}//細(xì)節(jié)://先加載的圖片在上方,后加載的圖片在下方//添加背景圖片ImageIcon background = new ImageIcon("image\\background\\background.jpg");JLabel backgroundJLabel = new JLabel(background);backgroundJLabel.setBounds(40,40,508,560);//把背景圖片添加到界面中this.getContentPane().add(backgroundJLabel);}
2.上下移動(dòng)
上移動(dòng):
向上移動(dòng)實(shí)際上就是把空白方塊下方的圖片上移。
(新加代碼,非完整)
public class GameJFrame extends javax.swing.JFrame implements KeyListener {//記錄空白方塊的位置int x = 0;int y = 0;private void initImage() {//清空原本已經(jīng)出現(xiàn)的圖片this.getContentPane().removeAll();}private void initJFrame() {//給整個(gè)界面添加鍵盤監(jiān)聽this.addKeyListener(this);}@Overridepublic void keyTyped(KeyEvent e) {}@Overridepublic void keyPressed(KeyEvent e) {}@Overridepublic void keyReleased(KeyEvent e) {//對(duì)應(yīng)鍵盤上的上下左右鍵//獲取鍵盤上的鍵碼int keyCode = e.getKeyCode();System.out.println(keyCode);if (keyCode == 38) {System.out.println("上");if (x == 3) {//已經(jīng)到底了,什么都不做return;}//邏輯://把空白方塊下方的數(shù)字往上移動(dòng)//x,y 表示空白方塊//x+1,y 表示空白方塊上的位置//把x+1,y位置上的數(shù)字賦值給x,y位置arr[x][y] = arr[x+1][y];arr[x+1][y] = 0;//空白方塊的位置發(fā)生了改變x++;//重新初始化圖片initImage();} else if (keyCode == 40) {if (x == 0) {//已經(jīng)到底了,什么都不做return;}System.out.println("下");arr[x][y] = arr[x-1][y];arr[x-1][y] = 0;//空白方塊的位置發(fā)生了改變x--;//重新初始化圖片initImage();} else if (keyCode == 37) {if (y == 3) {//已經(jīng)到底了,什么都不做return;}System.out.println("左");arr[x][y] = arr[x][y+1];arr[x][y+1] = 0;//空白方塊的位置發(fā)生了改變y++;//重新初始化圖片initImage();} else if (keyCode == 39) {if (y == 0) {//已經(jīng)到底了,什么都不做return;}System.out.println("右");arr[x][y] = arr[x][y-1];arr[x][y-1] = 0;//空白方塊的位置發(fā)生了改變y--;//重新初始化圖片initImage();} else {System.out.println("其他");}}
}
3.查看完整圖片的功能
按住A不松開,顯示完整圖片
松開A顯示隨機(jī)打亂的圖片
(新加代碼,非完整)
//定義一個(gè)變量,記錄當(dāng)前展示圖片的路徑String path = "";private void initImage() {//清空原本已經(jīng)出現(xiàn)的圖片this.getContentPane().removeAll();//..........//刷新界面this.getContentPane().repaint();}//監(jiān)聽上一步添加過了,直接用,修改方法即可//按下不松,一直觸發(fā)@Overridepublic void keyPressed(KeyEvent e) {int code = e.getKeyCode();if (code == 65) {//把界面中的所有圖片全部刪除this.getContentPane().removeAll();//加載第一張完整的圖片JLabel allJLabel = new JLabel(new ImageIcon(path+"all.jpg"));//設(shè)置圖片的位置allJLabel.setBounds(83,134,420,420);//把圖片添加到界面中this.getContentPane().add(allJLabel);//加載背景圖片ImageIcon background = new ImageIcon("image\\background\\background.jpg");JLabel backgroundJLabel = new JLabel(background);backgroundJLabel.setBounds(40,40,508,560);//把背景圖片添加到界面中this.getContentPane().add(backgroundJLabel);//刷新界面this.getContentPane().repaint();}}@Overridepublic void keyReleased(KeyEvent e) {//...........} else if( keyCode == 65){initImage();}}
}
4.作弊碼
按一下W,直接勝利
keyReleased方法體中添加:
(新加代碼,非完整)
else if (keyCode == 87) {arr = new int[][]{{1,2,3,4},{5,6,7,8},{9,10,11,12},{13,14,15,0}};initImage();
5.判斷勝利
其實(shí)就是判斷二維數(shù)組中的數(shù)字是否按照順序進(jìn)行排列
如果按照順序進(jìn)行排列的,那么顯示勝利的圖片
實(shí)現(xiàn)步驟:
- 定義一個(gè)正確的二維數(shù)組win
- 在加載圖片之前,先判斷一下二維數(shù)組中的數(shù)字跟win數(shù)組中是否相同
- 如果相同展示正確圖標(biāo)
- 如果不同則不展示正確圖標(biāo)
(新加代碼,非完整)
//定義一個(gè)二維數(shù)組,存儲(chǔ)正確的數(shù)據(jù)int[][] win = {{1,2,3,4},{5,6,7,8},{9,10,11,12},{13,14,15,0}};private void initImage() {
//....//判斷游戲是否結(jié)束if (isWin()) {//顯示勝利的圖片ImageIcon winIcon = new ImageIcon("image\\win.jpg");JLabel winJLabel = new JLabel(winIcon);winJLabel.setBounds(203,283,197,73);this.getContentPane().add(winJLabel);}//........
}public void keyReleased(KeyEvent e) {//判斷游戲是否勝利,如果勝利,此方法直接結(jié)束if (isWin()) {//1.返回結(jié)果//2.結(jié)束方法return;
//........}
}//判斷游戲是否勝利public boolean isWin(){for (int i = 0; i < arr.length; i++) {for (int j = 0; j < arr[i].length; j++) {if (arr[i][j] != win[i][j]){return false;}}}return true;}
6.計(jì)步功能
//定義變量,記錄步數(shù)int step = 0;private void initImage() {
//........
JLabel stepCount = new JLabel("步數(shù):"+step);stepCount.setBounds(50,30,100,20);this.getContentPane().add(stepCount);//........
}// keyReleased 截止到現(xiàn)在的完整代碼@Overridepublic void keyReleased(KeyEvent e) {//判斷游戲是否勝利,如果勝利,此方法直接結(jié)束if (isWin()) {//1.返回結(jié)果//2.結(jié)束方法return;}//對(duì)應(yīng)鍵盤上的上下左右鍵//獲取鍵盤上的鍵碼int keyCode = e.getKeyCode();System.out.println(keyCode);if (keyCode == 38) {System.out.println("上");if (x == 3) {//已經(jīng)到底了,什么都不做return;}//邏輯://把空白方塊下方的數(shù)字往上移動(dòng)//x,y 表示空白方塊//x+1,y 表示空白方塊上的位置//把x+1,y位置上的數(shù)字賦值給x,y位置arr[x][y] = arr[x+1][y];arr[x+1][y] = 0;//空白方塊的位置發(fā)生了改變x++;step++;//重新初始化圖片initImage();} else if (keyCode == 40) {if (x == 0) {//已經(jīng)到底了,什么都不做return;}System.out.println("下");arr[x][y] = arr[x-1][y];arr[x-1][y] = 0;//空白方塊的位置發(fā)生了改變x--;step++;//重新初始化圖片initImage();} else if (keyCode == 37) {if (y == 3) {//已經(jīng)到底了,什么都不做return;}System.out.println("左");arr[x][y] = arr[x][y+1];arr[x][y+1] = 0;//空白方塊的位置發(fā)生了改變y++;step++;//重新初始化圖片initImage();} else if (keyCode == 39) {if (y == 0) {//已經(jīng)到底了,什么都不做return;}System.out.println("右");arr[x][y] = arr[x][y-1];arr[x][y-1] = 0;//空白方塊的位置發(fā)生了改變y--;step++;//重新初始化圖片initImage();} else if( keyCode == 65){initImage();} else if (keyCode == 87) {arr = new int[][]{{1,2,3,4},{5,6,7,8},{9,10,11,12},{13,14,15,0}};initImage();}}
7.菜單功能
1.重新開始
- 給重新游戲綁定點(diǎn)擊事件---------->ActionListener
- 重新打亂二維數(shù)組中的數(shù)字
- 加載圖片
- 計(jì)步器清零
2.關(guān)閉游戲
- 給關(guān)閉游戲綁定事件
- 結(jié)束虛擬機(jī),關(guān)閉所有
3.關(guān)于我們
4.代碼
(新加代碼,非完整)
public class GameJFrame extends javax.swing.JFrame implements KeyListener , ActionListener {//把條目添加到選項(xiàng)中 ----- 移到成員位置functionJMenu.add(replayJMenuItem);functionJMenu.add(reLoginJMenuItem);functionJMenu.add(closeJMenuItem);aboutJMenu.add(accountItem);}private void initJMenuBar() {//.........//給條目綁定事件replayJMenuItem.addActionListener(this);reLoginJMenuItem.addActionListener(this);closeJMenuItem.addActionListener(this);accountItem.addActionListener(this);
}
//initData 截止到現(xiàn)在的完整代碼private void initData() {//1.定義一個(gè)一維數(shù)組int[] tempArr = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15};//2.隨機(jī)打亂一維數(shù)組中的數(shù)據(jù)for (int i = 0; i < tempArr.length; i++) {//獲取隨機(jī)索引int randomIndex = (int)(Math.random()*tempArr.length);//拿著隨機(jī)索引對(duì)應(yīng)的值和i索引對(duì)應(yīng)的值進(jìn)行交換int temp = tempArr[i];tempArr[i] = tempArr[randomIndex];tempArr[randomIndex] = temp;}//3.遍歷一維數(shù)組for (int i = 0; i < tempArr.length; i++) {if (tempArr[i] == 0) {x = i / 4;y = i % 4;} arr[i / 4][i % 4] = tempArr[i];}System.out.println();}@Overridepublic void actionPerformed(ActionEvent e) {//獲取被點(diǎn)擊的條目對(duì)象Object obj = e.getSource();if (obj == replayJMenuItem) {System.out.println("重新游戲");//步數(shù)清零step = 0;//重新打亂數(shù)據(jù)initData();//重新初始化圖片initImage();} else if (obj == reLoginJMenuItem) {System.out.println("重新登錄");//關(guān)閉當(dāng)前登錄的界面this.setVisible(false);//打開登錄界面new LoginJFrame();} else if (obj == closeJMenuItem) {System.out.println("關(guān)閉游戲");System.exit(0);} else if (obj == accountItem) {System.out.println("公眾號(hào)");//創(chuàng)建一個(gè)彈窗對(duì)象JDialog jDialog = new JDialog();//創(chuàng)建一個(gè)管理圖片的容器JLabel jLabel = new JLabel(new ImageIcon("image\\account.jpg"));//設(shè)置位置和寬高jLabel.setBounds(0,0,258,258);//把圖片添加到彈窗中jDialog.getContentPane().add(jLabel);//設(shè)置彈窗的寬高jDialog.setSize(280,316);//設(shè)置彈窗置頂jDialog.setAlwaysOnTop(true);//設(shè)置彈窗居中jDialog.setLocationRelativeTo(null);//彈框不關(guān)閉無法操作下面的界面jDialog.setModal(true);//讓彈窗顯示出來jDialog.setVisible(true);}}
8.游戲打包exe(概括)
- 一定要包含圖形化界面
- 代碼要打包起來
- 游戲用到的圖片也要打包起來
- JDK也要打包起來
步驟:
- 把所有代碼打包成一個(gè)壓縮包,jar后綴的壓縮包
- 把jar包轉(zhuǎn)換成exe安裝包
- 把第二步的exe,圖片,JDK整合在一起,變成最終的exe安裝包
9.所有完整代碼
1.GameJFrame
package com.woziji.ui;import javax.swing.*;
import javax.swing.border.BevelBorder;
import javax.swing.border.Border;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.util.ArrayList;public class GameJFrame extends javax.swing.JFrame implements KeyListener , ActionListener {//JFrame 界面,窗體//子類呢? 也表示界面,窗體//規(guī)定:GameJFrame 表示游戲的主界面//以后和游戲相關(guān)的所有邏輯都寫在這個(gè)類中//用來管理數(shù)據(jù)int[][] arr = new int[4][4];//記錄空白方塊的位置int x = 0;int y = 0;//定義一個(gè)變量,記錄當(dāng)前展示圖片的路徑String path = "";//定義一個(gè)二維數(shù)組,存儲(chǔ)正確的數(shù)據(jù)int[][] win = {{1,2,3,4},{5,6,7,8},{9,10,11,12},{13,14,15,0}};//定義變量,記錄步數(shù)int step = 0;//創(chuàng)建選項(xiàng)下面的條目對(duì)象JMenuItem replayJMenuItem = new JMenuItem("重新游戲");JMenuItem reLoginJMenuItem = new JMenuItem("重新登錄");JMenuItem closeJMenuItem = new JMenuItem("關(guān)閉游戲");JMenuItem accountItem = new JMenuItem("公眾號(hào)");public GameJFrame() {//初始化界面initJFrame();//初始化菜單initJMenuBar();//初始化數(shù)據(jù)(打亂)initData();//初始化圖片initImage();//讓界面顯示出來,建議寫在最后this.setVisible(true);}private void initData() {//1.定義一個(gè)一維數(shù)組int[] tempArr = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15};//2.隨機(jī)打亂一維數(shù)組中的數(shù)據(jù)for (int i = 0; i < tempArr.length; i++) {//獲取隨機(jī)索引int randomIndex = (int)(Math.random()*tempArr.length);//拿著隨機(jī)索引對(duì)應(yīng)的值和i索引對(duì)應(yīng)的值進(jìn)行交換int temp = tempArr[i];tempArr[i] = tempArr[randomIndex];tempArr[randomIndex] = temp;}//3.遍歷一維數(shù)組for (int i = 0; i < tempArr.length; i++) {if (tempArr[i] == 0) {x = i / 4;y = i % 4;}arr[i / 4][i % 4] = tempArr[i];}System.out.println();}private void initImage() {//清空原本已經(jīng)出現(xiàn)的圖片this.getContentPane().removeAll();//判斷游戲是否結(jié)束if (isWin()) {//顯示勝利的圖片ImageIcon winIcon = new ImageIcon("image\\win.jpg");JLabel winJLabel = new JLabel(winIcon);winJLabel.setBounds(203,283,197,73);this.getContentPane().add(winJLabel);}JLabel stepCount = new JLabel("步數(shù):"+step);stepCount.setBounds(50,30,100,20);this.getContentPane().add(stepCount);//路徑分兩種://1.絕對(duì)路徑:從盤符開始寫的路徑 D:\\aaa\\bbb\\ccc.jpg//2.相對(duì)路徑:從當(dāng)前項(xiàng)目開始寫的路徑 aaa\\bbb\\ccc.jpg//添加圖片的時(shí)候,就需要按照二維數(shù)組中管理的數(shù)據(jù)添加圖片//外循環(huán)----把內(nèi)循環(huán)的代碼重復(fù)執(zhí)行4次for (int i = 0; i < 4; i++) {//內(nèi)循環(huán)----表示在一行中放4個(gè)圖片for (int j = 0; j < 4; j++) {//獲取二維數(shù)組中每個(gè)索引對(duì)應(yīng)的數(shù)字int number = arr[i][j];//創(chuàng)建一個(gè)圖片ImageIcon對(duì)象 參數(shù):圖片的路徑(沒加圖片,意思一下得了)//這里的圖片最好命名為數(shù)字ImageIcon icon = new ImageIcon("image\\background\\"+number+".jpg");//創(chuàng)建一個(gè)JLabel對(duì)象(管理容器)JLabel jLabel = new JLabel(icon);//設(shè)置圖片的位置jLabel.setBounds(105*j+83,105*i+134,105,105);//給圖片添加邊框jLabel.setBorder(new BevelBorder(1));//把JLabel對(duì)象添加到界面中this.getContentPane().add(jLabel);//添加一次后number自增1,表示下一次加載后面一張圖片}}//細(xì)節(jié)://先加載的圖片在上方,后加載的圖片在下方//添加背景圖片ImageIcon background = new ImageIcon("image\\background\\background.jpg");JLabel backgroundJLabel = new JLabel(background);backgroundJLabel.setBounds(40,40,508,560);//把背景圖片添加到界面中this.getContentPane().add(backgroundJLabel);//刷新界面this.getContentPane().repaint();}private void initJMenuBar() {//創(chuàng)建整個(gè)的菜單對(duì)象JMenuBar JMenuBar = new JMenuBar();//創(chuàng)建菜單上面的兩個(gè)選項(xiàng)的對(duì)象 (功能 關(guān)于我們)JMenu functionJMenu = new JMenu("功能");JMenu aboutJMenu = new JMenu("關(guān)于我們");//把條目添加到選項(xiàng)中functionJMenu.add(replayJMenuItem);functionJMenu.add(reLoginJMenuItem);functionJMenu.add(closeJMenuItem);aboutJMenu.add(accountItem);//把選項(xiàng)添加到菜單中JMenuBar.add(functionJMenu);JMenuBar.add(aboutJMenu);//把菜單設(shè)置到界面中this.setJMenuBar(JMenuBar);//給條目綁定事件replayJMenuItem.addActionListener(this);reLoginJMenuItem.addActionListener(this);closeJMenuItem.addActionListener(this);accountItem.addActionListener(this);}private void initJFrame() {//設(shè)置界面的寬高this.setSize(603,680);//設(shè)置界面的標(biāo)題this.setTitle("拼圖單機(jī)版 v1.0");//設(shè)置界面置頂this.setAlwaysOnTop(true);//設(shè)置界面居中this.setLocationRelativeTo(null);//設(shè)置界面的關(guān)閉方式this.setDefaultCloseOperation(3);//取消默認(rèn)的居中放置,只有取消了才可以設(shè)置坐標(biāo)this.setLayout(null);//給整個(gè)界面添加鍵盤監(jiān)聽this.addKeyListener(this);}@Overridepublic void keyTyped(KeyEvent e) {}//按下不松,一直觸發(fā)@Overridepublic void keyPressed(KeyEvent e) {int code = e.getKeyCode();if (code == 65) {//把界面中的所有圖片全部刪除this.getContentPane().removeAll();//加載第一張完整的圖片JLabel allJLabel = new JLabel(new ImageIcon(path+"all.jpg"));//設(shè)置圖片的位置allJLabel.setBounds(83,134,420,420);//把圖片添加到界面中this.getContentPane().add(allJLabel);//加載背景圖片ImageIcon background = new ImageIcon("image\\background\\background.jpg");JLabel backgroundJLabel = new JLabel(background);backgroundJLabel.setBounds(40,40,508,560);//把背景圖片添加到界面中this.getContentPane().add(backgroundJLabel);//刷新界面this.getContentPane().repaint();}}@Overridepublic void keyReleased(KeyEvent e) {//判斷游戲是否勝利,如果勝利,此方法直接結(jié)束if (isWin()) {//1.返回結(jié)果//2.結(jié)束方法return;}//對(duì)應(yīng)鍵盤上的上下左右鍵//獲取鍵盤上的鍵碼int keyCode = e.getKeyCode();System.out.println(keyCode);if (keyCode == 38) {System.out.println("上");if (x == 3) {//已經(jīng)到底了,什么都不做return;}//邏輯://把空白方塊下方的數(shù)字往上移動(dòng)//x,y 表示空白方塊//x+1,y 表示空白方塊上的位置//把x+1,y位置上的數(shù)字賦值給x,y位置arr[x][y] = arr[x+1][y];arr[x+1][y] = 0;//空白方塊的位置發(fā)生了改變x++;step++;//重新初始化圖片initImage();} else if (keyCode == 40) {if (x == 0) {//已經(jīng)到底了,什么都不做return;}System.out.println("下");arr[x][y] = arr[x-1][y];arr[x-1][y] = 0;//空白方塊的位置發(fā)生了改變x--;step++;//重新初始化圖片initImage();} else if (keyCode == 37) {if (y == 3) {//已經(jīng)到底了,什么都不做return;}System.out.println("左");arr[x][y] = arr[x][y+1];arr[x][y+1] = 0;//空白方塊的位置發(fā)生了改變y++;step++;//重新初始化圖片initImage();} else if (keyCode == 39) {if (y == 0) {//已經(jīng)到底了,什么都不做return;}System.out.println("右");arr[x][y] = arr[x][y-1];arr[x][y-1] = 0;//空白方塊的位置發(fā)生了改變y--;step++;//重新初始化圖片initImage();} else if( keyCode == 65){initImage();} else if (keyCode == 87) {arr = new int[][]{{1,2,3,4},{5,6,7,8},{9,10,11,12},{13,14,15,0}};initImage();}}//判斷游戲是否勝利public boolean isWin(){for (int i = 0; i < arr.length; i++) {for (int j = 0; j < arr[i].length; j++) {if (arr[i][j] != win[i][j]){return false;}}}return true;}@Overridepublic void actionPerformed(ActionEvent e) {//獲取被點(diǎn)擊的條目對(duì)象Object obj = e.getSource();if (obj == replayJMenuItem) {System.out.println("重新游戲");//步數(shù)清零step = 0;//重新打亂數(shù)據(jù)initData();//重新初始化圖片initImage();} else if (obj == reLoginJMenuItem) {System.out.println("重新登錄");//關(guān)閉當(dāng)前登錄的界面this.setVisible(false);//打開登錄界面new LoginJFrame();} else if (obj == closeJMenuItem) {System.out.println("關(guān)閉游戲");System.exit(0);} else if (obj == accountItem) {System.out.println("公眾號(hào)");//創(chuàng)建一個(gè)彈窗對(duì)象JDialog jDialog = new JDialog();//創(chuàng)建一個(gè)管理圖片的容器JLabel jLabel = new JLabel(new ImageIcon("image\\account.jpg"));//設(shè)置位置和寬高jLabel.setBounds(0,0,258,258);//把圖片添加到彈窗中jDialog.getContentPane().add(jLabel);//設(shè)置彈窗的寬高jDialog.setSize(280,316);//設(shè)置彈窗置頂jDialog.setAlwaysOnTop(true);//設(shè)置彈窗居中jDialog.setLocationRelativeTo(null);//彈框不關(guān)閉無法操作下面的界面jDialog.setModal(true);//讓彈窗顯示出來jDialog.setVisible(true);}}
}
2.LoginJFrame
package com.woziji.ui;import javax.swing.*;public class LoginJFrame extends javax.swing.JFrame{//登錄界面//以后和登錄相關(guān)的所有邏輯都寫在這個(gè)類中public LoginJFrame(){//在創(chuàng)建登陸界面的時(shí)候,同時(shí)給這個(gè)界面去設(shè)置一些信息//比如:寬高,直接展示出來this.setSize(488,430);this.setVisible(true);//設(shè)置界面的標(biāo)題this.setTitle("拼圖 登錄");//設(shè)置界面置頂this.setAlwaysOnTop(true);//設(shè)置界面居中this.setLocationRelativeTo(null);//設(shè)置界面的關(guān)閉方式this.setDefaultCloseOperation(3);}
}
3.RegisterJFrame
package com.woziji.ui;public class RegisterJFrame extends javax.swing.JFrame{//注冊(cè)界面//以后和注冊(cè)相關(guān)的所有邏輯都寫在這個(gè)類中public RegisterJFrame(){this.setSize(488,500);this.setVisible(true);//設(shè)置界面的標(biāo)題this.setTitle("拼圖 注冊(cè)");//設(shè)置界面置頂this.setAlwaysOnTop(true);//設(shè)置界面居中this.setLocationRelativeTo(null);//設(shè)置界面的關(guān)閉方式this.setDefaultCloseOperation(3);}
}
4.主入口
import com.woziji.ui.GameJFrame;
import com.woziji.ui.LoginJFrame;
import com.woziji.ui.RegisterJFrame;public class App {public static void main(String[] args) {//表示程序的入口//如果我們想開啟一個(gè)界面,就創(chuàng)建誰的對(duì)象//new LoginJFrame();//new RegisterJFrame();new GameJFrame();}
}