重庆分公司,新征程启航

为企业提供网站建设、域名注册、服务器等服务

java代码精品 高质量java代码

求一个简单的JAVA游戏代码,100行左右,谢谢!

import java.awt.Dimension;

目前成都创新互联公司已为上1000+的企业提供了网站建设、域名、虚拟空间、网站托管运营、企业网站设计、鲤城网站维护等服务,公司将坚持客户导向、应用为本的策略,正道将秉承"和谐、参与、激情"的文化,与客户和合作伙伴齐心协力一起成长,共同发展。

import java.awt.Graphics;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import javax.swing.JButton;

import javax.swing.JFrame;

import javax.swing.JPanel;

public class Painter extends JFrame{

/**

*

*/

private static final long serialVersionUID = 8160427604782702376L;

CanvasPanel canvas = new CanvasPanel();;

public Painter() {

super("Star");

this.add(canvas);

this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

this.pack();

this.setResizable(false);

this.setLocationRelativeTo(null);

this.setVisible(true);

}

public static void main(String[] args) {

new Painter();

}

}

class CanvasPanel extends JPanel implements ActionListener{

/**

*

*/

private static final long serialVersionUID = -4642528854538741028L;

private JButton[] btn = new JButton[4];

private String[] btn_name = {"+", "-", "R", "L"};

private int center_x = 200, center_y = 200, radius = 100, degree = 0;

public CanvasPanel() {

this.setPreferredSize(new Dimension(400, 500));

this.setLayout(null);

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

btn[i] = new JButton(btn_name[i]);

btn[i].setBounds(160 + i * 60, 425, 50, 50);

btn[i].addActionListener(this);

this.add(btn[i]);

}

}

@Override

public void paintComponent(Graphics g) {

super.paintComponent(g);

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

g.drawLine( (int) (center_x + radius * Math.sin(Math.toRadians(degree + 72 * i))),

(int) (center_y - radius * Math.cos(Math.toRadians(degree + 72 * i))),

(int) (center_x + radius * Math.sin(Math.toRadians(degree + 72 * i + 144))),

(int) (center_y - radius * Math.cos(Math.toRadians(degree + 72 * i + 144))));

}

}

public void actionPerformed(ActionEvent e) {

// TODO Auto-generated method stub

if(e.getActionCommand() == "+") {

if(radius 200)

radius += 2;

repaint();

} else if(e.getActionCommand() == "-") {

if(radius 0)

radius -= 2;

repaint();

} else if(e.getActionCommand() == "R") {

degree = (degree + 2) % 360;

repaint();

} else if(e.getActionCommand() == "L") {

degree = (degree - 2) % 360;

repaint();

}

}

}

求这段JAVA程序代码

//Example.java

class A{

float a;

static float b;

void setA(float a ){

this.a = a;

}

void setB(float b){

this.b = b;

}

float getA() {

return a;

}

float getB() {

return b;

}

void inputA() {

System.out.println(a);

}

static void inputB() {

System.out.println(b);

}

}

public class Example {

public static void main (String args[]){

/*代码5] //通过类名操作类变量b,并赋值100

[代码6] //通过类名调用方法inputB()

A cat=new A();

A dog=new A();

[代码7] //cat调用方法setA(int a)将cat的成员a的值设置为200

[代码8] //cat调用方法setB(int b)将cat的成员b的值设置为400

[代码9] //dog调用方法setA(int a)将dog的成员a的值设置为300

[代码10] //dog调用方法setB(int b)将dog的成员b的值设置为800

[代码11] //cat调用方法inputA()

[代码12] //cat调用方法inputB()

[代码13] //dog调用方法inputA()

[代码14] //dog调用方法inputB()*/

A.b = 100;

A.inputB();

A cat = new A();

A dog = new A();

cat.setA(200);

cat.setB(300);

dog.setA(300);

dog.setB(800);

cat.inputA();

cat.inputB();

dog.inputA();

dog.inputB();

}

}

有一个要说明的是,setA()与setB()的形参是浮点型的,所以如楼上所说,楼主代码7到代码10的形参设错了。但200,400,300,800是可以的。只是将int改为float.

谁能给一个Java程序代码我,要50行到100行就可以啦。最好有几行解释

给你一个前几天才帮人写的

“计算整钱兑零”。程序要求用户输入一个双精度数代表总元数,就会列出总值与其等价的1元币、二角五分币、5分币和1分币的数目。程序报告的数目是1元币的最大数、其次是二角五分币的最大数,等等,依此类推。只显示非零的单位。对单个单位显示单数单词,对多于一个单位的显示复数单词

import java.util.Scanner;

public class MoneyCalculate {

public static void main(String[] args) {

int max100 = 0;

int max25 = 0;

int max5 = 0;

int max1 = 0;

double money = getMoneyFromInput();

String str = String.valueOf(money).trim();

String[] ary = str.split("\\.");

max100 = Integer.parseInt(ary[0]);

if(ary.length == 2){

int fen = Integer.parseInt(ary[1]);

if(ary[1].trim().length() == 1){

fen = Integer.parseInt(ary[1]) * 10;

}

max25 = fen / 25;

if(fen % 25 != 0){

fen = fen % 25;

}else{

fen = 0;

}

max5 = fen / 5;

max1 = fen % 5;

}

StringBuilder sb = new StringBuilder(money + " = ");

if(max100 != 0){

sb.append(max100);

sb.append("*1 ");

}

if(max25 != 0){

sb.append(max25);

sb.append("*0.25 ");

}

if(max5 != 0){

sb.append(max5);

sb.append("*0.05 ");

}

if(max1 != 0){

sb.append(max1);

sb.append("*0.01 ");

}

System.out.println(sb.toString());

}

private static double getMoneyFromInput() {

Scanner scanner = new Scanner(System.in);

return scanner.nextDouble();

}

}

-----------

2.49

2.49 = 2*1 1*0.25 4*0.05 4*0.01

-----------

2.5

2.5 = 2*1 2*0.25

-----------

37.23

37.23 = 37*1 4*0.05 3*0.01

-----------------

123.569

123.569 = 123*1 22*0.25 3*0.05 4*0.01


本文名称:java代码精品 高质量java代码
网页链接:http://cqcxhl.cn/article/dddghjg.html

其他资讯

在线咨询
服务热线
服务热线:028-86922220
TOP