java小車圖片代碼 Java代碼圖

求大神解答,Java 畫出如下圖所示的小車

import java.awt.Color;

創(chuàng)新互聯(lián)公司專注于企業(yè)營銷型網站、網站重做改版、渭城網站定制設計、自適應品牌網站建設、html5、商城網站開發(fā)、集團公司官網建設、成都外貿網站建設、高端網站制作、響應式網頁設計等建站業(yè)務,價格優(yōu)惠性價比高,為渭城等各大城市提供網站開發(fā)制作服務。

import java.awt.Graphics;

import java.awt.Graphics2D;

import java.awt.Point;

import java.awt.event.KeyAdapter;

import java.awt.event.KeyEvent;

import javax.swing.JFrame;

import com.me.util.JFrameUtil;

public class SwingCar extends JFrame {

private final int rect_Width = 80;

private final int rect_Height = 50;

private final int radius = 15;

private final int arcAngle = 30;

private Point p = new Point();

public SwingCar() {

setSize(500, 300);

setVisible(true);

setResizable(false);

setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

JFrameUtil.toCenter(this);

p = new Point(getWidth() / 2, getHeight() / 2);

move();

}

@Override

public void paint(Graphics g) {

super.paint(g);

drawRect(p);

drawRolls(p);

g.drawLine(0,getHeight()/2+rect_Height/2+radius, getWidth(), getHeight()/2+rect_Height/2+radius);

}

public void drawRect(Point c) {

Graphics2D g = (Graphics2D) getGraphics();

g.setColor(Color.red);

g.drawRect((int) (c.getX() - rect_Width / 2),

(int) (c.getY() - rect_Height / 2), rect_Width, rect_Height);

g.setColor(Color.black);

g.drawLine((int) (c.getX() - rect_Width / 2)-50, (int) (c.getY() - rect_Height / 2)-rect_Height/2, (int) (c.getX() - rect_Width / 2), (int) (c.getY() - rect_Height / 2)+rect_Height/2);

g.setColor(Color.green);

g.fillOval((int) (c.getX() - rect_Width / 2)-50-2, (int) (c.getY() - rect_Height / 2)-rect_Height/2-2, 10, 10);

}

public void drawRolls(Point c) {

Graphics2D g = (Graphics2D) getGraphics();

g.setColor(Color.blue);

// first roll

g.fillOval((int) (c.getX() - rect_Width / 4 - radius), (int) (c.getY()

+ rect_Height / 2 - radius), radius * 2, radius * 2);

g.setColor(Color.green);

g.fillArc((int) (c.getX() - rect_Width / 4 - radius), (int) (c.getY()

+ rect_Height / 2 - radius), radius * 2, radius * 2,

calcAngle(c), arcAngle);

// second roll

g.setColor(Color.blue);

g.fillOval((int) (c.getX() + rect_Width / 4 - radius), (int) (c.getY()

+ rect_Height / 2 - radius), radius * 2, radius * 2);

g.setColor(Color.green);

g.fillArc((int) (c.getX() + rect_Width / 4 - radius), (int) (c.getY()

+ rect_Height / 2 - radius), radius * 2, radius * 2,

calcAngle(c), arcAngle);

}

public int calcAngle(Point c) {

Point center = new Point(getWidth() / 2, getHeight() / 2);

double distance = c.getX() - center.getX();

int angle = (int) (180 * distance / (Math.PI * radius));

return -angle;

}

public void move() {

this.addKeyListener(new KeyAdapter() {

@Override

public void keyPressed(KeyEvent e) {

if (e.getKeyCode() == KeyEvent.VK_RIGHT) {

p.translate(2, 0);

} else if (e.getKeyCode() == KeyEvent.VK_LEFT) {

p.translate(-2, 0);

}

repaint();

}

});

}

public static void main(String[] args) {

SwingCar sc = new SwingCar();

}

}

急~~高手請告訴我如何編寫小汽車的java程序代碼??重賞!

import java.lang.*;

class Car{

public void safe(){

System.out.println("an quan xi shu gao !");

}

}

class Benz extends Car{

public void safe(){

System.out.println("che hao !");

}

}

class Santana extends Car{

public void safe(){

System.out.println("che hen bu hao hao !");

}

}

public class Test{

public static void main(String[]args){

Car s = new Car();

s.safe();

Benz s1 = new Benz();

s1.safe();

Santana s2 = new Santana();

s2.safe();

Car s3 = new Benz();

s3.safe();

Car s4 = new Santana();

s4.safe();

}

}

這是一個 命名為Test.java

public class Car{

double price;

String name;

int id;

//3個重載的構造方法(name)(id,name)(id,name,price)

public Car(String name){

this(789,name);

}

public Car(int id,String name){

this(id,name,100000);

}

protected Car(int id,String name,double price){

this.price = price;

this.name = name;

this.id = id;

}

//3個重載的普通方法drive(int) drive(String) drive(int ,String)

public void drive(int i){

System.out.println("i = " + i);

System.out.println(price + "\n" + name + "\n" + id);

}

protected String drive(String s){

return "s is: " + s;

}

int drive(int i,String s){

return 2007;

}

}

class Test{

public static void main(String[]args){

Car c1 = new Car(777,"Santana");

c1.drive(18);

}

}

這個命名為Car.java

希望有你要的!

跪求大神榮光 回答下面的機器人的JAVA代碼

import java.text.DecimalFormat;

import java.util.ArrayList;

import java.util.List;

import java.util.Scanner;

public class WalkDistance {

public static void main(String[] args) {

Scanner in = new Scanner(System.in);

int n = in.nextInt();

for (int i = 0; i n; i++) {

String order = in.next();

System.out.println(new DecimalFormat("0.00").format(calDistance(order)));

}

in.close();

}

private static float calDistance(String order) {

char[] orderChar = order.toCharArray();

ListString orderList = new ArrayListString();

int num = 0;

for (int i = 0, len = orderChar.length; i len; i++) {

if (orderChar[i] = '0' orderChar[i] = '9') {

num++;

} else {

if (num == 0) {

orderList.add(String.valueOf(orderChar[i]));

} else {

StringBuffer sb = new StringBuffer();

for (int j = num; j 0; j--) {

sb.append(String.valueOf(orderChar[i - j]));

}

orderList.add(sb.toString());

orderList.add(String.valueOf(orderChar[i]));

num = 0;

}

}

if (i == len - 1 num != 0) {

StringBuffer sb = new StringBuffer();

for (int j = num - 1; j = 0; j--) {

sb.append(String.valueOf(orderChar[i - j]));

}

orderList.add(sb.toString());

}

}

Point curPoint = new Point(0, 0, 90);

for (int i = 0, len = orderList.size(); i len; i++) {

if ("R".equals(orderList.get(i))) {

curPoint.angle = (curPoint.angle - 90 + 360) % 360;

} else if ("L".equals(orderList.get(i))) {

curPoint.angle = (curPoint.angle + 90) % 360;

} else {

curPoint.setLocation(curPoint, orderList.get(i));

}

}

return curPoint.getDis();

}

static class Point {

private int x;

private int y;

private int angle;

private float dis;

public Point(int x, int y, int angle) {

this.x = x;

this.y = y;

this.angle = angle;

this.dis = (float) 0;

}

public void setLocation(Point point, String distance) {

if (point.angle == 0) {

point.x += Integer.valueOf(distance);

} else if (point.angle == 90) {

point.y += Integer.valueOf(distance);

} else if (point.angle == 180) {

point.x -= Integer.valueOf(distance);

} else {

point.y -= Integer.valueOf(distance);

}

}

public float getDis() {

return (float) Math.sqrt(this.x * this.x + this.y * this.y);

}

}

}

網站名稱:java小車圖片代碼 Java代碼圖
本文鏈接:http://muchs.cn/article2/docoooc.html

成都網站建設公司_創(chuàng)新互聯(lián),為您提供微信公眾號、網站內鏈微信小程序、商城網站、品牌網站設計、

廣告

聲明:本網站發(fā)布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經允許不得轉載,或轉載時需注明來源: 創(chuàng)新互聯(lián)

成都網站建設