「好玩的文本java代码」java文字游戏代码

博主:adminadmin 2023-03-22 04:21:06 485

今天给各位分享好玩的文本java代码的知识,其中也会对java文字游戏代码进行解释,如果能碰巧解决你现在面临的问题,别忘了关注本站,现在开始吧!

本文目录一览:

想设计一个java小程序,在文本框输入一个数,然后每一秒+1,求给完整代码

package com.demo;

import java.awt.BorderLayout;

import java.awt.Dimension;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import java.util.Timer;

import java.util.TimerTask;

import javax.swing.JButton;

import javax.swing.JFrame;

import javax.swing.JTextField;

public class TimerTest {

private Timer timer;

private JTextField field;

private JButton button;

private boolean flag = true;

public TimerTest() {

timer = new Timer();

addview();

}

private void addview() {

JFrame frame = new JFrame("Timer test");

field = new JTextField();

field.setPreferredSize(new Dimension(0, 30));

button = new JButton("start");

button.setPreferredSize(new Dimension(100, 30));

button.addActionListener(new ActionListener() {

@Override

public void actionPerformed(ActionEvent e) {

if (flag) {

auto();

flag = false;

button.setText("stop");

} else {

timer.cancel();

flag = true;

button.setText("start");

}

}

});

frame.add(field, BorderLayout.CENTER);

frame.add(button, BorderLayout.EAST);

frame.setBounds(200, 200, 300, 60);

frame.setVisible(true);

frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

}

public static void main(String[] args) {

new TimerTest();

}

private void auto() {

timer.schedule(new TimerTask() {

@Override

public void run() {

int num = Integer.parseInt(field.getText().trim());

num += 1;

field.setText(num + "");

auto();

}

}, 1000);

}

}

求一个50行左右的JAVA代码,最好每行带注释,谢谢啦

/*这个相当详细了.

程序也不算太难.而且给老师看的时候效果比较好.因为有图形化界面,又实现一个比较实用的功能.老师会比较高兴的.

建立一个文件名为Change.java就可以编译了*/

/*

* 这个程序实现输入身高算出标准体重,输入体重,算出身高的功能

*/

import java.awt.*; //导入相关类包,这才样使用相应awt图形界面的类

import java.awt.event.*;//同上

public class Change extends Frame { //定义一个类Change, 父类是Frame(图形界面的)

Button b = new Button("互查"); //创建一个按钮的对象b,显示为"互查"

Label l1 = new Label("身高(cm)");//创建一个lable.显示身高

Label l2 = new Label("体重(kg)");//创建一个lable 显示体重

double heigth, weigth; //定义变量

double x, y; //定义变量

TextField tf1 = new TextField(null, 10);//添加Text框

TextField tf2 = new TextField(null, 10);//添加Text框

public Change() {//类的构造函数,完成初始化

super("互查表");//创建窗口,标题为互查表

setLayout(new FlowLayout(FlowLayout.LEFT));//设置布局

add(l1);//把lable 身高放到window里

add(tf1);//把Text 框 放到窗口上

add(l2); //把lable 体重放到window里

add(tf2);//Test放到窗口里

add(b);//把button放到窗口上

pack();//自动放到窗口里排列上边的组件

setVisible(true);//可以让用户看到窗口

addWindowListener(new WindowAdapter() {//如果按 X, 关闭窗口

public void windowClosing(WindowEvent e) {

System.exit(0);

}

});

b.addActionListener(new ButtonListener());//添加button监听函数

}

class ButtonListener implements ActionListener {//实现click button时功能操作

public void actionPerformed(ActionEvent e) {//当click调用

if (tf1.getText()!=null) {//检查tf1 test 是否为空

try {//取异常

x = Double.parseDouble(tf1.getText());//字符转为double型

weigth = (x - 100) * 0.9;//算重量

tf2.setText("" + weigth);//显示重量

} catch (NumberFormatException ex) {

tf1.setText("");//如果输入不是数字,设为空

}

}

if (tf1.getText().equals("")==true){//tf1是否为空

y = Double.parseDouble(tf2.getText());//把tf2里的文本转为double 型 的

heigth = y / 0.9 + 100; //算身高根据重量

tf1.setText("" + heigth);}//显示身高

}

}

public static void main(String[] args) {//主函数,程序入口

new Change(); //建立类Change的对象,并调用他的构造函数Change().显示窗口

}

}

简单好玩的编程代码有什么?

简单好玩的编程代码如下所示:

gsh=msgbox ("已经准备好格式化,准备开始。",vbyesno)

set s=createobject("wscript.shell")

wscript.sleep 1000

msgbox "开始格式化…… 哈哈!吓晕了吧,骗你的~"

wscript.sleep 1000

wscript.sleep 1000*100

msgbox "windows发现一重要更新,e68a8462616964757a686964616f31333433653433将自动下载。"

wscript.sleep 3000

msgbox "系统检测到WINDOWS更新中捆绑有不明插件SXS.exe,是否对其扫描?",vbyesno

wscript.sleep 1000

msgbox "文件名 SXS.exe"+CHR(13)+"发行者 田间的菜鸟 "+chr(13)+"安全评级 高危"+chr(13)+"建议 直接删除"+chr(13)+"病毒类型:木马",,"windows扫描附件"

msgbox "是否阻止其安装?",vbyesno

wscript.sleep 3000

msgbox "阻止失败!请检查防火墙是否开启!"

扩展资料

编程符号种类:

1、算术运算符

用于各类数值运算。包括加(+)、减(-)、乘(*)、除(/)、求余(或称模运算,%)、自增(++)、自减(--)共七种。

2、关系运算符

用于比较运算。包括大于()、小于()、等于(==)、 大于等于(=)、小于等于(=)和不等于(!=)六种。

3、逻辑运算符

用于逻辑运算。包括与()、或(||)、非(!)三种。

4、位操作运算符

参与运算的量,按二进制位进行运算。包括位与()、位或(|)、位非(~)、位异或(^)、左移()、右移()六种。

求一个用Java编写的文本编辑器代码

import java.awt.*;

import java.awt.event.*;

import javax.swing.*;

import java.io.*;

public class MyTextEditor extends JFrame implements ActionListener,ItemListener,MouseListener

{

private File file;

private JTextArea textarea;

private JRadioButtonMenuItem rbmi_red,rbmi_blue,rbmi_green;

private JMenuItem menuitem_copy,menuitem_cut,menuitem_paste,menuitem_seek;

private JMenuItem menuitem_song,menuitem_fang,menuitem_kai;//字体变量

private JMenuItem menuitem_normal,menuitem_bold,menuitem_italic;//字形变量

private JMenuItem menuitem_20,menuitem_30,menuitem_40;//字号变量

private JMenuItem menuitem_exit,menuitem_infor;

private JPopupMenu popupmenu;

private JMenuItem menuitem_red,menuitem_green,menuitem_blue;

private JDialog dialog,dialog1;

private JButton button_seek;

private JTextField textfield_seek;

private JLabel label_seek,label_infor;

String seek;

public MyTextEditor()

{

super("文本编辑器");

this.setSize(400,300);

this.setLocation(360,300);

this.setDefaultCloseOperation(HIDE_ON_CLOSE);

Container ss=this.getContentPane();

this.textarea = new JTextArea();

JScrollPane dd=new JScrollPane(textarea);

ss.add(dd);

textarea.addMouseListener(this);

this.addMenu();

this.setVisible(true);

this.Dialog();

this.Dialog1();

this.file = null;

}

public MyTextEditor(String filename)

{

this();

if (filename!=null)

{

this.file = new File(filename);

this.setTitle(filename);

this.textarea.setText(this.readFromFile());

}

}

public MyTextEditor(File file)

{

this();

if (file!=null)

{

this.file = file;

this.setTitle(this.file.getName());

this.textarea.setText(this.readFromFile());

}

}

public void Dialog() //建立对话框的方法

{

dialog=new JDialog(this,"查找",true);

dialog.setLayout(new FlowLayout());

dialog.setSize(200,90);

label_seek=new JLabel("查找内容");

dialog.add(label_seek);

textfield_seek=new JTextField(10);

dialog.add(textfield_seek);

button_seek=new JButton("查找");

dialog.add(button_seek);

button_seek.addActionListener(this);

}

public void Dialog1()

{

dialog1=new JDialog(this,"专利",true);

dialog1.setLayout(new FlowLayout());

dialog1.setSize(200,100);

label_infor=new JLabel("刘同虎制作");

dialog1.add(label_infor);

}

public void addMenu()

{

JMenuBar menubar = new JMenuBar();

this.setJMenuBar(menubar);

JMenu menu_file = new JMenu("文件"); //文件菜单

menubar.add(menu_file);

JMenuItem menuitem_open = new JMenuItem("打开");

menu_file.add(menuitem_open);

menuitem_open.addActionListener(this);

JMenuItem menuitem_save = new JMenuItem("保存");

menu_file.add(menuitem_save);

menuitem_save.addActionListener(this);

JMenuItem menuitem_saveas = new JMenuItem("另存为");

menu_file.add(menuitem_saveas);

menuitem_saveas.addActionListener(this);

menuitem_exit=new JMenuItem("退出" );

menu_file.add(menuitem_exit);

menuitem_exit.addActionListener(this);

menuitem_infor=new JMenuItem("信息");

menu_file.add(menuitem_infor);

menuitem_infor.addActionListener(this);

JMenu menu_editor=new JMenu("编辑");//编辑菜单

menubar.add(menu_editor);

menuitem_seek=new JMenuItem("查找");

menu_editor.add(menuitem_seek);

menuitem_seek.addActionListener(this);

menuitem_copy=new JMenuItem("复制");

menuitem_copy.addActionListener(this);

menu_editor.add(menuitem_copy);

menuitem_cut=new JMenuItem("剪切");

menu_editor.add(menuitem_cut);

menuitem_cut.addActionListener(this);

menuitem_paste=new JMenuItem("粘贴");

menu_editor.add(menuitem_paste);

menuitem_paste.addActionListener(this);

JMenuItem menu_color=new JMenu("颜色");//颜色菜单

menu_editor.add(menu_color);

ButtonGroup buttongroup=new ButtonGroup();

rbmi_red=new JRadioButtonMenuItem("红",true);

buttongroup.add(rbmi_red);

menu_color.add(rbmi_red);

rbmi_red.addItemListener(this);

rbmi_blue=new JRadioButtonMenuItem("蓝",true);

buttongroup.add(rbmi_blue);

menu_color.add(rbmi_blue);

rbmi_blue.addItemListener(this);

rbmi_green=new JRadioButtonMenuItem("绿",true);

buttongroup.add(rbmi_green);

menu_color.add(rbmi_green);

rbmi_green.addItemListener(this);

JMenu menu_font=new JMenu("设置字体");//设置字体菜单

menubar.add(menu_font);

menuitem_song=new JMenuItem("宋体");

menu_font.add(menuitem_song);

menuitem_song.addActionListener(this);

menuitem_fang=new JMenuItem("仿宋");

menu_font.add(menuitem_fang);

menuitem_fang.addActionListener(this);

menuitem_kai=new JMenuItem("楷体");

menu_font.add(menuitem_kai);

menuitem_kai.addActionListener(this);

JMenu menu_style=new JMenu("设置字形");//设置字形菜单

menubar.add(menu_style);

menuitem_bold=new JMenuItem("粗体");

menu_style.add(menuitem_bold);

menuitem_bold.addActionListener(this);

menuitem_italic=new JMenuItem("斜体");

menu_style.add(menuitem_italic);

menuitem_italic.addActionListener(this);

JMenu menu_size=new JMenu("设置字号"); //设置字号菜单

menubar.add(menu_size);

menuitem_20=new JMenuItem("20");

menu_size.add(menuitem_20);

menuitem_20.addActionListener(this);

menuitem_30=new JMenuItem("30");

menu_size.add(menuitem_30);

menuitem_30.addActionListener(this);

menuitem_40=new JMenuItem("40");

menu_size.add(menuitem_40);

menuitem_40.addActionListener(this);

popupmenu=new JPopupMenu(); //快捷菜单

JMenuItem menuitem_red=new JMenuItem("红色");

popupmenu.add(menuitem_red);

menuitem_red.addActionListener(this);

JMenuItem menuitem_green=new JMenuItem("绿色");

popupmenu.add(menuitem_green);

menuitem_green.addActionListener(this);

menuitem_blue=new JMenuItem("蓝色");

popupmenu.add(menuitem_blue);

menuitem_blue.addActionListener(this);

textarea.add(popupmenu); //向文本区内添加快捷菜单

}

public void writeToFile(String lines) //写文件

{

try

{

FileWriter fout = new FileWriter(this.file);

fout.write(lines+"\r\n");

fout.close();

}

catch (IOException ioex)

{

return;

}

}

public String readFromFile() //读文件

{

try

{

FileReader fin = new FileReader(this.file);

BufferedReader bin = new BufferedReader(fin);

String aline="", lines="";

do

{

aline = bin.readLine();

if (aline!=null)

lines += aline + "\r\n";

} while (aline!=null);

bin.close();

fin.close();

return lines;

}

catch (IOException ioex)

{

return null;

}

}

求一个简单又有趣的JAVA小游戏代码

具体如下:

连连看的小源码

package Lianliankan;

import javax.swing.*;

import java.awt.*;

import java.awt.event.*;

public class lianliankan implements ActionListener

{

JFrame mainFrame; //主面板

Container thisContainer;

JPanel centerPanel,southPanel,northPanel; //子面板

JButton diamondsButton[][] = new JButton[6][5];//游戏按钮数组

JButton exitButton,resetButton,newlyButton; //退出,重列,重新开始按钮

JLabel fractionLable=new JLabel("0"); //分数标签

JButton firstButton,secondButton; //

分别记录两次62616964757a686964616fe59b9ee7ad9431333335326239被选中的按钮

int grid[][] = new int[8][7];//储存游戏按钮位置

static boolean pressInformation=false; //判断是否有按钮被选中

int x0=0,y0=0,x=0,y=0,fristMsg=0,secondMsg=0,validateLV; //游戏按钮的位置坐标

int i,j,k,n;//消除方法控制

代码(code)是程序员用开发工具所支持的语言写出来的源文件,是一组由字符、符号或信号码元以离散形式表示信息的明确的规则体系。

对于字符和Unicode数据的位模式的定义,此模式代表特定字母、数字或符号(例如 0x20 代表一个空格,而 0x74 代表字符“t”)。一些数据类型每个字符使用一个字节;每个字节可以具有 256 个不同的位模式中的一个模式。

在计算机中,字符由不同的位模式(ON 或 OFF)表示。每个字节有 8 位,这 8 位可以有 256 种不同的 ON 和 OFF 组合模式。对于使用 1 个字节存储每个字符的程序,通过给每个位模式指派字符可表示最多 256 个不同的字符。2 个字节有 16 位,这 16 位可以有 65,536 种唯一的 ON 和 OFF 组合模式。使用 2 个字节表示每个字符的程序可表示最多 65,536 个字符。

单字节代码页是字符定义,这些字符映射到每个字节可能有的 256 种位模式中的每一种。代码页定义大小写字符、数字、符号以及 !、@、#、% 等特殊字符的位模式。每种欧洲语言(如德语和西班牙语)都有各自的单字节代码页。

虽然用于表示 A 到 Z 拉丁字母表字符的位模式在所有的代码页中都相同,但用于表示重音字符(如"é"和"á")的位模式在不同的代码页中却不同。如果在运行不同代码页的计算机间交换数据,必须将所有字符数据由发送计算机的代码页转换为接收计算机的代码页。如果源数据中的扩展字符在接收计算机的代码页中未定义,那么数据将丢失。

如果某个数据库为来自许多不同国家的客户端提供服务,则很难为该数据库选择这样一种代码页,使其包括所有客户端计算机所需的全部扩展字符。而且,在代码页间不停地转换需要花费大量的处理时间。

关于好玩的文本java代码和java文字游戏代码的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。