java实心矩形代码 java编程实现矩形类

JAVA,写一个名为Rectangle的类表示矩形

这个我做完了 希望您能满意

成都创新互联公司是少有的网站设计、网站制作、营销型企业网站、小程序开发、手机APP,开发、制作、设计、买链接、推广优化一站式服务网络公司,自2013年起,坚持透明化,价格低,无套路经营理念。让网页惊喜每一位访客多年来深受用户好评

public class Rectangle {

private double height;

private double width;

private String color;

public double getHeight() {

return height;

}

public void setHeight(double height) {

this.height = height;

}

public double getWidth() {

return width;

}

public void setWidth(double width) {

this.width = width;

}

public String getColor() {

return color;

}

public void setColor(String color) {

this.color = color;

}

public Rectangle(double width,double height,String color){

this.setColor(color);

this.setHeight(height);

this.setWidth(width);

}

public void getArea(){

double area=0;

area=this.height*this.width;

System.out.println("矩形的面积为"+area);

}

public String toString(){

String recStr="矩形的高度:"+this.getHeight()+"宽度:"+this.getWidth()

+"颜色:"+this.getColor();

return recStr;

}

/**

* 测试函数

* @param args

*/

public static void main(String[] args) {

Rectangle rec=new Rectangle(3, 4, "红色");

rec.getArea();

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

}

}

java中做一个按钮,点击按钮后画一个矩形的代码怎么写?

兄弟帮你写了一个:

import java.awt.Button;

import java.awt.Color;

import java.awt.Frame;

import java.awt.Graphics;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import java.awt.event.WindowAdapter;

import java.awt.event.WindowEvent;

import java.util.Random;

public class Print {

public static void main(String[] args) {

new Te();

}

}

class Te extends Frame implements ActionListener {

Color cc = Color.red;

int x = -20, y = -50;

Random r = new Random();

public Te() {

this.setLayout(null);

Button b = new Button("画圆");

this.add(b);

b.setBounds(30,30,50,50);

b.addActionListener(this);

this.addWindowListener(new WindowAdapter () {

@Override

public void windowClosing(WindowEvent e) {

System.exit(0);

}

});

this.setBounds(200,200,500,400);

this.setVisible(true);

}

public void actionPerformed(ActionEvent e) {

this.cc = Color.red;

this.x = r.nextInt(400);

do {

int x1 = r.nextInt(300);

this.y = x1;

} while (this.y 50);

this.repaint();

}

@Override

public void paint(Graphics g) {

Color c = g.getColor();

g.setColor(cc);

g.drawRect(x,y,50,50);

g.setColor(c);

}

}

JAVA输入长和宽打印实心矩形。要简单点的方法。打印结果大概是 ****** ****** ******

Scanner sc = new Scanner(System.in);

int length = sc.nextInt();

int width = sc.nextInt();

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

for(int j = 0; j width; j++){

System.out.print("*");

}

System.out.println();

}


网页标题:java实心矩形代码 java编程实现矩形类
链接地址:http://ybzwz.com/article/ddogiid.html