Roma
Крч там есть строка со знаками(///////////////) Это разделитель. Сверху первый класс, слева-второйunknown
java
3 years ago
4.5 kB
31
Indexable
import java.awt.*;
import java.awt.geom.*;
import javax.swing.*;
import java.util.concurrent.ThreadLocalRandom;
class test3 extends JPanel {
public void paintComponent(Graphics g)
{
int randomNum = ThreadLocalRandom.current().nextInt(0, 1000); //рандом точки
int randomNum2 = ThreadLocalRandom.current().nextInt(0, 1000);
int randomNum3 = ThreadLocalRandom.current().nextInt(0, 1000);
int randomNum4 = ThreadLocalRandom.current().nextInt(0, 500); //рандом точки
int randomNum5 = ThreadLocalRandom.current().nextInt(0, 500);
int randomNum6 = ThreadLocalRandom.current().nextInt(0, 500);
super.paintComponent(g);
Graphics2D g2 = (Graphics2D) g;
int x1 = randomNum; //корды прямогуольников
int y1 = randomNum4;
int[] xa=new int[]{x1, x1+100, x1+100, x1};
int[] ya=new int[]{y1, y1, y1+100, y1+100};
int x2 = randomNum2;
int y2 = randomNum5;
int[] xb=new int[]{x2, x2+100, x2+100, x2};
int[] yb=new int[]{y2, y2, y2+100, y2+100};
int x3 = randomNum3;
int y3 = randomNum6;
int[] xc=new int[]{x3, x3+100, x3+100, x3};
int[] yc=new int[]{y3, y3, y3+100, y3+100};
GeneralPath genPath = new GeneralPath();
genPath.moveTo(xa[0],ya[0]); //прямоугольник 1
g2.setPaint(Color.RED);
g2.drawPolygon(xa,ya,4);
g2.fillPolygon(xa,ya,4);
genPath.moveTo(xb[0],yb[0]); //прямоугольник 2
g2.setPaint(Color.blue);
g2.drawPolygon(xb,yb,4);
g2.fillPolygon(xb,yb,4);
genPath.moveTo(xc[0],yc[0]); //прямоугольник 3
g2.setPaint(Color.GREEN);
g2.drawPolygon(xc,yc,4);
g2.fillPolygon(xc,yc,4);
}
public static void main(String[] args) {
JFrame frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
test3 gui = new test3();
gui.setBackground(Color.WHITE);
frame.add(gui);
frame.setSize(1280,720);
frame.setVisible(true);
}
}
/////////////////////////////////////////////////////////////////////////////////////////////
import java.awt.*;
import java.awt.geom.*;
import javax.swing.*;
public class affine extends JPanel {
public void paintComponent(Graphics g)
{
super.paintComponent(g);
Graphics2D g2 = (Graphics2D) g;
int x1 = 200; //корды прямогуольников
int y1 = 100;
int[] xa=new int[]{x1, x1+100, x1+100,x1,x1};
int[] ya=new int[]{y1, y1, y1+100,y1+100,y1};
GeneralPath genPath = new GeneralPath();
g2.setPaint(Color.RED);
for(int i = 0; i < xa.length-1; i++)
{
g2.drawLine(xa[i],ya[i],xa[i+1],ya[i+1]);
}
g2.fill(genPath);
AffineTransform affine;
affine = new AffineTransform(1.0,0.0,0.0,1.0,0.0,0.0);
affine.translate(100,100);
affine.scale(1.0,1.0);
g2.setTransform(affine);
g2.drawPolygon(xa,ya,4);
affine = new AffineTransform(1.0,0.0,0.0,1.0,0.0,0.0);
affine.translate(0,200);
affine.scale(1.0,1.0);
g2.setTransform(affine);
g2.drawPolygon(xa,ya,4);
affine = new AffineTransform(1.0,0.0,0.0,1.0,0.0,0.0);
affine.translate(-100,100);
affine.scale(1.0,1.0);
g2.setTransform(affine);
g2.drawPolygon(xa,ya,4);
affine = new AffineTransform(1.0,0.5,0.4,0.7,120.0,-40.0);
affine.translate(-100,-100);
affine.scale(1.0,1.0);
g2.setTransform(affine);
g2.drawPolygon(xa,ya,4);
affine = new AffineTransform(1.0,-0.5,-0.4,0.7,0.0,0.0);
affine.translate(100,200);
affine.scale(1.0,1.0);
g2.setTransform(affine);
g2.drawPolygon(xa,ya,4);
}
public static void main(String[] args) {
JFrame frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
affine gui = new affine();
gui.setBackground(Color.WHITE);
frame.add(gui);
frame.setSize(500,300);
frame.setVisible(true);
}
}
Editor is loading...