java 求大神帮我写个小程序,谢谢!(必定追加分数,我只想把分数留给对我有帮助的大神。。3Q!)
程序给你了,里面有注释。你是学软件的文档和程序部署我就不写了,不会自己百度。
这个很简单啊,i首先是1,因为++i会先将i加一,然后将加一后的值赋给i,所以j=++i*++i变成j=2*++i,然后i再++,就变成了j=2*3,结果就是6
import java.awt.Container;
import java.awt.Dimension;
import java.awt.Graphics;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class Curve extends JFrame {
private Circle circle = new Circle();
/**
* 构造函数
*/
public Curve() {
setTitle("DrawCurve[绘制一份沿着曲线运动的圆形]");
MyPanel panel = new MyPanel();
Container contentPane = getContentPane();
contentPane.add(panel);
pack();
}
public static void main(String[] args) {
Curve c = new Curve();
c.setVisible(true);
}
/**
*
* Circle 主要功能为:圆 记录当前圆的x坐标,y坐标和圆半径
*
*/
public class Circle {
int x = 0;
int y = 0;
int r = 15;
public int getX() {
return x;
}
public void setX(int x) {
this.x = x;
}
public int getY() {
return y;
}
public void setY(int y) {
this.y = y;
}
public int getR() {
return r;
}
public void setR(int r) {
this.r = r;
}
}
public class MyPanel extends JPanel {
private static final int WIDTH = 480;
private static final int HEIGHT = 480;
public MyPanel() {
this.setPreferredSize(new Dimension(WIDTH, HEIGHT));
Thread thread = new Thread() {
public void run() {
while (true) {
repaint();
try {
Thread.sleep(300);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
};
thread.start();
}
/**
*
* 根据曲线横坐标获取纵坐标值
*
* @param x
*/
public double getY(int x) {
double a = Math.sin(x * Math.PI / 180);
return (80 + 40 * a);
}
/**
*
* 绘制曲线
*
* @param g
*/
public void drawCurve(Graphics g) {
for (int i = 0; i < this.getWidth(); i++) {
g.drawString("*", i, (int) getY(i));
}
}
@Override
public void paint(Graphics g) {
super.paint(g);
drawCurve(g);
drawCircle(g);
}
/**
*
* 以当前的x坐标画一个圆
*
* @param g
*/
public void drawCircle(Graphics g) {
circle.setX(circle.getX() + 1);
g.fillOval(circle.getX(), (int) getY(circle.getX()), circle.getR(),
circle.getR());
}
}
}
类似于这样的东西么?
import java.applet.Applet;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Image;
public class TestApplet extends Applet implements Runnable {
private int x = 0;
private int y = 0;
private int d = 2;
private int r = 20;
Image buffer;
Graphics bufferg;
boolean flag = true;
/**
*
*/
private static final long serialVersionUID = 1L;
public void init() {
this.setSize(500, 500);
new Thread(this).start();
Dimension d = getSize();
buffer = createImage(d.width, d.height);
}
public void start() {
}
public void paint(Graphics g) {
if (x >= 500) {
g.drawString("OVER", 200, 200);
this.flag = false;
return;
}
if (bufferg == null)
bufferg = buffer.getGraphics();
Dimension d = getSize();
bufferg.setColor(Color.white);
bufferg.fillRect(0, 0, d.width, d.height);
bufferg.setColor(Color.red);
bufferg.fillOval(x, y, r, r);
g.drawImage(buffer, 0, 0, this);
x += this.d;
if(x <= 100){
y = (int) (200 - Math.sqrt(Math.abs(100 * 100 - x * x)));
}else if(x <= 300){
y = (int) (200 - Math.sqrt(Math.abs(100 * 100 - (x - 200) * (x - 200))));
}else if(x <= 500){
y = (int) (200 - Math.sqrt(Math.abs(100 * 100 - (x - 400) * (x - 400))));
}
}
@Override
public void run() {
// TODO Auto-generated method stub
while (flag) {
this.repaint();
try {
Thread.sleep(10);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
你粘过去自己看吧 Applet小程序, 也没什么意思
主要是你的运动轨迹怎么计算
Swing....完全不会
寿莘乌鸡: public class Dog { private int weigth;//成员属性 public Dog(){//无参构造器 } public Dog(int weigth){//有参构造器 this.weigth=weigth; } public int getWeigth() {//返回Dog的重量weigth return weigth; } public void setWeigth(int weigth) {//设置Dog的...
高平市17745896869: 用java写一个小程序求代码: - ?
寿莘乌鸡: 给你一个简单的提示 不是只要For吗 太简单了 你把这个图形用星星补满可以看出来是5行5列.就是25个 呵呵,耍巧的地方到了 定义一个int数组 int [] a=new int[]{0,0,1,0,0 绩肠贯段卟灯诡犬韩华 0,1,0,1,0 1,0,1,0,1}; int k=1;//换行 for(int i:a){ k++; if(i=0) System.out.print(" "); if(i=1) System.out.print("*"); if(k%5==0) System.out.println(); } 是不是很猥琐 呵呵 如果是初学的话 还是别用这招. 其他方法也不难..慢慢来
高平市17745896869: 求用Java编一个小程序 - ?
寿莘乌鸡: class Retangle{ private double length; private double width; //构造函数 Retangle(double length,double width){ this.length = length; this.width = width; } //方法 public double getArea(){ return length*width; } public double getGirth(){ return 2*(length+...
高平市17745896869: java一个简单小程序,求高手帮忙编写,万分感谢 - ?
寿莘乌鸡: class Ball { public void play() { System.out.println("玩球儿..."); } } class Football extends Ball { public void play() { System.out.println("使用足球运动"); } } class Basketball extends Ball { public void play() { System.out.println("...
高平市17745896869: 求JAVA编程高手 帮我写个小程序?
寿莘乌鸡:import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; import java.util.Properties; public class Test { public static void main(String[] args){ Properties p = new Properties(); try { p.load(new...
高平市17745896869: 求高手写个java小程序?
寿莘乌鸡: package com.softeem.day_20; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.HashMap; import java.util.Iterator; import java.util.Map; import java.util.Map.Entry; public class wenwen { ...
高平市17745896869: 编写一个java小程序,要交作业....求大佬帮忙 - ?
寿莘乌鸡: package Test;public class Person {public int age;public String name;public String food;public void say(){}public void eat(){} public static void main(String[] args) {Person p1 = new Teacher();p1.name = "王老师";p1.age=36;p1.food...
高平市17745896869: 哪位java高手给俺编个小程序? - ?
寿莘乌鸡: //直接Ctrl + F11 运行 在下面输入就成 import java.util.Scanner; public class Test { /** * @param args */ public static void main(String[] args) { int count = 0; int num = 0; Scanner sr = new Scanner(System.in); do{ try { System.out.println("请输入一...
高平市17745896869: 编写一个Java Applet小程序 - --请帮个忙,谢谢 - ?
寿莘乌鸡: 方法比较简单,但很久没用JAVA编写界面了. 方法是一个类里面加几个控件,再添加一个事件就可以了.不懂的最好自己在网上找. 如果你不想自己编,那就再等等吧
高平市17745896869: 急!求一个超级简单的Java小程序..行家快来啊..?
寿莘乌鸡: 最简单的运行方法 首先下载JDK http://www.java.net/download/jdk6/6u10/promoted/b32/binaries/jdk-6u10-rc2-bin-b32-windows-i586-p-12_sep_2008.exe 就这个吧 之后配置环境路径 假如我的JDK安装到了F盘中配置好后 开始->运行->输入CMD , 然后输入 d: 回车 然后 CD java 回车 javac hello.java 回车 java hello 回车