H5小游戏源码和微信小程序源码100套
在本文中,我们将解释在Java中构建微信小程序游戏源码的基本方法。要在窗口中打印字符串,我们将使用java.awt包中的 drawString()方法。drawString 方法接受三个参数:
完整源码:y.wxlbyx.icu
绘制字符串(字符串,x,y)
string:此参数采用要显示的字符串。
x:此参数采用x坐标,字符串将在屏幕上显示。
y:此参数采用y坐标,字符串将
在屏幕上显示。
我们将在 (x, y)坐标处打印字符串,然后更新x坐标,然后再次重新绘制屏幕。
java.awt安装步骤:
对于 Windows:(x64)
下载并安装适用于 Windows 64 位的最新稳定版 JRE 和 JDK。
下载并安装适用于 Windows 64 位的最新稳定版 Eclipse。
从 http://jnetpcap.com/download 下载 jNetPcap 的稳定版本(用于 64 位 Windows)。
提取 .rar 文件。
解压后,将其数据链接库(jnetpcap.dll)复制到具有管理权限的system32文件夹中。
现在打开 Eclipse,创建项目。右键单击项目,转到属性,转到 java build
路径,单击 Add External jars 并提供 jnetpcap.jar 的路径。
编写程序并运行。
对于 Linux:(x64)
首选 Ubuntu 14.04 或 16, .04(稳定版)。它包含 java 作为操作系统安装的默认值。
安装 eclipse-full,如果找不到,它将自动安装最新支持的 java。(从命令行或软件中心)
安装 g++ 和 libpcap-dev(从命令行安装,因为如果它
不是更新的,它不会出现在软件中心)。
从 http://jnetpcap.com/download 下载 jNetPcap 的稳定版本(用于 64 位 Linux)。
提取 .rar 文件。
解压后,将 libjnetpcap.so 和 libjnetpcap-pcap100.so 复制到 /usr/lib/(作为 sudo)。
现在打开 Eclipse,创建项目。右键单击项目,转到属性,转到 java 构建
路径,单击添加外部 jar 并提供 jnetpcap.jar 的路径。
编写程序并运行。
/*
*/
// Java Code to implement Moving text using
// applet and thread.
import java.awt.*;
import java.applet.*;
public class GFG extends Applet implements Runnable {
private String display;
private int x, y, flag;
Thread t;
// initializing
// called when the applet is
// started.
public void init()
{
display = "GeeksforGeeks";
x = 100;
y = 100;
flag = 1;
// creating thread
t = new Thread(this, "MyThread");
// start thread
t.start();
}
// update the x co-ordinate
public void update()
{
x = x + 10 * flag;
if (x > 300)
flag = -1;
if (x < 100)
flag = 1;
}
// run
public void run()
{
while (true) {
// Repainting the screen
// calls the paint function
repaint();
update();
try {
// creating a pause of 1 second
// so that the movement is recognizable
Thread.sleep(1000);
}
catch (InterruptedException ie) {
System.out.println(ie);
}
}
}
// drawString
public void paint(Graphics g)
{
g.drawString(display, x, y);
}
}
注意:上述函数是 java.awt 包的一部分,属于java.awt.Graphics 类。此外,这些代码可能无法在在线编译器中运行,请使用离线编译器。程序员可以根据需要更改 x 和 y 坐标。