Java Swing猜英文单词游戏(java+面向对象编程+swing+awt+io流)

简介: Java Swing猜英文单词游戏(java+面向对象编程+swing+awt+io流)

一、直接上运行效果

猜测成功的界面:

猜测失败的界面:

二、技术栈

java+面向对象编程+swing+awt+io流

三、项目结构

四、部分代码

主程序入口类 WordleApp.java

/*
 * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
 * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
 */
package wordlegame;
import java.io.File;
import java.util.ArrayList;
import java.util.Random;
import java.util.Scanner;
public class WordleApp {
    public static void main(String[] args) {
        try{
            ArrayList<String> CommonWords = new ArrayList<>();  // Array list to store words.
            int i = 0;
            File myObj = new File("common1.txt");           //Read words from test file
            Scanner myReader = new Scanner(myObj);        // Scanner object to scan the input file.
            while (myReader.hasNextLine()) {              // While loop till the end of text file.
              String data = myReader.nextLine();          // Read each line from text file one by one.
              CommonWords.add(data.toLowerCase().trim());       // Add words one-by-one in the array list.
            }
            myReader.close();
            ArrayList<String> Words = new ArrayList<>();
            myObj = new File("words1.txt");           //Read words from test file
            myReader = new Scanner(myObj);        // Scanner object to scan the input file.
            while (myReader.hasNextLine()) {              // While loop till the end of text file.
              String data = myReader.nextLine();          // Read each line from text file one by one.
              Words.add(data.toLowerCase().trim());       // Add words one-by-one in the array list.
            }
            myReader.close();
            Random rand = new Random();                   //Create instance of random to get random number form the list.    
            int upperbound = CommonWords.size()-1;              // set the upperlimit for the random number to be generated.
            int int_random = rand.nextInt(upperbound);    // Generate random number.
            String actualWord =CommonWords.get(int_random);     // Get word form the list.
            System.out.println("Your have total 6 attempts to predict the word"); 
                System.err.println(actualWord);   // actual word uncomment the line if want to keep track.
            WordleModel m = new WordleModel(false,0,0,actualWord,"",Words,false,false);  //Initialize model.
            WordleView v = new WordleView(); //Create instance of View.
            WordleController c = new WordleController(m, v); //Create instance of controller.
            c.initController(); //Initialize controller.
            System.out.println(actualWord);
            System.out.println();
        }
        catch(Exception ex){
            System.out.println(ex);
        }
       }
}

Indexes.java类

/*
 * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
 * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
 */
package wordlegame;
import java.awt.Color;
public class Indexes{
        public int index;
        public Color color;
        public Indexes(int index, Color color){
            this.index = index;
            this.color = color;
        }
    }

五、源码地址

https://download.csdn.net/download/weixin_43860634/87784529


相关文章
|
10月前
|
监控 Java API
现代 Java IO 高性能实践从原理到落地的高效实现路径与实战指南
本文深入解析现代Java高性能IO实践,涵盖异步非阻塞IO、操作系统优化、大文件处理、响应式网络编程与数据库访问,结合Netty、Reactor等技术落地高并发应用,助力构建高效可扩展的IO系统。
281 0
|
7月前
|
Java Unix Go
【Java】(8)Stream流、文件File相关操作,IO的含义与运用
Java 为 I/O 提供了强大的而灵活的支持,使其更广泛地应用到文件传输和网络编程中。!但本节讲述最基本的和流与 I/O 相关的功能。我们将通过一个个例子来学习这些功能。
290 3
|
Java
Java实现贪吃蛇游戏
本文介绍了如何使用Java实现一个简单的贪吃蛇游戏。
760 4
|
9月前
|
Java 测试技术 API
Java IO流(二):文件操作与NIO入门
本文详解Java NIO与传统IO的区别与优势,涵盖Path、Files类、Channel、Buffer、Selector等核心概念,深入讲解文件操作、目录遍历、NIO实战及性能优化技巧,适合处理大文件与高并发场景,助力高效IO编程与面试准备。
|
10月前
|
存储 Java Linux
操作系统层面视角下 Java IO 的演进路径及核心技术变革解析
本文从操作系统层面深入解析Java IO的演进历程,涵盖BIO、NIO、多路复用器及Netty等核心技术。分析各阶段IO模型的原理、优缺点及系统调用机制,探讨Java如何通过底层优化提升并发性能与数据处理效率,全面呈现IO技术的变革路径与发展趋势。
207 2
|
9月前
|
SQL Java 数据库连接
Java IO流(一):字节流与字符流基础
本文全面解析Java IO流,涵盖字节流、字符流及其使用场景,帮助开发者理解IO流分类与用途,掌握文件读写、编码转换、异常处理等核心技术,通过实战案例提升IO编程能力。
|
9月前
|
设计模式 人工智能 前端开发
现代 Java 实现数字华容道与石头迷阵游戏的项目实战及项目开发指南
本项目基于Java 17+,采用JavaFX与MVC架构,实战开发数字华容道/石头迷阵游戏。内容涵盖技术选型、核心逻辑、现代GUI设计、动画实现及项目打包发布,结合sealed class、record等新特性,打造简洁可维护的游戏代码结构。
326 0
|
10月前
|
机器学习/深度学习 存储 Java
Java 大视界 -- Java 大数据机器学习模型在游戏用户行为分析与游戏平衡优化中的应用(190)
本文探讨了Java大数据与机器学习模型在游戏用户行为分析及游戏平衡优化中的应用。通过数据采集、预处理与聚类分析,开发者可深入洞察玩家行为特征,构建个性化运营策略。同时,利用回归模型优化游戏数值与付费机制,提升游戏公平性与用户体验。
|
存储 网络协议 安全
Java网络编程,多线程,IO流综合小项目一一ChatBoxes
**项目介绍**:本项目实现了一个基于TCP协议的C/S架构控制台聊天室,支持局域网内多客户端同时聊天。用户需注册并登录,用户名唯一,密码格式为字母开头加纯数字。登录后可实时聊天,服务端负责验证用户信息并转发消息。 **项目亮点**: - **C/S架构**:客户端与服务端通过TCP连接通信。 - **多线程**:采用多线程处理多个客户端的并发请求,确保实时交互。 - **IO流**:使用BufferedReader和BufferedWriter进行数据传输,确保高效稳定的通信。 - **线程安全**:通过同步代码块和锁机制保证共享数据的安全性。
596 23