
正文
java画月亮代码 python代码画月亮
提示:扫一扫查出行【扫一扫了解最新限行尾号】
复制提示
Java编写月亮程序
给你写java画月亮代码了个简单java画月亮代码的测试java画月亮代码,基本能实现你所描述java画月亮代码的
package com.bobo.thread;
import java.awt.*;
import javax.swing.*;
public class Test extends JFrame implements Runnable {
static int i = 10;
static int j = 440;
public Test() {
this.setSize(500, 500);
this.setVisible(true);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public void paint(Graphics g) {
super.paint(g);
g.setColor(Color.BLACK);
g.fillRect(0, 0, 500, 500);
g.setColor(Color.white);
g.fillOval(i, j, 60, 60);
g.setColor(Color.BLACK);
g.fillOval(i - 20, j - 20, 60, 60);
}
public void run() {
while (true) {
try {
Thread.sleep(500);
} catch (InterruptedException e) {
e.printStackTrace();
}
if (i = 155) {
i += 5;
j += 15;
}
if (i 155) {
i += 5;
j -= 15;
}
if (i = 305) {
i = 10;
j = 440;
}
System.out.println(i + " " + j);
this.repaint();
}
}
public static void main(String args[]) {
new Thread(new Test()).start();
}
}
相关问答
Q1: 画一个月亮,使月亮整体移动,先升起在落下。用java编写
推荐一个方法,你试试,首先先用java的Graphics类画一个月亮,然后使用Graphics2D的translate(int dx, int dy)的方法,参数是新点的坐标,然后在新的位置重新画月亮
Q2: java中,画一个月亮,最初在左下方,先慢慢沿45°上升,到顶时再慢慢沿45°下降到右下方。
public void draw(Graphics2D g) {
g.setColor(color);//设置颜色
g.setStroke(stroke);//宽度
int x, y, w, h;
if (startX endX) {//以下的startx 、endx都是由鼠标拖 动事件得到
x = endX;
w = startX - endX;
} else {
x = startX;
w = endX - startX;
}
if (startY endY) {
y = endY;
h = startY - endY;
} else {
y = startY;
h = endY - startY;
}
g.drawOval(x, y, w, h);
}
关于java画月亮代码和python代码画月亮的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。






