当前位置: 首页 > news >正文

拼图小游戏

  做一个拼图小游戏要有登入页面注册页面,可以换图片,一键看图,一键还原,还有存档

游戏页面:

import javax.swing.*;
import javax.swing.border.BevelBorder;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.io.*;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Properties;public class GameJFrame extends JFrame implements KeyListener, ActionListener {int[][] ints = new int[3][3];int[][]win=new int[][]{{1,2,3},{4,5,6},{7,8,0}};//空白处的的位置int x=0;int y=0;String path="java\\imger1\\";//步数int step=0;//菜单项JMenuItem jMenuItem = new JMenuItem("重新游戏");JMenuItem jMenuItem1 = new JMenuItem("重新登入");JMenuItem jMenuItem2 = new JMenuItem("关闭游戏");JMenuItem jMenuItem3 = new JMenuItem("公众号");JMenuItem jMenuItem0 = new JMenuItem("美女");JMenuItem jMenuItem4 = new JMenuItem("植物");JMenuItem jMenuItem5 = new JMenuItem("动物");JMenuItem jMenuItem6 = new JMenuItem("存档0(空)");JMenuItem jMenuItem7 = new JMenuItem("存档1(空)");JMenuItem jMenuItem8 = new JMenuItem("存档2(空)");JMenuItem jMenuItem9 = new JMenuItem("存档3(空)");JMenuItem jMenuItem10 = new JMenuItem("存档4(空)");JMenuItem jMenuItem11 = new JMenuItem("存档5(空)");JMenuItem jMenuItem12 = new JMenuItem("读档0(空)");JMenuItem jMenuItem13 = new JMenuItem("读档1(空)");JMenuItem jMenuItem14 = new JMenuItem("读档2(空)");JMenuItem jMenuItem15 = new JMenuItem("读档3(空)");JMenuItem jMenuItem16 = new JMenuItem("读档4(空)");JMenuItem jMenuItem17 = new JMenuItem("读档5(空)");JMenu jMenu4 = new JMenu("读档");JMenu jMenu3 = new JMenu("存档");public GameJFrame() {intiJFrame();initJFrame();initDate();initImager();//显示this.setVisible(true);}private void initDate() {ArrayList<Integer> integers = new ArrayList<>();Collections.addAll(integers, 0, 1, 2, 3, 4, 5, 6, 7, 8);Collections.shuffle(integers);int index = 0;for (int i1 = 0; i1 < ints.length; i1++) {for (int i = 0; i < ints[i1].length; i++) {ints[i1][i] = integers.get(index);if (integers.get(index)==0){x=i1;y=i;}index++;}}}private void initImager(){//清空原本出现的图片this.getContentPane().removeAll();//判断if (victory()){JLabel jLabel = new JLabel(new ImageIcon(path + "胜利.png"));jLabel.setBounds(20,20,179,78);this.getContentPane().add(jLabel);}//步数JLabel jLabel2 = new JLabel("步数" + step);jLabel2.setBounds(500,50,200,50);this.getContentPane().add(jLabel2);//先加载的图片在上面 后加载的图片在下方for (int i = 0; i < 3; i++) {for (int j = 0; j < 3; j++) {//创建一个图片ImagerIcon对象//创建JLabel对象(容器)int i1 = ints[i][j];JLabel jLabel = new JLabel(new ImageIcon(path+"未标题-"+i1+".png"));//设置图片位置jLabel.setBounds(105*j+132,105*i+150,105,105);//添加图片边框//0:让图片突出//1:让图片凹进去jLabel.setBorder(new BevelBorder(BevelBorder.LOWERED));//把容器添加界面中this.getContentPane().add(jLabel);}}//背景JLabel jLabel1 = new JLabel(new ImageIcon(path+"img.png"));jLabel1.setBounds(35,4,506,560);this.getContentPane().add(jLabel1);//刷新this.getContentPane().repaint();
}private void initJFrame() {//菜单栏JMenuBar jMenuBar = new JMenuBar();//菜单JMenu jMenu = new JMenu("功能");JMenu jMenu1 = new JMenu("关于我们");JMenu jMenu2 = new JMenu("更换图片");jMenu.add(jMenu2);jMenu.add(jMenu3);jMenu.add(jMenu4);jMenu2.add(jMenuItem0);jMenu2.add(jMenuItem4);jMenu2.add(jMenuItem5);jMenu3.add(jMenuItem6);jMenu3.add(jMenuItem7);jMenu3.add(jMenuItem8);jMenu3.add(jMenuItem9);jMenu3.add(jMenuItem10);jMenu3.add(jMenuItem11);jMenu4.add(jMenuItem12);jMenu4.add(jMenuItem13);jMenu4.add(jMenuItem14);jMenu4.add(jMenuItem15);jMenu4.add(jMenuItem16);jMenu4.add(jMenuItem17);//监听jMenuItem0.addActionListener(this);jMenuItem.addActionListener(this);jMenuItem1.addActionListener(this);jMenuItem2.addActionListener(this);jMenuItem3.addActionListener(this);jMenuItem4.addActionListener(this);jMenuItem5.addActionListener(this);jMenuItem6.addActionListener(this);jMenuItem7.addActionListener(this);jMenuItem8.addActionListener(this);jMenuItem9.addActionListener(this);jMenuItem10.addActionListener(this);jMenuItem11.addActionListener(this);jMenuItem12.addActionListener(this);jMenuItem13.addActionListener(this);jMenuItem14.addActionListener(this);jMenuItem15.addActionListener(this);jMenuItem16.addActionListener(this);jMenuItem17.addActionListener(this);//添加jMenu.add(jMenuItem);jMenu.add(jMenuItem1);jMenu.add(jMenuItem2);jMenu1.add(jMenuItem3);jMenuBar.add(jMenu);jMenuBar.add(jMenu1);getGameinfo();this.setJMenuBar(jMenuBar);}private void getGameinfo(){File file = new File("java\\src\\Game03\\save");File[] files = file.listFiles();for (File file1 : files) {Gameinfo gi= null;try {ObjectInputStream objectInputStream = new ObjectInputStream(new FileInputStream(file1));gi = (Gameinfo)objectInputStream.readObject();objectInputStream.close();} catch (IOException e) {throw new RuntimeException(e);} catch (ClassNotFoundException e) {throw new RuntimeException(e);}//步数int step1 = gi.getStep();//文件名String name = file1.getName();int i1 = name.charAt(4) - '0';jMenu3.getItem(i1).setText("存档"+i1+"("+step1+")");jMenu4.getItem(i1).setText("读档"+i1+"("+step1+")");}}private void intiJFrame() {//设置宽高this.setSize(603,680);//设置界面标题this.setTitle("拼图单机小游戏1.0");//设置界面置顶this.setAlwaysOnTop(true);//设置界面居中this.setLocationRelativeTo(null);//设置关闭页面this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);//关闭容器的默认值this.setLayout(null);//添加键盘监听this.addKeyListener(this);}/*** Invoked when a key has been typed.* See the class description for {@link KeyEvent} for a definition of* a key typed event.** @param e*/@Overridepublic void keyTyped(KeyEvent e) {}/*** Invoked when a key has been pressed.* See the class description for {@link KeyEvent} for a definition of* a key pressed event.** @param e*/@Overridepublic void keyPressed(KeyEvent e) {//按下不松int keyCode = e.getKeyCode();if (keyCode==65){//清空当前页面的图片this.getContentPane().removeAll();//加载JLabel jLabel = new JLabel(new ImageIcon(path+"未标题-10.png"));jLabel.setBounds(130,150,320,320);this.getContentPane().add(jLabel);JLabel jLabel1 = new JLabel(new ImageIcon(path+"img.png"));jLabel1.setBounds(35,4,506,560);this.getContentPane().add(jLabel1);this.getContentPane().repaint();}}/*** Invoked when a key has been released.* See the class description for {@link KeyEvent} for a definition of* a key released event.** @param e*/@Overridepublic void keyReleased(KeyEvent e) {//松开if (victory()){//结束方法return;}//上38//下40//左37//右39int keyCode = e.getKeyCode();if (keyCode==38){if (x==2){return;}//零变成零下面的数ints[x][y]=ints[x+1][y];ints[x+1][y]=0;x++;step++;//新的零的位置initImager();}else if (keyCode==40){if (x==0){return;}ints[x][y]=ints[x-1][y];ints[x-1][y]=0;x--;step++;initImager();}else if (keyCode==37){if (y==2){return;}ints[x][y]=ints[x][y+1];ints[x][y+1]=0;y++;step++;initImager();}else if (keyCode==39){if (y==0){return;}ints[x][y]=ints[x][y-1];ints[x][y-1]=0;y--;step++;initImager();}else if (keyCode==65){initImager();}else if (keyCode==87){ints=new int[][]{{1,2,3},{4,5,6},{7,8,0}};initImager();x=2;y=2;}}//胜利方法private boolean victory(){for (int i1 = 0; i1 < ints.length; i1++) {for (int i = 0; i < ints[i1].length; i++) {if (ints[i1][i]!=win[i1][i]){return false;}}}return true;}/*** Invoked when an action occurs.** @param e*/@Overridepublic void actionPerformed(ActionEvent e) {Object source = e.getSource();if (source==jMenuItem){//重新游戏step=0;initDate();initImager();}else if (source==jMenuItem1){//重新登入this.setVisible(false);new LoginJFrame();}else if (source==jMenuItem2){//关闭游戏System.exit(0);}else if (source==jMenuItem3) {//创建一个弹框对象JDialog jDialog = new JDialog();Properties properties = new Properties();try {FileInputStream stream = new FileInputStream("java\\picture.properties");properties.load(stream);stream.close();} catch (IOException ex) {throw new RuntimeException(ex);}String s = (String) properties.get("a");//图片JLabel jLabel = new JLabel(new ImageIcon(s));//图片位置jLabel.setBounds(0, 0, 258, 258);//添加到弹框里jDialog.getContentPane().add(jLabel);//设置弹框大小jDialog.setSize(344, 344);//置顶jDialog.setAlwaysOnTop(true);//居中jDialog.setLocationRelativeTo(null);//不关闭不可以执行jDialog.setModal(true);//显示jDialog.setVisible(true);}else if (source==jMenuItem0){step=0;path="java\\imger2\\";initDate();initImager();} else if (source==jMenuItem4) {step=0;path="java\\imger3\\";initDate();initImager();} else if (source==jMenuItem5) {step=0;path="java\\imger4\\";initDate();initImager();} else if (source==jMenuItem6||source==jMenuItem7||source==jMenuItem8||source==jMenuItem9||source==jMenuItem10||source==jMenuItem11) {System.out.println("存档");//获得里面的菜单信息JMenuItem source1 = (JMenuItem) source;String text = source1.getText();int i1 = text.charAt(2) - '0';System.out.println(i1);try {ObjectOutputStream objectOutputStream = new ObjectOutputStream(new FileOutputStream("java\\src\\Game03\\save\\save"+i1+".date"));Gameinfo gameinfo = new Gameinfo(ints, x, y, path, step);objectOutputStream.writeObject(gameinfo);objectOutputStream.close();} catch (IOException ex) {throw new RuntimeException(ex);}source1.setText("存档"+i1+"步数"+step);//获取读档里的数据//jMenu4.getItem(i1).setText("读档"+i1+"步数"+step);} else if (source==jMenuItem12||source==jMenuItem13||source==jMenuItem14||source==jMenuItem15||source==jMenuItem16||source==jMenuItem17) {System.out.println("读档");//获得里面的菜单信息JMenuItem source1 = (JMenuItem) source;String text = source1.getText();int i1 = text.charAt(2) - '0';Gameinfo gameinfo=null;System.out.println(i1);try {ObjectInputStream objectInputStream = new ObjectInputStream(new FileInputStream("java\\src\\Game03\\save\\save"+i1+".date"));gameinfo = (Gameinfo) objectInputStream.readObject();objectInputStream.close();} catch (IOException ex) {throw new RuntimeException(ex);} catch (ClassNotFoundException ex) {throw new RuntimeException(ex);}ints=gameinfo.getData();x=gameinfo.getX();y=gameinfo.getY();path=gameinfo.getPath();step=gameinfo.getStep();initImager();}}
}

登入页面:

import cn.hutool.core.io.FileUtil;import javax.swing.*;
import javax.swing.border.BevelBorder;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;public class LoginJFrame extends JFrame implements ActionListener, MouseListener {ArrayList<User> users = new ArrayList<>();ArrayList<String> list = new ArrayList<>();JTextField jTextField = new JTextField();JPasswordField jTextField2 = new JPasswordField();JTextField jTextField3 = new JTextField();JLabel jLabel4 = new JLabel();JButton jButton3 = new JButton("换一下");JButton jButton = new JButton();JButton jButton2 = new JButton();String app="java\\imger1\\登入.png";String app2="java\\imger1\\注册.png";public LoginJFrame(){readUserinto();initJFrame();String();initImager();//设置界面显示this.setVisible(true);}private void readUserinto() {List<String> list = FileUtil.readUtf8Lines("Game03\\Geme\\用户信息.txt");for (String s : list) {String[] split = s.split("&");String[] split1 = split[0].split("=");String[] split2 = split[1].split("=");User user = new User(split1[1], split2[1]);users.add(user);}}private void String(){Collections.addAll(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","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","10","0");Collections.shuffle(list);jLabel4.setText(list.get(0)+list.get(1)+list.get(2)+list.get(3)+list.get(4));}private void initJFrame(){//设置界面大小this.setSize(480,430);//设置界面标题this.setTitle("登入");//设置界面置顶this.setAlwaysOnTop(true);//设置界面居中this.setLocationRelativeTo(null);//设置界面关闭this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);//关闭默认this.setLayout(null);}private void initImager(){this.getContentPane().removeAll();JLabel jLabel1 = new JLabel(new ImageIcon("java\\imger1\\用户名.png"));jLabel1.setBounds(25,120,200,60);this.getContentPane().add(jLabel1);//文本框jTextField.setBounds(180,138,200,30);jTextField.setBorder(new BevelBorder(BevelBorder.LOWERED));this.getContentPane().add(jTextField);JLabel jLabel2 = new JLabel(new ImageIcon("java\\imger1\\密码.png"));jLabel2.setBounds(25,180,200,60);this.getContentPane().add(jLabel2);jTextField2.setBounds(180,190,200,30);jTextField2.setBorder(new BevelBorder(BevelBorder.LOWERED));this.getContentPane().add(jTextField2);JLabel jLabel3 = new JLabel(new ImageIcon("java\\imger1\\码.png"));jLabel3.setBounds(25,220,200,60);this.getContentPane().add(jLabel3);jTextField3.setBounds(180,240,100,30);jTextField3.setBorder(new BevelBorder(BevelBorder.LOWERED));this.getContentPane().add(jTextField3);jLabel4.setBounds(300,230,100,50);this.getContentPane().add(jLabel4);jButton3.setBounds(320,240,80,30);jButton3.setBorderPainted(false);jButton3.setContentAreaFilled(false);//文字颜色jButton3.setForeground(Color.red);jButton3.addActionListener(this);this.getContentPane().add(jButton3);//按钮jButton.setBounds(120,290,80,40);//设置按钮背景jButton.setIcon(new ImageIcon(app));//关闭边框jButton.setBorderPainted(false);//关闭按钮背景jButton.setContentAreaFilled(false);//监听jButton.addMouseListener(this);this.getContentPane().add(jButton);jButton2.addMouseListener(this);jButton2.setBounds(270,290,80,45);//设置按钮背景jButton2.setIcon(new ImageIcon(app2));//关闭边框jButton2.setBorderPainted(false);//关闭按钮背景jButton2.setContentAreaFilled(false);this.getContentPane().add(jButton2);JLabel jLabel = new JLabel(new ImageIcon("java\\imger1\\1.png"));jLabel.setBounds(0,0,480,430);this.getContentPane().add(jLabel);
this.getContentPane().repaint();}/*** Invoked when an action occurs.** @param e*/@Overridepublic void actionPerformed(ActionEvent e) {Object source = e.getSource();if (source==jButton3){String();initImager();}}/*** Invoked when the mouse button has been clicked (pressed* and released) on a component.** @param e*/@Overridepublic void mouseClicked(MouseEvent e) {}/*** Invoked when a mouse button has been pressed on a component.** @param e*/@Overridepublic void mousePressed(MouseEvent e) {Object source = e.getSource();if (source == jButton) {app = "java\\imger1\\变色1.png";initImager();String text = jTextField.getText();String text2 = jTextField2.getText();String text3 = jTextField3.getText();for (User user2 : users) {String name = user2.getName();String poss = user2.getPoss();System.out.println(name);System.out.println(poss);if (text3.length() == 0) {JDialog jDialog = new JDialog();JLabel jLabel = new JLabel("验证码不能为空");jLabel.setBounds(80, 50, 200, 50);jDialog.add(jLabel);jDialog.setSize(40, 80);//置顶jDialog.setAlwaysOnTop(true);//居中jDialog.setLocationRelativeTo(null);//不关闭不可以执行jDialog.setModal(true);//显示jDialog.setVisible(true);return;} else if (text.length() == 0 && text2.length() == 0) {JDialog jDialog = new JDialog();JLabel jLabel = new JLabel("账号和密码不能为空");jLabel.setBounds(80, 50, 200, 50);jDialog.add(jLabel);jDialog.setSize(40, 80);//置顶jDialog.setAlwaysOnTop(true);//居中jDialog.setLocationRelativeTo(null);//不关闭不可以执行jDialog.setModal(true);//显示jDialog.setVisible(true);return;} else if (!text3.equals(jLabel4.getText())) {JDialog jDialog = new JDialog();JLabel jLabel = new JLabel("验证码错误");jLabel.setBounds(80, 50, 200, 50);jDialog.add(jLabel);jDialog.setSize(40, 80);//置顶jDialog.setAlwaysOnTop(true);//居中jDialog.setLocationRelativeTo(null);//不关闭不可以执行jDialog.setModal(true);//显示jDialog.setVisible(true);return;} else if (!text.equals(name)||text.equals(poss)) {JDialog jDialog = new JDialog();JLabel jLabel = new JLabel("账号和密码错误");jLabel.setBounds(80, 50, 200, 50);jDialog.add(jLabel);jDialog.setSize(40, 80);//置顶jDialog.setAlwaysOnTop(true);//居中jDialog.setLocationRelativeTo(null);//不关闭不可以执行jDialog.setModal(true);//显示jDialog.setVisible(true);return;} else if (text3.equals(jLabel4.getText())&&text.equals(name)&&text2.equals(poss)) {this.setVisible(false);new GameJFrame();return;}}} else if (source == jButton2) {app2 = "java\\imger1\\变色2.png";initImager();this.setVisible(false);new RegisterJFrame();return;}}/*** Invoked when a mouse button has been released on a component.** @param e*/@Overridepublic void mouseReleased(MouseEvent e) {Object source = e.getSource();if (source==jButton){app="java\\imger1\\登入.png";initImager();} else if (source==jButton2) {app2="java\\imger1\\注册.png";initImager();}}/*** Invoked when the mouse enters a component.** @param e*/@Overridepublic void mouseEntered(MouseEvent e) {}/*** Invoked when the mouse exits a component.** @param e*/@Overridepublic void mouseExited(MouseEvent e) {}
}

 注册页面:

import cn.hutool.core.io.FileUtil;import javax.swing.*;
import javax.swing.border.BevelBorder;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.util.ArrayList;
import java.util.List;public class RegisterJFrame extends JFrame implements ActionListener, MouseListener {ArrayList<User> users = new ArrayList<>();String app="java\\imger1\\注册.png";String app2="java\\imger1\\重置.png";JButton jButton = new JButton();JButton jButton1 = new JButton();JTextField jTextField = new JTextField();JPasswordField jTextField2 = new JPasswordField();JPasswordField jTextField3 = new JPasswordField();public RegisterJFrame() {readUserinto();initJFrame();initImager();//设置界面显示this.setVisible(true);}private void readUserinto() {List<String> list = FileUtil.readUtf8Lines("Game03\\Geme\\用户信息.txt");for (String s : list) {String[] split = s.split("&");String[] split1 = split[0].split("=");String[] split2 = split[1].split("=");User user = new User(split1[1], split2[1]);users.add(user);}}private void initJFrame(){//设置宽高this.setSize(488,500);//设置界面标题this.setTitle("注册");//设置界面置顶this.setAlwaysOnTop(true);//设置界面居中this.setLocationRelativeTo(null);//设置关闭页面this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);}private boolean USerName(String app){for (User user : users) {if (user.getName().equals(app)){return true;}}return false;}private void initImager() {this.getContentPane().removeAll();JLabel jLabel1 = new JLabel(new ImageIcon("java\\imger1\\注册用户.png"));jLabel1.setBounds(25, 120, 200, 60);this.getContentPane().add(jLabel1);//文本框jTextField.setBounds(180, 138, 200, 30);jTextField.setBorder(new BevelBorder(BevelBorder.LOWERED));this.getContentPane().add(jTextField);JLabel jLabel2 = new JLabel(new ImageIcon("java\\imger1\\注册密码.png"));jLabel2.setBounds(25, 180, 200, 60);this.getContentPane().add(jLabel2);String s = new String(jTextField2.getPassword());System.out.println(s);jTextField2.setBounds(180, 190, 200, 30);jTextField2.setBorder(new BevelBorder(BevelBorder.LOWERED));this.getContentPane().add(jTextField2);JLabel jLabel3 = new JLabel(new ImageIcon("java\\imger1\\再次密码.png"));jLabel3.setBounds(25, 240, 200, 60);this.getContentPane().add(jLabel3);jTextField3.setBounds(180, 250, 200, 30);jTextField3.setBorder(new BevelBorder(BevelBorder.LOWERED));this.getContentPane().add(jTextField3);jButton.setBounds(150,300,80,40);//设置按钮背景jButton.setIcon(new ImageIcon(app));//关闭边框jButton.setBorderPainted(false);//关闭按钮背景jButton.setContentAreaFilled(false);jButton.addActionListener(this);jButton.addMouseListener(this);this.getContentPane().add(jButton);jButton1.addActionListener(this);jButton1.setBounds(250,305,80,25);jButton1.setIcon(new ImageIcon(app2));jButton1.setBorderPainted(false);jButton1.setContentAreaFilled(false);this.getContentPane().add(jButton1);JLabel jLabel = new JLabel(new ImageIcon("java\\imger1\\1.png"));jLabel.setBounds(0,0,480,430);this.getContentPane().add(jLabel);this.getContentPane().repaint();}/*** Invoked when an action occurs.** @param e*/@Overridepublic void actionPerformed(ActionEvent e) {Object source = e.getSource();if (source==jButton){String text = jTextField.getText();char[] password = jTextField2.getPassword();String s = new String(password);char[] password1 = jTextField3.getPassword();String s1 = new String(password1);if (!s.equals(s1)){JDialog jDialog = new JDialog();JLabel jLabel = new JLabel("密码输入错误");jLabel.setBounds(80,50,200,50);jDialog.add(jLabel);jDialog.setSize(40, 80);//置顶jDialog.setAlwaysOnTop(true);//居中jDialog.setLocationRelativeTo(null);//不关闭不可以执行jDialog.setModal(true);//显示jDialog.setVisible(true);return;} else if (text.length()==0||s.length()==0||s1.length()==0) {JDialog jDialog = new JDialog();JLabel jLabel = new JLabel("不能为空");jLabel.setBounds(80, 50, 200, 50);jDialog.add(jLabel);jDialog.setSize(40, 80);//置顶jDialog.setAlwaysOnTop(true);//居中jDialog.setLocationRelativeTo(null);//不关闭不可以执行jDialog.setModal(true);//显示jDialog.setVisible(true);return;} else if (USerName(text)) {JDialog jDialog = new JDialog();JLabel jLabel = new JLabel("用户重复");jLabel.setBounds(80, 50, 200, 50);jDialog.add(jLabel);jDialog.setSize(40, 80);//置顶jDialog.setAlwaysOnTop(true);//居中jDialog.setLocationRelativeTo(null);//不关闭不可以执行jDialog.setModal(true);//显示jDialog.setVisible(true);return;} else if (!text.matches("[a-zA-Z0-9]{4,16}")) {JDialog jDialog = new JDialog();JLabel jLabel = new JLabel("用户起名不规范");jLabel.setBounds(80, 50, 200, 50);jDialog.add(jLabel);jDialog.setSize(40, 80);//置顶jDialog.setAlwaysOnTop(true);//居中jDialog.setLocationRelativeTo(null);//不关闭不可以执行jDialog.setModal(true);//显示jDialog.setVisible(true);return;}  else if (!s.matches("\\S*(?=\\S{6,})(?=\\S*\\d)(?=\\S*[A-Z])(?=\\S*[a-z])\\S*")) {JDialog jDialog = new JDialog();JLabel jLabel = new JLabel("密码不规范,至少一个字母,一个数字,6位数");jLabel.setBounds(80, 50, 200, 50);jDialog.add(jLabel);jDialog.setSize(40, 80);//置顶jDialog.setAlwaysOnTop(true);//居中jDialog.setLocationRelativeTo(null);//不关闭不可以执行jDialog.setModal(true);//显示jDialog.setVisible(true);return;}else {User user = new User(text, s);users.add(user);System.out.println(users);FileUtil.appendLines(users, "Game03\\Geme\\用户信息.txt", "UTF-8");this.setVisible(false);new LoginJFrame();return;}}if (source==jButton1) {jTextField.setText("");jTextField2.setText("");jTextField3.setText("");return;}}/*** Invoked when the mouse button has been clicked (pressed* and released) on a component.** @param e*/@Overridepublic void mouseClicked(MouseEvent e) {}/*** Invoked when a mouse button has been pressed on a component.** @param e*/@Overridepublic void mousePressed(MouseEvent e) {}/*** Invoked when a mouse button has been released on a component.** @param e*/@Overridepublic void mouseReleased(MouseEvent e) {}/*** Invoked when the mouse enters a component.** @param e*/@Overridepublic void mouseEntered(MouseEvent e) {}/*** Invoked when the mouse exits a component.** @param e*/@Overridepublic void mouseExited(MouseEvent e) {}
}

注意:有些代码的实现要用到糊涂包

读档信息存储:

import java.io.Serializable;public class Gameinfo implements Serializable {
private int[][]data;
private int x=0;
private int y=0;
private String path;
private int step;public Gameinfo(){}public Gameinfo(int[][] data, int x, int y, String path, int step) {this.data = data;this.x = x;this.y = y;this.path = path;this.step = step;}/*** 获取* @return data*/public int[][] getData() {return data;}/*** 设置* @param data*/public void setData(int[][] data) {this.data = data;}/*** 获取* @return x*/public int getX() {return x;}/*** 设置* @param x*/public void setX(int x) {this.x = x;}/*** 获取* @return y*/public int getY() {return y;}/*** 设置* @param y*/public void setY(int y) {this.y = y;}/*** 获取* @return path*/public String getPath() {return path;}/*** 设置* @param path*/public void setPath(String path) {this.path = path;}/*** 获取* @return step*/public int getStep() {return step;}/*** 设置* @param step*/public void setStep(int step) {this.step = step;}public String toString() {return "Gameinfo{data = " + data + ", x = " + x + ", y = " + y + ", path = " + path + ", step = " + step + "}";}
}

效果:

 


http://www.mrgr.cn/news/20475.html

相关文章:

  • location.protocol+‘//‘+location.hostname实现什么功能?
  • 2024 数学建模高教社杯 国赛(C题)| 农作物的种植策略 | 建模秘籍文章代码思路大全
  • 2024高教社杯数学建模国赛ABCDE题选题建议+初步分析
  • 从“红米汽车”到“陆地航母”,小鹏汽车杀疯了?
  • 同一个命令,ssh 远程服务器命令可用,vscode ssh 连接服务器不可用
  • BUUCTF PWN wp--bjdctf_2020_babystack
  • JavaWeb后端开发总结(3)
  • 如何撰写SCI作者同意发表函/版权转让协议
  • 海外盲盒APP系统开发,盲盒全球化发展机遇
  • 网工内推 | 富士康、移动,大厂网工,最高25K,IE认证优先
  • 2024 高教社杯 数学建模国赛 (C题)深度剖析|农作物的种植策略|数学建模完整代码+建模过程全解全析
  • 针对STM32串口输出乱码错误问题
  • uniapp解决页面跳转时,含有base64的数据丢失问题
  • LeetCode438. 找到字符串中所有字母异位词(2024秋季每日一题 11)
  • C++基础智能指针
  • Web入门-08.Tomcat-基本使用
  • 易保全出席人工智能应用场景高峰论坛,发布AI-数据资产管理平台2.0应用成果
  • 简单介绍 NVIDIA推出的图形处理单元(GPU)架构“安培架构“
  • 【JAVA数据结构】简单洗牌算法——ArrayList(顺序表)使用实例
  • 如何借助AI快速筛选和整理文献?