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 74 75 76 77 78 79 80
| public class ExempleLogo {
public static void main(String[] args) {
JFrame fenetre = new JFrame("Flappy Bird");
fenetre.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);//permet de d'arreter le programme en cliquant sur le coix
fenetre.setSize(360, 485);
fenetre.setLocationRelativeTo(null);//centrer la fenetre en ecran
fenetre.setResizable(false);// empaicher de redimensier la fenetre
fenetre.setAlwaysOnTop(true); //le fenetre est en dessus
JPanel logo = new Logo();
JButton buttonStart = new JButton("Start");
JButton buttonExit = new JButton("Exit");
JPanel mainPanel = new JPanel();
mainPanel.setLayout(new GridLayout(3,0));
mainPanel.add(logo);
mainPanel.add(buttonStart);
mainPanel.add(buttonExit);
mainPanel.setBorder(BorderFactory.createLineBorder(Color.WHITE, 30));
fenetre.add(mainPanel);
fenetre.setVisible(true);
}
private static class Logo extends JPanel {
private final Shape star;
public Logo() {
setBackground(Color.WHITE);
Path2D.Double dessin = new Path2D.Double();
boolean first=true;
double c=2*Math.PI;
for(double i=0; i<c; i+=c/5) {
double x=40*Math.cos(i);
double y=40*Math.sin(i);
if ( first ) {
dessin.moveTo(x, y);
first=false;
}
else {
dessin.lineTo(x, y);
}
double a = i+c/10;
x=40*2/5*Math.cos(a);
y=40*2/5*Math.sin(a);
dessin.lineTo(x, y);
}
dessin.closePath();
AffineTransform transform = AffineTransform.getTranslateInstance(40, 70);
transform.rotate(-Math.PI/3);
star = transform.createTransformedShape(dessin);
}
@Override
protected void paintComponent(Graphics g) {
super.paintComponent(g);
g.setFont(getFont().deriveFont(72f).deriveFont(Font.BOLD));
Graphics2D g2d = (Graphics2D)g;
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
g.setColor(Color.RED);
g2d.fill(star);
Shape logo = AffineTransform.getTranslateInstance(70, 100).createTransformedShape(g.getFont().createGlyphVector(g2d.getFontRenderContext(), "LOGO").getOutline());
g2d.fill(new BasicStroke(5).createStrokedShape(logo));
g.setColor(Color.ORANGE);
g2d.fill(logo);
}
}
} |
Partager