Je sens que je suis passé par tout ce que je devais faire:Graphics non dessin à JFrame
- Faire une classe graphique qui a un vide appelé paintComponent et étend JComponent
- Avoir ce vide paintComponent ont Graphics g comme un paramètre, puis faites Graphics2D g2d = (Graphics2D) g;
- Ajouter la classe Graphics à mon JFrame
Je ne trouve rien à redire à cela, donc je suis un peu confus.
Mon code est ici:
public static void main(String[] args) {
DragonEscape game = new DragonEscape();
frame.setTitle(title);
frame.setSize(1000, 500);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
frame.setResizable(false);
frame.setLocationRelativeTo(null);
frame.add(new Graphicsa());
frame.add(game);
}
et
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import javax.swing.JComponent;
public class Graphicsa extends JComponent {
private static final long serialVersionUID = 1L;
public Graphics g;
protected void paintComponent(Graphics g) {
Graphics2D g2d = (Graphics2D) g;
g.fillRect(0, 0, 1000, 500);
g.setColor(Color.gray);
g.fillRect(0, 0, 100, 100);
}
}
Quelqu'un va-t-il faire quelque chose? –
(1-) Soyez patient! Les gens répondent aux questions quand ils ont le temps. Il n'y a aucune garantie quand cela sera. – camickr
@camickr ok. Je vais –