「点矩形JAVA」点矩形序列Rn自变量的取值范围为
本篇文章给大家谈谈点矩形JAVA,以及点矩形序列Rn自变量的取值范围为对应的知识点,希望对各位有所帮助,不要忘了收藏本站喔。
本文目录一览:
- 1、java中做一个按钮,点击按钮后画一个矩形的代码怎么写?
- 2、java中关于矩形类
- 3、java 编写一个矩形类 rect 要求如下:
- 4、在java中判断一个点是否在一个有斜度的矩形内的 Rectangle的用法
- 5、Java编写一个矩形类,至少包含以下方法:
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中关于矩形类
public class Rectangle2 {
// 属性:
private double m_height;
private double m_width;
private double m_x1;
private double m_y1;
private double m_x2;
private double m_y2;
private boolean m_isRectangle;
// 操作:
public Rectangle2() {
this(0.0, 0.0, 0.0, 0.0);
}
public Rectangle2(double aX1, double aY1, double aX2, double aY2) {
setCoordinates(aX1, aY1, aX2, aY2);
}
public void setCoordinates(double aX1, double aY1, double aX2, double aY2) {
m_x1 = aX1;
m_y1 = aY1;
m_x2 = aX2;
m_y2 = aY2;
setHeight();
setWidth();
isRectangle();
}
public boolean isRectangle() {
if ((m_height = 0 m_width = 0) (m_x1 != m_x2 || m_y1 != m_y2)) {
System.err.println("输入的坐标构成一个矩形");
m_isRectangle = true;
} else {
if ((m_x1 == m_x2 m_y1 != m_y2)
|| (m_x1 != m_x2 m_y1 == m_y2)) {
System.err.println("输入的坐标构成一条直线");
} else if (m_x1 == m_x2 m_y1 == m_y2) {
System.err.println("输入的坐标构成一点");
}
m_isRectangle = false;
}
return m_isRectangle;
}
public boolean isSquare() {
return isRectangle() m_height == m_width;
}
private void setHeight() {
double side1 = Math.abs(m_x1 - m_x2);
double side2 = Math.abs(m_y1 - m_y2);
m_height = side1 = side2 ? side1 : side2;
}
private void setWidth() {
double side1 = Math.abs(m_x1 - m_x2);
double side2 = Math.abs(m_y1 - m_y2);
m_width = side1 = side2 ? side1 : side2;
}
public double getHeight() {
return m_height;
}
public double getWidth() {
return m_width;
}
public double perimeter() {
return 2 * (m_height + m_width);
}
public double area() {
return m_height * m_width;
}
}
public class Rectangle2Test {
public static void main(String[] args) {
// TODO Auto-generated method stub
Rectangle2 rect1 = new Rectangle2();
System.err.println(rect1.isRectangle());
System.err.println(rect1.isSquare());
System.err.println(rect1.getHeight());
System.err.println(rect1.getWidth());
System.err.println(rect1.perimeter());
System.err.println(rect1.area());
Rectangle2 rect2 = new Rectangle2(22, 33, 66, 99);
System.err.println(rect2.isRectangle());
System.err.println(rect2.isSquare());
System.err.println(rect2.getHeight());
System.err.println(rect2.getWidth());
System.err.println(rect2.perimeter());
System.err.println(rect2.area());
}
}
java 编写一个矩形类 rect 要求如下:
public class Rect{
private int length;
private int width;
private int startX;
private int startY
public Rect(){}
public Rect(int length,int width){
this.length = length;
this.width = width;
}
public Rect(int length,int width,int startX,int startY){
this.length = length;
this.width = width;
this.startX = startX;
this.startY = startY;
}
//不知道你要什么成员方法,我随便点....
public void louzhuhao(){
System.out.println("楼主好....");
}
public int getLength() {
return length;
}
public void setLength(int length) {
this.length = length;
}
public int getWidth() {
return width;
}
public void setWidth(int width) {
this.width = width;
}
public int getStartX() {
return startX;
}
public void setStartX(int startX) {
this.startX = startX;
}
public int getStartY() {
return startY;
}
public void setStartY(int startY) {
this.startY = startY;
}
}
在java中判断一个点是否在一个有斜度的矩形内的 Rectangle的用法
只要实现这个的话,不考虑效率问题,可以new一个image,然后把这个不规则的四边fill上去,当然要指定个颜色,然后获取你要判断坐标的点。然后判断下颜色是不是和填充的一样
BufferedImage 有getRGB(int x, int y) 下面方法可以获取r、g、b的值
public static int [] getRGB(BufferedImage image, int x, int y) {
int [] rgb = null ;
if (image != null x image.getWidth() y image.getHeight()) {
rgb = new int [ 3 ];
int pixel = image.getRGB(x,y);
rgb[ 0 ] = (pixel 0xff0000 ) 16 ;
rgb[ 1 ] = (pixel 0xff00 ) 8 ;
rgb[ 2 ] = (pixel 0xff );
}
return rgb;
}
Java编写一个矩形类,至少包含以下方法:
import java.awt.Point;
public class Rectangle {
private int widthT = 0;
private int heightT = 0;
Point point = new Point();
public Rectangle(int width, int height, int centerX, int centerY) {
widthT = width;
heightT = height;
point.x = centerX;
point.y = centerY;
}
public int width() {
return widthT;
}
public int height() {
return heightT;
}
public int centerX() {
return point.x;
}
public int centerY() {
return point.y;
}
}
麻烦采纳呦~~~亲
点矩形JAVA的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于点矩形序列Rn自变量的取值范围为、点矩形JAVA的信息别忘了在本站进行查找喔。
发布于:2022-11-26,除非注明,否则均为
原创文章,转载请注明出处。