我们专注攀枝花网站设计 攀枝花网站制作 攀枝花网站建设
成都网站建设公司服务热线:400-028-6601

网站建设知识

十年网站开发经验 + 多家企业客户 + 靠谱的建站团队

量身定制 + 运营维护+专业推广+无忧售后,网站问题一站解决

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://mswzjz.cn/article/ddogiid.html

其他资讯