JAVA题目笔记(十二) 拼图游戏

一、创建界面:

创建一个603×680像素大小的游戏主界面。

创建一个488×430像素的登录界面

创建一个488×500像素的注册界面

方法代码示例:

        JFrame gameJFrame=new JFrame();  //创建界面对象
        gameJFrame.setSize(603,680);  //设置界面大小   界面默认隐藏
        gameJFrame.setVisible(true);   //显示/隐藏界面    方法参数为boolean变量,true则显示界面,false隐藏。

二、编辑界面

设置界面标题及各种内容。

相关方法示例:

        JFrame jframe=new JFrame();  //创建界面对象 
        jframe.setTitle("游戏标题");  //设置界面标题
        jframe.setAlwaysOnTop(true); //界面置顶
        jframe.setLocationRelativeTo(null);  //设置界面初始位置居中
        jframe.setDefaultCloseOperation(3);  //设置关闭模式  参数为int 
        //0:点关闭啥也不做   1:默认关闭
        //2:若有多个界面则只有在关闭最后一个界面时虚拟机才会终止,前提:每个界面关闭模式都为2
        //3:只要关闭其中一个界面,虚拟机直接停止

三、编辑界面菜单

设置界面中菜单和菜单中的不同功能以及对应的各种条目

相关方法示例:



        JFrame jframe=new JFrame();  //创建界面对象

        //创建 菜单 对象
        JMenuBar jmenuBar=new JMenuBar();

        //创建 菜单选项1 和 菜单选项2 对象
        JMenu functionJMenu=new JMenu("功能");
        JMenu aboutJMenu=new JMenu("关于我们");

        //创建 条目 对象
        JMenuItem relodGame=new JMenuItem("重新开始");
        JMenuItem relogIn=new JMenuItem("重新登录");
        JMenuItem closeGame=new JMenuItem("关闭游戏");

        //创建 条目 对象
        JMenuItem officialAccount=new JMenuItem("公众号");

        //调用方法将条目对象添加到菜单选项1中
        functionJMenu.add(relogIn);
        functionJMenu.add(relodGame);
        functionJMenu.add(closeGame);

        //调用方法将条目对象添加到菜单选项2中
        aboutJMenu.add(officialAccount);

        //将选项添加到菜单中
        jmenuBar.add(functionJMenu);
        jmenuBar.add(aboutJMenu);

        //将菜单添加到界面中
        jframe.setJMenuBar(jmenuBar);


四、添加图片、调整图片位置

添加图片相关方法示例代码:

//创建图片ImageIcon对象 
ImageIcon icon=new ImageIcon("C:\\Users\\DDDic\\IdeaProjects\\PuzzleGame\\image\\animal\\animal3\\3.jpg");
//构造方法参数为图片文件地址

//创建管理容器对象   JLabel 将图片对象icon放入
JLabel jLabel=new Jlabel(icon);

//将容器添加进界面对象jmenuBar中
jmenuBar.add(jLabel);

//指定图片位置




创建图片和管理容器对象代码合并:
JLabel jLabel=new Jlabel(new ImageIcon("C:\\Users\\DDDic\\IdeaProjects\\PuzzleGame\\image\\animal\\animal3\\3.jpg"));

调整图片位置相关代码:

//设置图片位置
//方法参数为:(x坐标,y坐标,图片宽度,图片长度)
jLabel.setBounds(105*j,105*i,105,105); 

//将图片添加入界面中
GameJFrame.getContentPane().add(jLabel);

//getContentPane 方法就是调用下图中红色框表示的容器,将图片加入该容器

调整位置需要在界面初始化代码中增加以下代码:

        this.setAlwaysOnTop(true);  //true 置顶窗口
        this.setLocationRelativeTo(null);  //设置界面初始位置居中


        //取消界面默认的居中放置,将其设置为null,按照x,y轴坐标放置图片
        GameJFrame.setLayout(null);  

原因:图中红色框内是创建界面时自动生成的一个容器,默认状态会将接受的图片或者其他类进行居中放置,因此需要调用方法取消默认的居中放置。

五、添加事件

事件源:按钮/图片/窗体

事件:某些操作  如:鼠标单击  鼠标划入....

监听绑定:当事件源上发生了某个事件,则执行某段代码。

键盘监听:KeyListener      鼠标监听:MouseListener   动作监听:ActionListener

给按钮添加动作事件:

示例代码:

package com.java.ui;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class MyActionListener implements ActionListener {
    @Override
    public void actionPerformed(ActionEvent e) {
        System.out.println("按钮按下了");
    }

}



package com.java.ui;

import javax.swing.*;
import java.util.Random;

public class Test {
    public static void main(String[] args){


        JFrame jframe=new JFrame();  //创建界面对象
        jframe.setSize(500,500);

        jframe.setLayout(null);

        //创建一个按钮对象
        JButton jtb=new JButton("点击按钮");
        //设置坐标位置
        jtb.setBounds(0,0,100,50);
        //给按钮添加动作监听  方法参数为ActionListener 接口类型,因此需要使用这个接口的实现类 表示触发后执行的代码
        jtb.addActionListener(new MyActionListener());
        //将按钮加入界面中
        jframe.getContentPane().add(jtb);


        jframe.setVisible(true);


    }
}

由于实际情况中,每个按钮功能不一样,且动作监听接口的实现类只会在触发时被调用一次,因此可以采用 匿名内部类的形式进行简化代码:

package com.java.ui;

import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Random;

public class Test {
    public static void main(String[] args){


        JFrame jframe=new JFrame();  //创建界面对象
        jframe.setSize(500,500);

        jframe.setLayout(null);

        //创建一个按钮对象
        JButton jtb=new JButton("点击按钮");
        //设置坐标位置
        jtb.setBounds(0,0,100,50);
        //给按钮添加动作监听  方法参数为ActionListener 接口类型,
        //因此需要使用这个接口的实现类 表示触发后执行的代码
        jtb.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                System.out.println("按钮被按咯");
            }
        });
        //将按钮加入界面中
        jframe.getContentPane().add(jtb);


        jframe.setDefaultCloseOperation(3);
        
        jframe.setVisible(true);


    }
}

除此以外还有另一种方式:

package com.java.ui;

import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Random;

public class MyJFrame extends JFrame implements ActionListener {

    //创建一个按钮对象
    JButton jtb=new JButton("点击按钮1");
    //创建另一个按钮对象
    JButton jtb2=new JButton("点击按钮2");
    public MyJFrame(){
        this.setSize(500,500);

        this.setLayout(null);

        //设置坐标位置
        jtb.setBounds(0,0,100,50);
        jtb2.setBounds(100,0,100,50);
        //给按钮添加动作监听  方法参数为ActionListener 接口类型,因此需要使用这个接口的实现类 来执行实现类中设定的触发后的执行代码
        //而本类已经是ActionListener接口的实现类,因此this记录的就是本类地址,直接进入本类中对应重写执行代码部分,执行触发代码。
        jtb.addActionListener(this);
        jtb2.addActionListener(this);

        //将按钮加入界面中
        this.getContentPane().add(jtb);
        this.getContentPane().add(jtb2);

        this.setDefaultCloseOperation(3);

        this.setVisible(true);
    }




    @Override
    public void actionPerformed(ActionEvent e) {
        //对当前按钮进行判断
        Random r=new Random();
        Object source=e.getSource();//getSource()方法:获取当前被操作的按钮对象
        if(source==jtb)
            jtb.setSize(200,200);//设置按钮大小
        else if(source==jtb2)
            jtb2.setBounds(r.nextInt(500),r.nextInt(500),100,50);
    }
}
package com.java.ui;

public class Test {
    public static void main(String[] args){
        new MyJFrame();

    }
}

给按钮添加鼠标事件:

package com.java.ui;

import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.util.Random;

public class MyJFrame extends JFrame implements MouseListener {



    public MyJFrame(){

        this.setSize(500,500);

       //创建一个按钮对象
        JButton jtb=new JButton("点击按钮1");

        this.setLayout(null);

        //设置按钮坐标位置
        jtb.setBounds(0,0,100,50);

        //给按钮绑定鼠标监听  本类就是MouseListener接口的实现类,因此直接用this代表实现类
        jtb.addMouseListener(this);

        this.getContentPane().add(jtb);



        this.setVisible(true);
    }


    @Override
    public void mouseClicked(MouseEvent e) {
        System.out.println("单击");
    }

    @Override
    public void mousePressed(MouseEvent e) {
        System.out.println("按下不松");
    }

    @Override
    public void mouseReleased(MouseEvent e) {
        System.out.println("松开");
    }

    @Override
    public void mouseEntered(MouseEvent e) {
        System.out.println("划入");
    }

    @Override
    public void mouseExited(MouseEvent e) {
        System.out.println("划出");
    }
}


package com.java.ui;


public class Test {
    public static void main(String[] args){
        new MyJFrame();

    }
}

给窗体添加键盘事件:

package com.java.ui;

import javax.swing.*;
import java.awt.event.*;
import java.util.Random;

public class MyJFrame extends JFrame implements KeyListener {



    public MyJFrame(){
        this.setSize(500,500);

        this.setLayout(null);

       //给窗口增加键盘监听
        this.addKeyListener(this);


        this.setVisible(true);
    }


    @Override
    public void keyTyped(KeyEvent e) {

    }

    //若按下不松,则会重复调用KeyPressed方法
    @Override
    public void keyPressed(KeyEvent e) {
        System.out.println("按下");
    }

    //区分键盘按下的按键是哪一个 使用  getKeyCode方法
    //返回的是每个按键的编号
    @Override
    public void keyReleased(KeyEvent e) {
        System.out.println("松开");
        int code=e.getKeyCode();
        System.out.println((char)code);
    }
}

六、为拼图添加背景图片、为图片添加边框

Tips:

在窗口中添加图片,先添加的图片在上方,后添加的图片在下方,因此背景图片需要放在最后添加进窗口。

添加边框代码:

        //先加载的图片在上方,后加载的图片在下面,背景图片放最后。
        ImageIcon icon=new ImageIcon("C:\\Users\\DDDic\\IdeaProjects\\PuzzleGame\\image\\background.png");
        JLabel jbar=new JLabel(icon);
        //添加边框是对容器类JLabel 的对象调用setBorder()方法
        //BevelBorder()是边框类  参数0表示凸起   1表示凹陷
        // 0也可以用 BevelBorder.RAISED 表示   
        // 1也可以用BevelBorder.LOWERED表示
        jbar.setBorder(new BevelBorder(0));  
        jbar.setBounds(40,40,508,560);
        this.getContentPane().add(jbar);

七、代码路径调整

路径种类:

①绝对路径:从盘符开始 :C:\     D:\

②相对路径:不是从盘符开始 : aaa\bbb     在当前项目下去找aaa文件夹,里面去找bbb文件夹

路径转换:

//绝对路径
JLabel jLabel=new JLabel(new ImageIcon("C:\\Users\\DDDic\\IdeaProjects\\PuzzleGame\\image\\animal\\animal3\\"+number+".jpg"));

//相对路径  从模块名字开始image开始(大家都在一个项目里,没有相对的意义,删去项目名)

JLabel jLabel=new JLabel(new ImageIcon("image\\animal\\animal3\\"+number+".jpg"));

八、拼图移动

通过给界面添加键盘监听来实现:

    public void keyReleased(KeyEvent e) {
        //对上下左右进行判断
        //左37  上38 右39 下40
        int code=e.getKeyCode();
        if(code==37) {
            System.out.println("向左移动");
        }else if(code==38){
            System.out.println("向上移动");
        }else if(code==39){
            System.out.println("向右移动");
        }else if(code==40){
            System.out.println("向下移动");
        }
    }

每次移动都会重新生成移动后的图片,为了避免后续生成的图片被遮盖,每次生成新图片都要清空已经生成的图片+刷新界面:

        jframe.getContentPane().removeAll();    //清除所有界面中图片
 
        //新的图片代码

        jframe.getContentPane().repaint();   //刷新界面内容

九、作弊、查看原图、胜利判定

作弊:

将图片正确排列的次序定义为一个静态数组,在键盘监听函数中设置一个键值,当读取到键值时,直接将当前排列次序数组变为该数组。

    int[][] data=new int[4][4];
    int[][] win=new int[][]{
        {1,2,3,4},
        {5,6,7,8},
        {9,10,11,12},
        {13,14,15,0}
    };

   
 public void keyReleased(KeyEvent e) { 
        if (code == 87) {  // 作弊键值设置为 W
                FinialImage();
            } 
    }

//注意不能直接将win数组赋值给data,数组为引用数据类型,直接赋值是将地址值赋予daata
//会影响后续胜利的判断
    private void FinialImage() {
        data=new int[][]{
                {1,2,3,4},
                {5,6,7,8},
                {9,10,11,12},
                {13,14,15,0}
        };
        x=3;
        y=3;
        InitialImage();
    }

不能直接将win数组赋值给data,数组为引用数据类型,直接赋值是将地址值赋予data,会影响后续胜利的判断。


查看原图:

原理同上

public void keyPressed(KeyEvent e) {
   
            int code = e.getKeyCode();
            if (code == 65) {  //将键值设定为  A
                this.getContentPane().removeAll();    //清除所有界面中图片
                //加载完整图片
                JLabel jLabel = new JLabel(new ImageIcon(path + "all.jpg"));
                jLabel.setBorder(new BevelBorder(1));
                jLabel.setBounds(83, 134, 420, 420);
                this.getContentPane().add(jLabel);
                //加载背景图片
                ImageIcon icon = new ImageIcon("image\\background.png");
                JLabel background = new JLabel(icon);
                background.setBorder(new BevelBorder(1));
                background.setBounds(40, 40, 508, 560);
                this.getContentPane().add(background);
                //刷新界面内容
                this.getContentPane().repaint();

            }
        
    }


public void keyReleased(KeyEvent e) {
        
             if (code == 65)  //A键松开后重新恢复原状
                InitialImage();
         
    }

 胜利判定:

定义一个函数,将数组data 与 win 依次对比,返回boolean变量,前文键盘监听操作都是基于 未胜利 进行,一旦胜利则不再进行对应操作。

    public boolean victory(){
        for(int i=0;i<4;i++){
            for(int j=0;j<4;j++){
                if(data[i][j]!=win[i][j])
                    return false;
            }
        }
        return true;
    }

十、增加菜单条目功能

为条目绑定动作监听,重写动作监听接口中方法:

JMenuItem officialAccount=new JMenuItem("公众号");
officialAccount.addActionListener(this);
   public void actionPerformed(ActionEvent e) {
     //通过 getSource方法来判断 动作监听接收到的信号是哪一个
     //因此条目对象的创建需要写在成员方法中
              Object o=e.getSource();
       if (o == relodGame) {
            System.out.println("重新开始");

        } else if (o == relogIn) {
            System.out.println("重新登录");

        } else if (o == aboutJMenu) {
            System.out.println("关于我们");

        } else if (o == closeGame) {
            System.out.println("关闭游戏");

        } else if (o == officialAccount) {
           //弹出账号二维码
        }
    }

动作监听(多种设计):

弹窗:

//创建弹窗对象  JDialog
            JDialog jDialog=new JDialog();
            JLabel jLabel=new JLabel(new ImageIcon("image//damie.jpg"));
            jLabel.setBounds(0,0,258,258);
            //弹框和界面JFrame一样有隐藏容器,需要调用getContenPane方法再将图片容器添加。
            jDialog.getContentPane().add(jLabel);
            //设置弹框大小
            jDialog.setSize(344,344);
            //弹框置顶
            jDialog.setAlwaysOnTop(true);
            //弹框居中
            jDialog.setLocationRelativeTo(null);
            //不关闭弹框则无法进行下一步操作
            jDialog.setModal(true);
            //显示弹框
            jDialog.setVisible(true);

关闭游戏:

//直接关闭虚拟机
System.exit(0);

重新游戏:

           System.out.println("重新开始");
            //刷新步数
            stepcount=0;
            //初始化数据(将图片顺序打乱)
            InitialData();
            //初始化图片
            InitialImage();

重新登陆:

            System.out.println("重新登录");
            //隐藏当前游戏界面
            this.setVisible(false);
            //打开登录界面
            new LoginJFrame();

十一、密码框对象

明文密码框:

JTextField accountField=new JTextField();

密文密码框:

JPasswordField passwordField=new JPasswordField();

//设置大小
passwordField.setBounds(195,195,200,30);
//添加进窗口容器
JFrame.getContentPane().add(passwordField);



//获取框内字符串
passwordField.getText();

//设置框内字符串内容
passwordField.setText("字符串内容");

十二、完整代码(注册部分涉及到数据库,暂时先放一放)

工具类:

(验证码部分)

package com.java.ui;

import java.util.Random;

public class CodeUtil {
    private CodeUtil(){

    }

    public static String getcode(){
        Random r = new Random();
        char code[] = new char[5];
        int index = r.nextInt(5);
        char number = (char) (r.nextInt(10) + 48);
        for (int i = 0; i < code.length; i++) {
            if (i != index) {
                code[i] = (char) (r.nextInt(26) + 65);
            } else
                code[i] = number;
        }
        String result = new String(code);
        return result;
    }
}

(IO部分) 

import java.io.*;
import java.util.ArrayList;

public class IO {

    public static void Write(ArrayList<User> list,User user) throws IOException {//注册
        ObjectOutputStream oos=new ObjectOutputStream(new FileOutputStream(new File("account.txt")));
        list.add(user);
        oos.writeObject(list);
        oos.close();
    }

    public static void Write(ArrayList<User> list) throws IOException {//注册
        ObjectOutputStream oos=new ObjectOutputStream(new FileOutputStream(new File("account.txt")));
        oos.writeObject(list);
        oos.close();
    }

    public static ArrayList<User> Read() throws IOException, ClassNotFoundException {
        ObjectInputStream ois=new ObjectInputStream(new FileInputStream(new File("account.txt")));
        ArrayList<User> list = (ArrayList<User>) ois.readObject();
        ois.close();
        return  list;
    }

}

游戏窗口类+注册窗口类+登录窗口类+用户类:

游戏窗口类(含读取配置文件):



import javax.swing.*;
import javax.swing.border.BevelBorder;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Properties;
import java.util.Random;


public class GameJFrame extends JFrame implements KeyListener, MouseListener, ActionListener {
    //菜单选项

    JMenu functionJMenu=new JMenu("功能");
    JMenu aboutJMenu=new JMenu("关于我们");


    //选项条目
    //二级菜单  "更换图片"   存档 读档
    JMenu changeImage=new JMenu("更换图片");
    JMenu saveGame=new JMenu("存档");
    JMenu loadGame=new JMenu("读档");
    //存档读档的档位
    JMenuItem save1=new JMenuItem("save1(空)");
    JMenuItem save2=new JMenuItem("save2(空)");
    JMenuItem save3=new JMenuItem("save3(空)");
    JMenuItem save4=new JMenuItem("save4(空)");

    JMenuItem load1=new JMenuItem("save1(空)");
    JMenuItem load2=new JMenuItem("save2(空)");
    JMenuItem load3=new JMenuItem("save3(空)");
    JMenuItem load4=new JMenuItem("save4(空)");
    //更换图片的选项(二级菜单的条目)
    JMenuItem animal=new JMenuItem("动物");
    JMenuItem girls=new JMenuItem("美女");
    JMenuItem sports=new JMenuItem("运动");

    JMenuItem relodGame=new JMenuItem("重新开始");
    JMenuItem relogIn=new JMenuItem("重新登录");
    JMenuItem closeGame=new JMenuItem("关闭游戏");
    JMenuItem officialAccount=new JMenuItem("公众号");
    int[][] data=new int[4][4];
    int[][] win=new int[][]{
            {1,2,3,4},
            {5,6,7,8},
            {9,10,11,12},
            {13,14,15,0}
    };
    int stepcount=0;
    int x,y; //记录空白方块在二维数组中的位置


    //图片分类

    String[] animalArray=new String[]{"image\\animal\\animal1\\","image\\animal\\animal2\\","image\\animal\\animal3\\","image\\animal\\animal4\\",
            "image\\animal\\animal5\\","image\\animal\\animal6\\","image\\animal\\animal7\\","image\\animal\\animal8\\"};
    String[] girlArray=new String[]{"image\\girl\\girl1\\","image\\girl\\girl2\\","image\\girl\\girl3\\","image\\girl\\girl4\\",
            "image\\girl\\girl5\\","image\\girl\\girl6\\","image\\girl\\girl7\\","image\\girl\\girl8\\","image\\girl\\girl9\\","image\\girl\\girl10\\","image\\girl\\girl11\\",
            "image\\girl\\girl12\\","image\\girl\\girl13\\"};
    String[] sportArray=new String[]{"image\\sport\\sport1\\","image\\sport\\sport2\\","image\\sport\\sport3\\","image\\sport\\sport4\\",
            "image\\sport\\sport5\\","image\\sport\\sport6\\","image\\sport\\sport7\\","image\\sport\\sport8\\","image\\sport\\sport9\\","image\\sport\\sport10\\"};


    String path="image\\girl\\girl3\\";
    public GameJFrame() throws IOException, ClassNotFoundException {
        //界面初始化
        InitialJFrame();

        //菜单初始化
        InitialMenu();

        //初始化数据(将图片顺序打乱)
        InitialData();

        //数据同步
        DateSet();

        //初始化图片
        InitialImage();


        //显示/隐藏界面    方法参数为boolean变量,true则显示界面,false隐藏。
        this.setVisible(true);
    }

    private void DateSet() throws IOException, ClassNotFoundException {
        //读取存档文件
        File file=new File("save");
        File[] arr=file.listFiles();
        for (File f : arr) {
            //数据同步,判断是否有存档文件,修改对应菜单
            ObjectInputStream ois=new ObjectInputStream(new FileInputStream(f));
            Gameinfo o = (Gameinfo) ois.readObject();
            int step=o.getStepcount();
            switch (f.getName().substring(4,5)){
                case "1":
                    save1.setText(f.getName().substring(0,5)+"("+step+")");
                    load1.setText(f.getName().substring(0,5)+"("+step+")");
                    break;
                case "2":
                    save2.setText(f.getName().substring(0,5)+"("+step+")");
                    load2.setText(f.getName().substring(0,5)+"("+step+")");
                    break;
                case "3":
                    save3.setText(f.getName().substring(0,5)+"("+step+")");
                    load3.setText(f.getName().substring(0,5)+"("+step+")");
                    break;
                case "4":
                    save4.setText(f.getName().substring(0,5)+"("+step+")");
                    load4.setText(f.getName().substring(0,5)+"("+step+")");
                    break;
            }
        }
        System.out.println(Arrays.toString(arr));

    }


    private void InitialData() {
        int [] tempArr={0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15};
        Random r=new Random();
        for(int i=0;i<16;i++){
            int index=r.nextInt(16-i)+i;
            int temp=tempArr[i];
            tempArr[i]=tempArr[index];
            tempArr[index]=temp;
        }
        int count=0;
        for(int i=0;i<4;i++){
            for(int j=0;j<4;j++){
                data[i][j]=tempArr[count];
                if(data[i][j]==0){
                    x=i;
                    y=j;
                }
                count++;
            }
        }

    }

    private void InitialImage() {//初始化图片代码
        //清空已经生成的图片(先生成的图片在前面,会导致后续操作生成的图片被遮盖)
        this.getContentPane().removeAll();

        if(victory()){
            System.out.println("win!");
            JLabel jlabel=new JLabel(new ImageIcon("image//win.png"));
            jlabel.setBounds(203,283,197,73);
            this.getContentPane().add(jlabel);
        }else{
            this.getContentPane().removeAll();
        }
        JLabel str=new JLabel("步数:"+stepcount);
        str.setBounds(10,0,60,60);
        this.getContentPane().add(str);

        for (int i = 0; i < 4; i++) {
            for (int j = 0; j < 4; j++) {
                int number = data[i][j];
                //创建一个图片ImageIcon的对象  (图片需要放入到JLabel类的容器中,才能添加进界面)
                JLabel jLabel = new JLabel(new ImageIcon(path + number + ".jpg"));
                jLabel.setBorder(new BevelBorder(1));
                jLabel.setBounds(105 * j + 83, 105 * i + 134, 105, 105);
                this.getContentPane().add(jLabel);
                //number==16时,找不到名为16的图片路径,创建的JLabel对象为空白,将其添加到对应位置。
            }
        }
        //先加载的图片在上方,后加载的图片在下面,背景图片放最后。
        ImageIcon icon = new ImageIcon("image\\background.png");
        JLabel background = new JLabel(icon);
        background.setBorder(new BevelBorder(1));
        background.setBounds(40, 40, 508, 560);
        this.getContentPane().add(background);

        //刷新界面
        this.getContentPane().repaint();

    }

    private void InitialMenu() {//菜单初始化代码
        //菜单
        JMenuBar jmenuBar=new JMenuBar();
        //菜单选项

        functionJMenu.addActionListener(this);

        aboutJMenu.addActionListener(this);


        //选项1条目

        changeImage.addActionListener(this);

        relodGame.addActionListener(this);


        relogIn.addActionListener(this);

        closeGame.addActionListener(this);
        //选项2条目

        officialAccount.addActionListener(this);

        //二级菜单条目
        girls.addActionListener(this);
        animal.addActionListener(this);
        sports.addActionListener(this);


        //将二级菜单条目添加到二级菜单中
        changeImage.add(girls);
        changeImage.add(animal);
        changeImage.add(sports);

        loadGame.add(load1);
        loadGame.add(load2);
        loadGame.add(load3);
        loadGame.add(load4);

        saveGame.add(save1);
        saveGame.add(save2);
        saveGame.add(save3);
        saveGame.add(save4);

        load1.addActionListener(this);
        load2.addActionListener(this);
        load3.addActionListener(this);
        load4.addActionListener(this);
        save1.addActionListener(this);
        save2.addActionListener(this);
        save3.addActionListener(this);
        save4.addActionListener(this);


        //将选项1包含的条目添加到选项中
        functionJMenu.add(changeImage);
        functionJMenu.add(relogIn);
        functionJMenu.add(relodGame);
        functionJMenu.add(closeGame);
        functionJMenu.add(saveGame);
        functionJMenu.add(loadGame);
        //将选项2包含的条目添加到选项中
        aboutJMenu.add(officialAccount);

        //将选项添加到菜单中
        jmenuBar.add(functionJMenu);
        jmenuBar.add(aboutJMenu);

        //将菜单添加到界面中
        this.setJMenuBar(jmenuBar);
    }

    private void InitialJFrame() {  //游戏主界面代码
        //创建游戏主界面
        this.setSize(603,680);  //设置界面大小   界面默认隐藏
        //设置标题
        this.setTitle("拼图游戏");
        //设置置顶
        this.setAlwaysOnTop(true);  //true 置顶窗口
        this.setLocationRelativeTo(null);  //设置界面初始位置居中
        this.setDefaultCloseOperation(3);
        //设置关闭模式  参数为int 类型 0:点×啥也不做  1: 默认关闭
        //2:若有多个界面则只有在关闭最后一个界面时虚拟机才会终止,前提:每个界面关闭模式都为2
        // 3:只要关闭其中一个界面,虚拟机直接停止

        //取消默认的居中放置,按照x,y轴的方式放置图片
        this.setLayout(null);

        this.addKeyListener(this);
    }

    @Override
    public void keyTyped(KeyEvent e) {

    }

    @Override
    public void keyPressed(KeyEvent e) {
        if(!victory()) {
            int code = e.getKeyCode();
            if (code == 65) {
                this.getContentPane().removeAll();    //清除所有界面中图片
                //加载完整图片
                JLabel jLabel = new JLabel(new ImageIcon(path + "all.jpg"));
                jLabel.setBorder(new BevelBorder(1));
                jLabel.setBounds(83, 134, 420, 420);
                this.getContentPane().add(jLabel);
                //加载背景图片
                ImageIcon icon = new ImageIcon("image\\background.png");
                JLabel background = new JLabel(icon);
                background.setBorder(new BevelBorder(1));
                background.setBounds(40, 40, 508, 560);
                this.getContentPane().add(background);
                //刷新界面内容
                this.getContentPane().repaint();

            }
        }else return;
    }

    @Override
    public void keyReleased(KeyEvent e) {
        if(!victory()){
            InitialImage();
            //对上下左右进行判断
            //左37  上38 右39 下40
            int code = e.getKeyCode();
            if (code == 37) {
                if (y < 3) {
                    System.out.println("向左移动");
                    //此时空白方块坐标: x,y  右边需要左移的方块坐标 x ,y+1
                    int temp = data[x][y];
                    data[x][y] = data[x][y + 1];
                    data[x][y + 1] = temp;
                    y = y + 1;
                    stepcount++;
                    InitialImage();
                } else {

                }
            } else if (code == 38) {
                if (x < 3) {
                    System.out.println("向上移动");
                    //此时空白方块坐标: x,y  下边需要上移的方块坐标 x+1 ,y
                    int temp = data[x][y];
                    data[x][y] = data[x + 1][y];
                    data[x + 1][y] = temp;
                    x = x + 1;
                    stepcount++;
                    InitialImage();
                } else {

                }
            } else if (code == 39) {
                if (y > 0) {
                    System.out.println("向右移动");
                    //此时空白方块坐标: x,y  左边需要右移的方块坐标 x ,y-1
                    int temp = data[x][y];
                    data[x][y] = data[x][y - 1];
                    data[x][y - 1] = temp;
                    y = y - 1;
                    stepcount++;
                    InitialImage();
                } else {

                }
            } else if (code == 40) {
                if (x > 0) {
                    System.out.println("向下移动");
                    //此时空白方块坐标: x,y  上面需要下移的方块坐标 x-1 ,y
                    int temp = data[x][y];
                    data[x][y] = data[x - 1][y];
                    data[x - 1][y] = temp;
                    x = x - 1;
                    stepcount++;
                    InitialImage();
                }
            } else if (code == 87) {
                FinialImage();
            } else if (code == 65) {
                InitialImage();
            }
        }else return;
    }

    private void FinialImage() {
        stepcount++;
        data=new int[][]{
                {1,2,3,4},
                {5,6,7,8},
                {9,10,11,12},
                {13,14,15,0}
        };
        x=3;
        y=3;
        InitialImage();
    }

    public boolean victory(){
        for(int i=0;i<4;i++){
            for(int j=0;j<4;j++){
                if(data[i][j]!=win[i][j])
                    return false;
            }
        }
        return true;
    }

    @Override
    public void mouseClicked(MouseEvent e) {

    }

    @Override
    public void mousePressed(MouseEvent e) {

    }

    @Override
    public void mouseReleased(MouseEvent e) {

    }

    @Override
    public void mouseEntered(MouseEvent e) {

    }

    @Override
    public void mouseExited(MouseEvent e) {

    }

    @Override
    public void actionPerformed(ActionEvent e) {
        Random r=new Random();
        Object o=e.getSource();
        if (o == relodGame) {
            System.out.println("重新开始");
            stepcount=0;

            //初始化数据(将图片顺序打乱)
            InitialData();

            //初始化图片
            InitialImage();
        } else if (o == relogIn) {
            System.out.println("重新登录");
            this.setVisible(false);
            new LoginJFrame();
            //
        } else if (o == aboutJMenu) {
            System.out.println("关于我们");
            //
        } else if (o == closeGame) {
            System.out.println("关闭游戏");

            //关闭虚拟机
            System.exit(0);
            //
        } else if (o == officialAccount) {
            //读取配置文件信息
            Properties p=new Properties();
            try {
                BufferedReader br=new BufferedReader(new FileReader("game.properties"));
                p.load(br);
                br.close();
            } catch (FileNotFoundException ex) {
                throw new RuntimeException(ex);
            } catch (IOException ex) {
                throw new RuntimeException(ex);
            }
            System.out.println(p);
            //获取路径

            String s=(String)p.get("account");

            //创建弹窗对象  JDialog
            JDialog jDialog=new JDialog();
            JLabel jLabel=new JLabel(new ImageIcon(s));
            jLabel.setBounds(0,0,258,258);
            //弹框和界面JFrame一样有隐藏容器,需要调用getContenPane方法再将图片容器添加。
            jDialog.getContentPane().add(jLabel);
            //设置弹框大小
            jDialog.setSize(344,344);
            //弹框置顶
            jDialog.setAlwaysOnTop(true);
            //弹框居中
            jDialog.setLocationRelativeTo(null);
            //不关闭弹框则无法进行下一步操作
            jDialog.setModal(true);
            //显示弹框
            jDialog.setVisible(true);
        }else if(o==girls){
            //String path="image\\girl\\girl3\\";
            int index=r.nextInt(13)+1;
            path=girlArray[index];

            //重置步数
            stepcount=0;
            //打乱图片
            InitialData();
            //初始化图片
            InitialImage();
        }else if(o==sports){
            int index=r.nextInt(10)+1;
            path=sportArray[index];

            //重置步数
            stepcount=0;
            //打乱图片
            InitialData();
            //初始化图片
            InitialImage();
        }else if(o==animal){
            int index=r.nextInt(8)+1;
            path=animalArray[index];

            //重置步数
            stepcount=0;
            //打乱图片
            InitialData();
            //初始化图片
            InitialImage();
        }else if(o==save1||o==save2||o==save3||o==save4){
            //点击存档按钮  将游戏记录的数据存入到本地文件中
            JMenuItem obj=(JMenuItem)o;
            String text=obj.getText().substring(4,5);
            System.out.println(text);
            Gameinfo gi=new Gameinfo(stepcount,data,path);
            File file=new File("save\\save"+text+".txt");
            ObjectOutputStream oos;
            try {
                oos=new ObjectOutputStream(new FileOutputStream(file));
                oos.writeObject(gi);
                oos.close();
            } catch (IOException ex) {
                throw new RuntimeException(ex);
            }
            obj.setText(obj.getText().substring(0,5)+"("+stepcount+")");
            switch (text){
                case "1":
                    load1.setText(obj.getText().substring(0,5)+"("+stepcount+")");break;
                case "2":
                    load2.setText(obj.getText().substring(0,5)+"("+stepcount+")");break;
                case "3":
                    load3.setText(obj.getText().substring(0,5)+"("+stepcount+")");break;
                case  "4":
                    load4.setText(obj.getText().substring(0,5)+"("+stepcount+")");break;
            }
        }else if(o==load1||o==load2||o==load3||o==load4){
            //点击读档按钮  读取数据
            JMenuItem obj=(JMenuItem)o;
            if(!obj.getText().substring(6,7).equals("空")){
                String text = obj.getText().substring(4,5);
                System.out.println(text);
                File file = new File("save\\save" + text + ".txt");
                ObjectInputStream ois;
                Gameinfo gi;
                try {
                    ois = new ObjectInputStream(new FileInputStream(file));
                    gi = (Gameinfo) ois.readObject();
                    ois.close();
                } catch (IOException ex) {
                    throw new RuntimeException(ex);
                } catch (ClassNotFoundException ex) {
                    throw new RuntimeException(ex);
                }
                data = gi.getDate();
                stepcount = gi.getStepcount();
                path = gi.getPath();
                InitialImage();
            }
        }
    }
}

 注册窗口类:



import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.io.*;
import java.util.ArrayList;
import java.util.Scanner;

public class RegisterJFrame extends JFrame implements ActionListener, MouseListener {

    Scanner sc=new Scanner(System.in);
    //账号输入框(明文输入框)
    JTextField accountField=new JTextField(1);
    //注册密码输入框(明文)
    JTextField passwordField=new JTextField(1);
    //再次输入密码框(明文)
    JTextField rePasswordField=new JTextField(1);

    //注册+重置按钮
    JButton registerButton=new JButton();
    JButton initialButton=new JButton();


    public RegisterJFrame(){

        InitialRegisterJFrame();

        InitialImage();

        this.setVisible(true);
    }

    private void InitialRegisterJFrame() {
        //创建注册界面
        this.setSize(488,430);
        this.setTitle("注册");
        this.setAlwaysOnTop(true);  //true 置顶窗口
        this.setLocationRelativeTo(null);  //设置界面初始位置居中
        this.setDefaultCloseOperation(3);
        this.setLayout(null);//取消内部默认布局
    }

    private void InitialImage(){
        //去除容器内所有图片
        this.getContentPane().removeAll();

        //注册密码图片+注册账号图片
        JLabel registerAccount=new JLabel(new ImageIcon("image\\register\\注册用户名.png"));
        registerAccount.setBounds(110,135,79,17);
        this.getContentPane().add(registerAccount);
        JLabel registerPassword=new JLabel(new ImageIcon("image\\register\\注册密码.png"));
        registerPassword.setBounds(125,195,64,16);
        this.getContentPane().add(registerPassword);
        JLabel registerRePassword=new JLabel(new ImageIcon("image\\register\\再次输入密码.png"));
        registerRePassword.setBounds(95,255,96,17);
        this.getContentPane().add(registerRePassword);

        //输入框
        accountField.setBounds(195,134,200,30);
        this.getContentPane().add(accountField);
        passwordField.setBounds(195,195,200,30);
        this.getContentPane().add(passwordField);
        rePasswordField.setBounds(195,255,200,30);
        this.getContentPane().add(rePasswordField);

        //注册按钮 + 重置按钮
        registerButton.setIcon(new ImageIcon("image\\register\\注册按钮.png"));
        registerButton.setBounds(123,310,128,47);
        initialButton.setIcon(new ImageIcon("image\\register\\重置按钮.png"));
        initialButton.setBounds(256,310,128,47);
        //删除按钮边框
        registerButton.setBorderPainted(false);
        initialButton.setBorderPainted(false);
        //删除按钮背景
        registerButton.setContentAreaFilled(false);
        initialButton.setContentAreaFilled(false);
        //绑定动作监听
        registerButton.addMouseListener(this);
        initialButton.addMouseListener(this);
        this.getContentPane().add(registerButton);
        this.getContentPane().add(initialButton);



        //背景图片
        JLabel jLabel=new JLabel(new ImageIcon("image\\register\\background.png"));
        jLabel.setBounds(0,0,470,390);
        this.getContentPane().add(jLabel);

        this.getContentPane().repaint();
    }

    @Override
    public void actionPerformed(ActionEvent e) {
    }

    @Override
    public void mouseClicked(MouseEvent e) {
        Object o=e.getSource();
        if(o==registerButton){
            String account=accountField.getText();
            String password=passwordField.getText();
            String password2=rePasswordField.getText();
           if(password2.equals(password)){
                User user = new User(account, password,0);
                ArrayList<User> list;
                try {
                    list = IO.Read();
                    IO.Write(list, user);
                } catch (IOException | ClassNotFoundException ex) {
                    throw new RuntimeException(ex);
                }

                showJDialog("注册成功!");
                this.setVisible(false);
                new LoginJFrame();
            }else{
               showJDialog("两次输入密码不一致!");
           }
        }else if(o==initialButton){
            passwordField.setText("");
            rePasswordField.setText("");
            accountField.setText("");
        }
    }

    public void showJDialog(String content){
        JDialog jDialog=new JDialog();
        JLabel jLabel=new JLabel(content); //创建 字符串 的JLabel容器对象
        jLabel.setBounds(0,0,200,150);
        jDialog.add(jLabel);
        jDialog.setSize(200,150);
        jDialog.setAlwaysOnTop(true);  //置顶
        jDialog.setLocationRelativeTo(null);  //居中
        jDialog.setModal(true); //设置不关闭则无法进行其他操作
        jDialog.setVisible(true);
    }

    @Override
    public void mousePressed(MouseEvent e) {
        Object o=e.getSource();
        if(o==registerButton){
            registerButton.setIcon(new ImageIcon("image\\register\\注册按下.png"));
        }else if(o==initialButton){
            initialButton.setIcon(new ImageIcon("image\\register\\重置按下.png"));
        }
    }

    @Override
    public void mouseReleased(MouseEvent e) {
        Object o=e.getSource();
        if(o==registerButton){
            registerButton.setIcon(new ImageIcon("image\\register\\注册按钮.png"));
        }else if(o==initialButton){
            initialButton.setIcon(new ImageIcon("image\\register\\重置按钮.png"));
        }
    }

    @Override
    public void mouseEntered(MouseEvent e) {

    }

    @Override
    public void mouseExited(MouseEvent e) {

    }
}

登录窗口类:

import javax.swing.*;
import java.awt.event.*;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;

public class LoginJFrame extends JFrame implements MouseListener, KeyListener , ActionListener {

    //成员变量处定义,方便监听判断
    JButton logIn=new JButton();
    JButton register=new JButton();

    //账号输入框(明文输入框类  JTextField)    (密文输入框类  JPasswordField)
    JTextField accountField=new JTextField(1);
    JPasswordField passwordField=new JPasswordField(1);
    //获取验证码
    String code=CodeUtil.getcode();
    //验证码输入框
    JTextField verifycodefield=new JTextField(1);

    //验证码显示区
    JLabel rightCode=new JLabel(code);
    public LoginJFrame(){

        Scanner sc=new Scanner(System.in);

        initialJFrame();

        initialImage();

        this.setVisible(true);
    }

    private void initialImage() {

        this.getContentPane().removeAll();

        accountField.setBounds(195,134,200,30);
        this.getContentPane().add(accountField);

        //密码输入框
        passwordField.setBounds(195,195,200,30);
        passwordField.addActionListener(this);
        this.getContentPane().add(passwordField);

        verifycodefield.setBounds(195,256,50,30);
        this.getContentPane().add(verifycodefield);

        //添加验证码显示区
        rightCode.setBounds(300,256,50,30);
        rightCode.addMouseListener(this);
        this.getContentPane().add(rightCode);

        //添加登录  注册按钮 +  按钮绑定鼠标监听
        logIn.setIcon(new ImageIcon("image\\login\\登录按钮.png"));
        logIn.setBounds(123,310,128,47);
        logIn.addMouseListener(this);
        register.setIcon(new ImageIcon("image\\login\\注册按钮.png"));
        register.setBounds(256,310,128,47);
        register.addMouseListener(this);

        //去除按钮边框
        logIn.setBorderPainted(false);
        register.setBorderPainted(false);
        //去除按钮背景
        logIn.setContentAreaFilled(false);
        register.setContentAreaFilled(false);
        //显示
        this.getContentPane().add(logIn);
        this.getContentPane().add(register);


        JLabel account=new JLabel(new ImageIcon("image\\login\\用户名.png"));
        account.setBounds(116,135,47,17);
        this.getContentPane().add(account);

        JLabel password=new JLabel(new ImageIcon("image\\login\\密码.png"));
        password.setBounds(130,195,32,16);
        this.getContentPane().add(password);

        JLabel verifycode=new JLabel(new ImageIcon("image\\login\\验证码.png"));
        verifycode.setBounds(110,256,56,21);
        this.getContentPane().add(verifycode);

        //添加背景图片
        //将背景图片加入容器
        JLabel jLabel=new JLabel(new ImageIcon("image\\login\\background.png"));
        jLabel.setBounds(0,0,470,390);
        //调用隐藏容器,再加入图片容器
        this.getContentPane().add(jLabel);

        this.getContentPane().repaint();
    }

    private void initialJFrame() {
        this.setSize(488,430);
        this.setTitle("登录");
        this.setAlwaysOnTop(true);  //true 置顶窗口
        this.setLocationRelativeTo(null);  //设置界面初始位置居中
        this.setDefaultCloseOperation(3);
        this.setLayout(null);//取消内部默认布局
    }

    public void checkAccountPassword() throws IOException, ClassNotFoundException {
        if(verifycodefield.getText().equalsIgnoreCase(code)){
            if(LoginTest.login(accountField.getText(),new String(passwordField.getPassword()))) {
                this.setVisible(false);
                new GameJFrame();
            }
        }else showJDialog("验证码错误!");
    }

    public void showJDialog(String content){
        JDialog jDialog=new JDialog();
        JLabel jLabel=new JLabel(content); //创建 字符串 的JLabel容器对象
        jLabel.setBounds(0,0,200,150);
        jDialog.add(jLabel);
        jDialog.setSize(200,150);
        jDialog.setAlwaysOnTop(true);  //置顶
        jDialog.setLocationRelativeTo(null);  //居中
        jDialog.setModal(true); //设置不关闭则无法进行其他操作
        jDialog.setVisible(true);
    }



    @Override
    public void mouseClicked(MouseEvent e) {

        Object o=e.getSource();
        if(o==logIn){
            try {
                checkAccountPassword();
            } catch (IOException ex) {
                throw new RuntimeException(ex);
            } catch (ClassNotFoundException ex) {
                throw new RuntimeException(ex);
            }
        }else if(o==rightCode){
            code=CodeUtil.getcode();
            rightCode=new JLabel(code);
            initialImage();
        }else if(o==register){
            this.setVisible(false);
            new RegisterJFrame();
        }
    }

    @Override
    public void mousePressed(MouseEvent e) {

        Object o=e.getSource();
        if(o==logIn){
            logIn.setIcon(new ImageIcon("image\\login\\登录按下.png"));
        }else if(o==register){
            register.setIcon(new ImageIcon("image\\login\\注册按下.png"));
        }
    }

    @Override
    public void mouseReleased(MouseEvent e) {
        Object o=e.getSource();
        if(o==logIn){
            logIn.setIcon(new ImageIcon("image\\login\\登录按钮.png"));
        }else if(o==register){
            register.setIcon(new ImageIcon("image\\login\\注册按钮.png"));
        }
    }

    @Override
    public void mouseEntered(MouseEvent e) {
        Object o=e.getSource();
        if(o==logIn){

        }
    }

    @Override
    public void mouseExited(MouseEvent e) {

        Object o=e.getSource();
        if(o==logIn){
        }
    }

    @Override
    public void keyTyped(KeyEvent e) {

    }

    @Override
    public void keyPressed(KeyEvent e) {

    }

    @Override
    public void keyReleased(KeyEvent e) {

    }

    @Override
    public void actionPerformed(ActionEvent e) {

    }
}

用户类: 

import java.io.Serializable;

public class User implements Serializable {
    private String account;
    private String password;

    private int count;
    public User(){

    }
    public User(String account,String password,int count){
        this.account=account;
        this.password=password;
        this.count=count;
    }

    /**
     * 获取
     * @return account
     */
    public String getAccount() {
        return account;
    }

    /**
     * 设置
     * @param account
     */
    public void setAccount(String account) {
        this.account = account;
    }

    /**
     * 获取
     * @return password
     */
    public String getPassword() {
        return password;
    }

    /**
     * 设置
     * @param password
     */
    public void setPassword(String password) {
        this.password = password;
    }

    public String toString() {
        return "account=" + account + "&password=" + password+"&count="+count;
    }

    /**
     * 获取
     * @return count
     */
    public int getCount() {
        return count;
    }

    /**
     * 设置
     * @param count
     */
    public void setCount(int count) {
        this.count = count;
    }
}

 登录小程序:

import java.io.*;
import java.util.ArrayList;


public class LoginTest {
    public static boolean login(String account,String password) throws IOException, ClassNotFoundException {


        //提取记录文件中的数据
        ArrayList<User> userlist = IO.Read();
        ArrayList<String> list=new ArrayList<>();
        for (User user : userlist) {
            list.add(user.toString());
        }

        System.out.println(list);  //[account=jin&password=woaini&count=0, account=zhang&password=buaini&count=0]

        for(int i=0;i<list.size();i++) {
            if (list.get(i).split("&")[0].split("=")[1].equals(account)) {
                //账号匹配上了
                int count = Integer.parseInt(list.get(i).split("&")[2].split("=")[1]);//统计次数
                if (count == 2) {
                    System.out.println("账号已经被锁定");
                    return false;
                } else {//没有锁定
                    if (list.get(i).split("&")[1].split("=")[1].equals(password)) {
                        //密码正确
                        //将集合中数据重新写入本地文件
                        IO.Write(userlist);
                        System.out.println("登录成功");
                        return true;
                    } else {
                        //密码错误  计数器+1
                        System.out.println("密码错误");
                        String info = list.get(i).substring(0, list.get(i).length() - 1);  //account=jin&password=woaini&count=
                        userlist.get(i).setCount(count + 1); //对用户数组进行修改 计数器+1
                        list.set(i, info + (count + 1));
                        return false;
                    }
                }
            }
        }
            //账号没有匹配上
            System.out.println("账号不存在");
            return false;
    }

}

主函数:

import java.io.*;

public class Main {


    public static void main(String[] args) throws IOException, ClassNotFoundException {
        //主程序启动入口
        new LoginJFrame();
        //预设的几个账号
        /*
        User user1=new User("jinluhao","1212",0);
        User user2=new User("jinluha","1212",0);
        User user3=new User("jinluh","1212",0);
        ArrayList<User> list=new ArrayList<>();
        list.add(user1);
        list.add(user2);
        list.add(user3);

        ObjectOutputStream oos=new ObjectOutputStream(new FileOutputStream(new File("account.txt")));
        oos.writeObject(list);
        oos.close();

        System.out.println(list);

         */
    }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值