1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
| package test;
import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.geom.AffineTransform;
import java.awt.geom.Path2D;
import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.SwingUtilities;
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author Fabrice
*/
public class Main extends JComponent {
private Path2D.Double path2;
private double scaleFactor = 2000000;
private AffineTransform zoom = AffineTransform.getScaleInstance(scaleFactor, scaleFactor);
private BasicStroke stroke = new BasicStroke(1 / (float) scaleFactor);
public Main() {
path2 = new Path2D.Double();
path2.moveTo(7.748175646263692, 48.629056806693107);
path2.lineTo(7.748157575425049, 48.629142234497543);
path2.lineTo(7.748297776149309, 48.629159166832196);
path2.lineTo(7.748321101157464, 48.629071727973418);
path2.lineTo(7.748175646263692, 48.629056806693107);
path2.closePath();
}
@Override
protected void paintComponent(Graphics g) {
Graphics2D g2d = (Graphics2D) g.create();
try {
g2d.setTransform(zoom);
g2d.translate(-7.748, -48.629);
g2d.setPaint(Color.BLACK);
g2d.drawRect(48, 48, 48, 48);
g2d.fillRect(7, 48, 1, 1);
g2d.setPaint(Color.RED);
g2d.setPaint(Color.BLUE);
g2d.fill(path2);
g2d.setStroke(stroke);
g2d.draw(path2.getBounds2D());
} finally {
g2d.dispose();
}
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
JFrame frame = new JFrame("Test");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(1500, 600);
frame.setContentPane(new Main());
frame.setVisible(true);
}
});
}
} |
Partager