Bonsoir, j'ai un petit problème de débutant que je n'arrive pas à régler.
Mon programme est fait de deux fichiers (Graph.java et Frame.java).
Dans le premier j'ai un code tout simple :
Dans le deuxième, lorsque je veux tracer une ligne, par exemple, lors de l'appui sur un bouton,
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9 public class Graph extends JPanel { public void paint(Graphics g) { g.setColor(java.awt.Color.GREEN); Dimension size = getSize(); g.translate(size.width / 2, size.height / 2); g.drawLine(-size.width / 2, 0, size.width / 2, 0); g.drawLine(0, -size.height / 2, 0, size.height / 2); } }
j'obtiens l'erreur :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 public class Frame extends JFrame implements ActionListener { public Frame() { //du code Graph g = new Graph(); } public void actionPerformed(ActionEvent e) { g.drawLine(-100, 100, 100, -100); } public static void main(String args[]) { Frame f = new Frame(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.setSize(800, 600); f.setVisible(true); } }
cannot find symbol
symbol : variable
location: class Frame
Pourtant, j'ai bien créé une instance de Graph, donc je ne vois pas trop.
Merci d'avance![]()
Partager