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

云南网站seo外包织梦网站怎么修改内容

云南网站seo外包,织梦网站怎么修改内容,网站开发所需要的技术,东莞哪家网站建设专业Java学习笔记#xff08;新手纯小白向#xff09; 第一章 JAVA基础概念 第二章 JAVA安装和环境配置 第三章 IntelliJ IDEA安装 第四章 运算符 第五章 运算符联系 第六章 判断与循环 第七章 判断与循环练习 第八章 循环高级综合 第九章 数组介绍及其内存图 第十章 数…Java学习笔记新手纯小白向 第一章 JAVA基础概念 第二章 JAVA安装和环境配置 第三章 IntelliJ IDEA安装 第四章 运算符 第五章 运算符联系 第六章 判断与循环 第七章 判断与循环练习 第八章 循环高级综合 第九章 数组介绍及其内存图 第十章 数组基础练习 第十一章 方法基础及简单应用 第十二章 方法基础练习 第十三章 前续知识综合练习 第十四章 面向对象基础 第十五章 面向对象综合训练 第十六章 字符串基础 第十七章 字符串基础练习 第十八章 ArrayList集合 第十九章 ArrayList集合基础练习 第二十章 面向对象进阶 第二十一章 面向对象进阶基础练习 第二十二章 阶段项目——拼图小游戏 目录 Java学习笔记新手纯小白向 前言 代码示例 一、UI界面搭建 1.游戏主界面 2.登录界面 3.注册界面 二、业务逻辑编写  1.用户类 2.生成验证码的工具类 三、游戏主入口 四、游戏打包exe说明 总结 前言 本篇章主要展示了阶段项目——拼图小游戏该项目基本包括了之前所学的所有知识点可以很好得巩固所学知识点。 代码示例 一、UI界面搭建 1.游戏主界面 //创建游戏主界面 public class GameJFrame extends JFrame implements KeyListener, ActionListener {//创建获取随机数的对象Random r new Random();//定义二维数组记录图片的编号int[][] imageCode new int[4][4];//定义二维数组记录胜利后图片的编号int[][] win new int[][]{{1, 2, 3, 4},{5, 6, 7, 8},{9, 10, 11, 12},{13, 14, 15, 0}};//定义变量x和y记录空白方块在二维数组中的位置int x 0;int y 0;//定义变量path记录当前加载图片的相对路径String path gigsawgame\\image\\animal\\animal1\\;//定义变量step记录移动的步数int step 0;//创建选项下的条目对象JMenuItem replayItem new JMenuItem(重新游戏);JMenuItem reLoginItem new JMenuItem(重新登录);JMenuItem closeItem new JMenuItem(关闭游戏);JMenuItem rewardItem new JMenuItem(谢谢打赏);JMenuItem girlItem new JMenuItem(美女);JMenuItem animalItem new JMenuItem(动物);JMenuItem sportsItem new JMenuItem(运动);//定义空参构造对界面进行初始化public GameJFrame() {//初始化游戏主界面initJFrame();//初始化菜单initJMenuBar();//初始化数据initImageCode();//初始化图片initImage();//设置界面是否显示建议写在最后this.setVisible(true);}//打乱图片编号private void initImageCode() {//定义一维数组记录图片编号int[] tempArr {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15};//打乱数组中号码的顺序for (int i 0; i tempArr.length; i) {//获取随机索引int index r.nextInt(tempArr.length);//进行数据交换int temp tempArr[i];tempArr[i] tempArr[index];tempArr[index] temp;}//定义变量index记录一维数组的索引int index 0;//将打乱后的一维数组中的编号添加到二维数组中for (int i 0; i imageCode.length; i) {for (int j 0; j imageCode[i].length; j) {if (tempArr[index] 0) {x i;y j;}imageCode[i][j] tempArr[index];index;}}}//将图片加载到界面中private void initImage() {//清空已经出现的图片this.getContentPane().removeAll();//如果胜利加载胜利图片if (victory()) {JLabel winJLabel new JLabel(new ImageIcon(gigsawgame\\image\\win.png));winJLabel.setBounds(203, 283, 197, 73);this.getContentPane().add(winJLabel);}//加载步数计数器JLabel stepCount new JLabel(步数 step);stepCount.setBounds(50, 30, 100, 20);this.getContentPane().add(stepCount);//使用循环添加每一行图片for (int i 0; i 4; i) {//使用循坏添加每一列图片for (int j 0; j 4; j) {//定义变量code记录图片编号int code imageCode[i][j];//创建ImageIcon图片对象并创建JLabel管理容器JLabel jLabel new JLabel(new ImageIcon(path code .jpg));//指定图片位置jLabel.setBounds(105 * j 83, 105 * i 134, 105, 105);//给图片添加边框jLabel.setBorder(new BevelBorder(BevelBorder.LOWERED));//将JLabel管理容器添加到界面中将JLabel管理容器添加到隐藏容器之中this.getContentPane().add(jLabel);}}//添加背景图片(后添加的在下方)JLabel background new JLabel(new ImageIcon(gigsawgame\\image\\background.png));background.setBounds(40, 40, 508, 560);this.getContentPane().add(background);//刷新界面this.getContentPane().repaint();}//设置菜单栏基础信息private void initJMenuBar() {//创建菜单栏对象JMenuBar jMenuBar new JMenuBar();//创建菜单上面的两个选项功能、关于我们JMenu functionJMenu new JMenu(功能);JMenu aboutJMenu new JMenu(关于我们);//创建功能选项中的更换图片选项JMenu replaceImage new JMenu(更换图片);//匹配选项与条目//匹配功能选项与其条目functionJMenu.add(replaceImage);functionJMenu.add(replayItem);functionJMenu.add(reLoginItem);functionJMenu.add(closeItem);//匹配功能选项下的更换图片选项与其条目replaceImage.add(girlItem);replaceImage.add(animalItem);replaceImage.add(sportsItem);//匹配关于我们选项与其条目aboutJMenu.add(rewardItem);//给条目绑定事件replayItem.addActionListener(this);reLoginItem.addActionListener(this);closeItem.addActionListener(this);rewardItem.addActionListener(this);girlItem.addActionListener(this);animalItem.addActionListener(this);sportsItem.addActionListener(this);//将选项添加到菜单栏中jMenuBar.add(functionJMenu);jMenuBar.add(aboutJMenu);//设置界面菜单栏this.setJMenuBar(jMenuBar);}//设置界面基础信息private void initJFrame() {//设置界面的宽高this.setSize(603, 680);//设置界面的标题this.setTitle(拼图单机版 v1.0);//设置界面置顶this.setAlwaysOnTop(true);//设置界面居中this.setLocationRelativeTo(null);//设置关闭模式this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);//取消默认的居中放置this.setLayout(null);//添加游戏操作给整个界面添加键盘监听事件this.addKeyListener(this);}//空实现keyTyped方法Overridepublic void keyTyped(KeyEvent e) {}//实现键盘按下不松按键操作方法查看完整图片Overridepublic void keyPressed(KeyEvent e) {//定义变量keyCode记录按下按键的值int keyCode e.getKeyCode();if (keyCode 65) {//清空之前的图片this.getContentPane().removeAll();//加载完整图片JLabel jLabel new JLabel(new ImageIcon(path all.jpg));jLabel.setBounds(83, 134, 420, 420);this.getContentPane().add(jLabel);//加载背景图片JLabel background new JLabel(new ImageIcon(gigsawgame\\image\\background.png));background.setBounds(40, 40, 508, 560);this.getContentPane().add(background);}//重新加载图片this.getContentPane().repaint();}//实现键盘松开按键操作方法使图片可以左上右下移动及一键通关Overridepublic void keyReleased(KeyEvent e) {//如果游戏胜利则结束方法if (victory()) {return;}//定义变量keyCode记录按键的值int keyCode e.getKeyCode();//对按键进行判断做出对应行为switch (keyCode) {//左键操作case 37 - {//判断是否为空白方块是否位于最右侧if (y 3) {return;} else {imageCode[x][y] imageCode[x][y 1];imageCode[x][y 1] 0;y;//移动一次步数增加一次step;}//调用方法initImage重新加载图片initImage();}//上键操作case 38 - {//判断是否为空白方块是否位于最下侧if (x 3) {return;} else {imageCode[x][y] imageCode[x 1][y];imageCode[x 1][y] 0;x;//移动一次步数增加一次step;}//调用方法initImage重新加载图片initImage();}//右键操作case 39 - {//判断是否为空白方块是否位于最左侧if (y 0) {return;} else {imageCode[x][y] imageCode[x][y - 1];imageCode[x][y - 1] 0;y--;//移动一次步数增加一次step;}//调用方法initImage重新加载图片initImage();}//下键操作case 40 - {//判断是否为空白方块是否位于最上侧if (x 0) {return;} else {imageCode[x][y] imageCode[x - 1][y];imageCode[x - 1][y] 0;x--;//移动一次步数增加一次step;}//调用方法initImage重新加载图片initImage();}//松开A键恢复之前的打乱效果case 65 - {initImage();}//松开按键W实现一键通关case 87 - {imageCode new int[][]{{1, 2, 3, 4},{5, 6, 7, 8},{9, 10, 11, 12},{13, 14, 15, 0}};initImage();}}}//定义方法victory判断游戏是否胜利public boolean victory() {for (int i 0; i imageCode.length; i) {for (int j 0; j imageCode[i].length; j) {if (imageCode[i][j] ! win[i][j]) {return false;}}}return true;}//给菜单栏中选项下的条目对象绑定事件Overridepublic void actionPerformed(ActionEvent e) {//获取被点击的条目对象Object clickItem e.getSource();//判断并执行if (clickItem replayItem) {//步数归零step 0;//重新打乱图片编号initImageCode();//重新加载图片initImage();} else if (clickItem reLoginItem) {//关闭当前游戏界面this.setVisible(false);//打开登录界面new LoginJFrame();} else if (clickItem closeItem) {//关闭虚拟机System.exit(0);} else if (clickItem rewardItem) {//创建一个弹框对象JDialog jDialog new JDialog();//创建图片管理容器JLabelJLabel jLabel new JLabel(new ImageIcon(gigsawgame\\image\\reward.jpg));//设置管理容器的位置和宽高jLabel.setBounds(0, 0, 514, 514);//把管理容器添加到弹框中jDialog.getContentPane().add(jLabel);//设置弹框的大小jDialog.setSize(600, 600);//设置弹框置顶jDialog.setAlwaysOnTop(true);//设置弹框居中jDialog.setLocationRelativeTo(null);//弹窗不关闭则无法操作下面的界面jDialog.setModal(true);//让弹窗显示jDialog.setVisible(true);} else if (clickItem girlItem) {//步数归零step 0;//随机获取美女图片编号int beautyCode r.nextInt(13) 1;path gigsawgame\\image\\girl\\girl beautyCode \\;//重新打乱图片编号initImageCode();//重新加载图片initImage();} else if (clickItem animalItem) {//步数归零step 0;//随机获取动物图片编号int animalCode r.nextInt(8) 1;path gigsawgame\\image\\animal\\animal animalCode \\;//重新打乱图片编号initImageCode();//重新加载图片initImage();} else if (clickItem sportsItem) {//步数归零step 0;//随机获取运动图片编号int sportsCode r.nextInt(10) 1;path gigsawgame\\image\\sport\\sport sportsCode \\;//重新打乱图片编号initImageCode();//重新加载图片initImage();}} } 2.登录界面 //创建登录界面 public class LoginJFrame extends JFrame implements MouseListener {//数据初始化//创建集合user存储正确的用户名和密码static ArrayListUser users new ArrayList();static {users.add(new User(张三, 123));users.add(new User(李四, abc));}//加载用户名、密码和验证码输入框JTextField usernameField new JTextField();JPasswordField passwordField new JPasswordField();JTextField iCodeField new JTextField();//加载显示密码按钮、登录按钮、注册按钮和验证码内容管理器JButton passwordVisible new JButton();JButton loginButton new JButton();JButton registerButton new JButton();JLabel rightCode new JLabel();//加载正确验证码String rightICode ICodeUtil.getCode();//定义空参构造对界面进行初始化public LoginJFrame() {//初始化登录主界面initJFrame();//初始化图片、输入框及按钮initTextButton();//设置界面是否显示建议写在最后this.setVisible(true);}//设置输入框、按钮及图片private void initTextButton() {//清空已经出现的图片、输入框及按钮this.getContentPane().removeAll();//加载输入框基础图片JLabel usernameImage new JLabel(new ImageIcon(gigsawgame\\image\\login\\用户名.png));usernameImage.setBounds(105, 129, 47, 17);JLabel passwordImage new JLabel(new ImageIcon(gigsawgame\\image\\login\\密码.png));passwordImage.setBounds(112, 202, 32, 16);JLabel iCodeImage new JLabel(new ImageIcon(gigsawgame\\image\\login\\验证码.png));iCodeImage.setBounds(100, 274, 56, 21);//设置用户名、密码和验证码输入框的基础信息usernameField.setBounds(200, 123, 150, 29);passwordField.setBounds(200, 196, 150, 29);iCodeField.setBounds(200, 270, 75, 29);//设置正确验证码内容管理器的基础信息rightCode.setText(rightICode);rightCode.setBounds(275, 270, 75, 29);//设置显示密码按钮、登录按钮和注册按钮的基础信息passwordVisible.setBounds(332, 196, 18, 29);passwordVisible.setIcon(new ImageIcon(gigsawgame\\image\\login\\显示密码.png));loginButton.setBounds(64, 320, 128, 47);loginButton.setIcon(new ImageIcon(gigsawgame\\image\\login\\登录按钮.png));registerButton.setBounds(275, 320, 128, 47);registerButton.setIcon(new ImageIcon(gigsawgame\\image\\login\\注册按钮.png));//去除按钮的默认边框及背景passwordVisible.setBorderPainted(false);passwordVisible.setContentAreaFilled(false);loginButton.setBorderPainted(false);loginButton.setContentAreaFilled(false);registerButton.setBorderPainted(false);registerButton.setContentAreaFilled(false);//加载背景图片JLabel background new JLabel(new ImageIcon(gigsawgame\\image\\login\\background.png));background.setBounds(0, 0, 470, 390);//给按钮及验证码内容管理器绑定事件rightCode.addMouseListener(this);passwordVisible.addMouseListener(this);loginButton.addMouseListener(this);registerButton.addMouseListener(this);//将图片、输入框及按钮添加到界面中this.getContentPane().add(usernameImage);this.getContentPane().add(usernameField);this.getContentPane().add(passwordImage);this.getContentPane().add(passwordVisible);this.getContentPane().add(passwordField);this.getContentPane().add(iCodeImage);this.getContentPane().add(iCodeField);this.getContentPane().add(rightCode);this.getContentPane().add(loginButton);this.getContentPane().add(registerButton);this.getContentPane().add(background);//刷新界面this.getContentPane().repaint();}//设置界面基础信息private void initJFrame() {//设置界面的宽高this.setSize(488, 430);//设置界面的标题this.setTitle(用户登录);//设置界面置顶this.setAlwaysOnTop(true);//设置界面居中this.setLocationRelativeTo(null);//设置关闭模式this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);//取消默认的居中放置this.setLocationRelativeTo(null);}//展示用户名或密码错误提示弹窗private void tipJDialog(String tip) {//创建弹窗JDialog tipJDialog new JDialog();//设置弹窗大小tipJDialog.setSize(200, 150);//设置弹窗置顶tipJDialog.setAlwaysOnTop(true);//设置弹窗居中tipJDialog.setLocationRelativeTo(null);//设置弹窗不关闭无法操作下方界面tipJDialog.setModal(true);//添加提示内容JLabel tips new JLabel(tip);tips.setBounds(0, 0, 200, 150);tipJDialog.getContentPane().add(tips);//使弹窗可见tipJDialog.setVisible(true);}//实现按钮的鼠标监听事件方法Overridepublic void mouseClicked(MouseEvent e) {//获取点击的按钮Object source e.getSource();//根据点击按钮不同做出相应操作if (source rightCode) {//更换一个新的验证码rightICode ICodeUtil.getCode();rightCode.setText(rightICode);}}Overridepublic void mousePressed(MouseEvent e) {//获取按下的按钮Object source e.getSource();//根据按下按钮不同做出相应操作if (source passwordVisible) {//切换显示密码按钮的背景图片passwordVisible.setIcon(new ImageIcon(gigsawgame\\image\\login\\显示密码按下.png));} else if (source loginButton) {//切换登录按钮的背景图片loginButton.setIcon(new ImageIcon(gigsawgame\\image\\login\\登录按下.png));} else if (source registerButton) {//切换注册按钮的背景图片registerButton.setIcon(new ImageIcon(gigsawgame\\image\\login\\注册按下.png));}}Overridepublic void mouseReleased(MouseEvent e) {//获取松开的按钮Object source e.getSource();//根据松开按钮不同做出相应操作if (source passwordVisible) {//恢复显示密码按钮的背景图片passwordVisible.setIcon(new ImageIcon(gigsawgame\\image\\login\\显示密码.png));} else if (source loginButton) {//获取用户输入的用户名密码验证码String username usernameField.getText();String password passwordField.getText();String iCode iCodeField.getText();//判断验证码是否正确//判断用户名和密码是否为空//判断用户名、密码是否正确if (iCode.equalsIgnoreCase(rightICode)) {if (username.length() ! 0 || password.length() ! 0) {if (contains(username, password)){new GameJFrame();}else {tipJDialog(用户名或密码错误);}} else {tipJDialog(用户名或者密码为空);}} else {tipJDialog(验证码输入错误);//更换一个新的验证码rightICode ICodeUtil.getCode();rightCode.setText(rightICode);}//恢复登录按钮的背景图片loginButton.setIcon(new ImageIcon(gigsawgame\\image\\login\\登录按钮.png));} else if (source registerButton) {//恢复注册按钮的背景图片registerButton.setIcon(new ImageIcon(gigsawgame\\image\\login\\注册按钮.png));}}//判断用户在集合中是否存在public boolean contains(String username, String password) {for (int i 0; i users.size(); i) {if (username.equals(users.get(i).getUsername()) password.equals(users.get(i).getPassword())) {return true;}}return false;}Overridepublic void mouseEntered(MouseEvent e) {}Overridepublic void mouseExited(MouseEvent e) {} }3.注册界面 //创建注册界面 public class RegisterJFrame extends JFrame {//定义空参构造对界面进行初始化public RegisterJFrame() {//初始化注册主界面initJFrame();//初始化图片及输入框}//设置界面基础信息private void initJFrame() {//设置界面的宽高this.setSize(488, 500);//设置界面的标题this.setTitle(用户注册);//设置界面置顶this.setAlwaysOnTop(true);//设置界面居中this.setLocationRelativeTo(null);//设置关闭模式this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);//取消默认的居中放置this.setLocationRelativeTo(null);//设置界面是否显示建议写在最后this.setVisible(true);} }二、业务逻辑编写  1.用户类 public class User {//定义用户的属性private String username;private String password;//定义空参构造和带参构造public User() {}public User(String username, String password) {this.username username;this.password password;}//定义所有成员变量的get和set方法public String getUsername() {return username;}public void setUsername(String username) {this.username username;}public String getPassword() {return password;}public void setPassword(String password) {this.password password;} }2.生成验证码的工具类 public class ICodeUtil {//私有化空参构造private ICodeUtil() {}//定义静态方法getCode获取验证码public static String getCode() {//创建获取随机数的对象Random r new Random();//创建字符数组存储验证码char[] code new char[5];//随机添加一个数字code[0] (char) (r.nextInt(10) 48);//定义字符数组存储大小写字母char[] letter new char[52];//将大小写字母添加进letter字符数组for (int i 0; i letter.length; i) {if (i 26) {letter[i] (char) (97 i - 26);} else {letter[i] (char) (65 i);}}//随机将大小写字母加入code字符数组for (int i 1; i code.length; i) {code[i] letter[r.nextInt(letter.length)];}//将数组中的字符打乱char temp;int index 0;for (int i 0; i code.length; i) {index r.nextInt(code.length - 1);temp code[i];code[i] code[index];code[index] temp;}return new String(code);} }三、游戏主入口 //程序的启动入口 public class App {public static void main(String[] args) {//想开启哪个界面就创建谁的对象 // new RegisterJFrame();new LoginJFrame(); // new GameJFrame();} }四、游戏打包exe说明 说明文本及工具在百度网盘中。链接: https://pan.baidu.com/s/1QxUXy_1ksPxfZ5xYvJQwnQ?pwd0806 提取码: 0806 若过期请在评论区留言。 总结 拼图小游戏有助于了解Java的GUI相关知识但在以后并不常用了解即可。因此该项目的重中之重还是游戏的业务逻辑及对所学知识的巩固。
http://www.dnsts.com.cn/news/102789.html

相关文章:

  • 做详情页比较好的网站怎么找wordpress博客
  • 合肥做装修哪个网站好w3school
  • 长沙营销网站设计沈阳seo优化
  • 实验室网站制作软件开发技术培训课程
  • 龙江做网站网站建设 王卫洲
  • 网站项目建设合同龙华城市建设局网站
  • 一台vps主机可以建设多少个网站手机网站制作费用
  • 网站搭建功能需求wordpress密码登录插件
  • 电子元器件网站怎么做电脑系统做的好的网站
  • 做一个网站做少多少钱湖南省建设厅气源适配性目录2022
  • 用来做网站的软件上海网站建设电
  • 网站无障碍建设标准网站推荐货源
  • 微网站怎么注册wordpress插件h5
  • 企业网站建设存在的不足与困难文章wordpress
  • 网站地图如何更新给女朋友做情侣网站的程序员
  • 使用cms快速搭建商业网站注册小公司
  • 可视化建站源码wordpress多个菜单menu
  • 哈尔滨专业网站建设哪个好蓝色系网站首页
  • ps做的网站怎么到网站上预览济南seo网站推广公司
  • dede更新网站阿里云 wordpress 500
  • 医学院英文网站建设方案局域网内的网站建设
  • 西双网站建设南海佛山网站建设
  • h5开发和前端开发区别东莞seo网站推广
  • 中国商标网商标查询网巩义网站优化培训
  • 皮具网站建设策划书施工企业管理杂志官网
  • 烟台城乡建设局网站网站建设颜色注意事项
  • 网站样式下载百度排名 网站标题
  • 网站建设怎么选公司我做微信淘宝客网站有哪些
  • 广州建设工程造价管理站深圳工作服制作
  • 小企业网站建设哪些好办郑州哪个公司专业做网站