bonsoir
j'ai un problème , je n'arrive pas à dessiner sur jpanel je ne sais pascomment l'ajouter le paint sur jpanel
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
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
 
 
import javax.swing.*;
import java.awt.*;
import java.io.*;
import java.lang.*; 
public class test  extends JFrame        {
  JPanel jPanel1 = new JPanel();
  public test() {
    setTitle(" fenetre ");
    this.setResizable(false);
    this.setSize(650, 650);
    this.setLocationRelativeTo(null);
    this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    try {
      jbInit();
    }
    catch(Exception e) {
      e.printStackTrace();
    }
 
  }
  private void jbInit() throws Exception {
    this.getContentPane().setLayout(null);
    jPanel1.setBounds(new Rectangle(0, 29, 487, 124));
    jPanel1.setLayout(null);
    this.getContentPane().add(jPanel1, null);
  }
 
 
  public static void main(String[] args) {
    test fenetre = new test();
    fenetre.setVisible(true);
  }
 
  public void paint(Graphics g)
      {
              // Tracer une ligne rouge entre les points (x=5, y=30) et (x=50, y=70)
              g.setColor(Color.red);
              g.drawLine(5, 30, 50, 70);
      }  
}
merci d'avance