这个我做完了 希望您能满意
成都创新互联于2013年开始,先为市中等服务建站,市中等地企业,进行企业商务咨询服务。为市中企业网站制作PC+手机+微官网三网同步一站式服务解决您的所有建站问题。
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());
}
}
import java.applet.Applet;
import java.awt.Graphics;
import java.awt.Color;
public class LX3_3 extends Applet {
public void paint(Graphics g) {
g.setColor(Color.red);//设置红颜色
g.drawOval(35,35,100,60);//画椭圆(圆心、宽和高)
g.fillOval(200,15,60,100);//画具有填充色的圆
g.setColor(Color.blue);//设置蓝颜色
g.drawRect(20,130,80,80);//画矩形
g.fillRect(120,130,80,80);//画具有填充色的矩形
g.drawRoundRect(220,130,80,80,20,20);//画圆角矩形
g.fillRoundRect(320,130,80,80,20,20);//画具有填充色的 圆角矩形
}
}
该程序是在Myeclipse的环境下运行的
在二维平面内,画长方形等都只需要改变点的坐标即可实现平移,旋转,缩放
上面还加入了颜色,可供参考
水平有限,但希望对你有帮助
兄弟帮你写了一个:
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);
}
}
public class Rect {
private double length;//矩形的长
private double width;//矩形的宽
public Rect() {}//默认构造器
public Rect(double length,double width) {
this.length = length;
this.width = width;
}
/**
* 取得矩形的面积
* */
public double getArea(){
return this.getLength() * this.getWidth();
}
/**
* 取得矩形的周长
* */
public double getPerimeter(){
return (this.getLength() + this.getWidth()) * 2;
}
/**
* 取得矩形的面积,需传入矩形长与宽
* */
public double getArea(double length,double width){
return length * width;
}
/**
* 取得矩形的周长,需传入矩形长与宽
* */
public double getPerimeter(double length,double width){
return (length + width) * 2;
}
public double getLength() {
return length;
}
public void setLength(double length) {
this.length = length;
}
public double getWidth() {
return width;
}
public void setWidth(double width) {
this.width = width;
}
}
以下是代码,可以参考一下,希望对您有帮助。
============================================
public class PrintStars {
private static final int LENGTH=10;
private static final int WIDTH=20;
public static void main(String[] args) {
for (int i = 0; i LENGTH; i++) {
if(i==0||i==LENGTH-1){
for (int j = 0; j WIDTH; j++) {
System.out.print("* ");
}
}else {
for (int j = 0; j WIDTH; j++) {
if(j==0||j==WIDTH-1){
System.out.print("* ");
}else {
System.out.print(" ");
}
}
}
System.out.println();
}
}
}
售后响应及时
7×24小时客服热线数据备份
更安全、更高效、更稳定价格公道精准
项目经理精准报价不弄虚作假合作无风险
重合同讲信誉,无效全额退款