Bonjour voila je débute en Java je me débrouille comme je peut avec différent tuto sur le net mais la je bloque.

Voila j'ai un code :

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
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
package barchartdemo;
 
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
 
  public class SimpleBarChart extends JPanel {
  private double[] value;
  private String[] languages;
  private String title;
 
  public SimpleBarChart(double[] val, String[] lang, String t) {
    languages = lang;
    value = val;
    title = t;
  }
 
 
  public void paintComponent(Graphics graphics) {
    super.paintComponent(graphics);
    if (value == null || value.length == 0)
      return;
    double minValue = 0;
    double maxValue = 0;
    for (int i = 0; i < value.length; i++) {
      if (minValue > value[i])
        minValue = value[i];
      if (maxValue < value[i])
        maxValue = value[i];
    }
    Dimension dim = getSize();
    int clientWidth = dim.width;
    int clientHeight = dim.height;
    int barWidth = clientWidth / value.length;
    Font titleFont = new Font("Book Antiqua", Font.BOLD, 15);
    FontMetrics titleFontMetrics = graphics.getFontMetrics(titleFont);
    Font labelFont = new Font("Book Antiqua", Font.PLAIN, 10);
    FontMetrics labelFontMetrics = graphics.getFontMetrics(labelFont);
    int titleWidth = titleFontMetrics.stringWidth(title);
    int q = titleFontMetrics.getAscent();
    int p = (clientWidth - titleWidth) / 2;
    graphics.setFont(titleFont);
    graphics.drawString(title, p, q);
    int top = titleFontMetrics.getHeight();
    int bottom = labelFontMetrics.getHeight();
    if (maxValue == minValue)
      return;
    double scale = (clientHeight - top - bottom) / (maxValue - minValue);
   q = clientHeight - labelFontMetrics.getDescent();
    graphics.setFont(labelFont);
 
    for (int j = 0; j < value.length; j++) {
      int valueP = j * barWidth + 1;
      int valueQ = top;
      int height = (int) (value[j] * scale);
      if (value[j] >= 0)
        valueQ += (int) ((maxValue - value[j]) * scale);
      else {
        valueQ += (int) (maxValue * scale);
        height = -height;
      }
 
      graphics.setColor(Color.black);
      graphics.fillRect(valueP, valueQ, barWidth - 2, height);
      graphics.setColor(Color.red);
      graphics.drawRect(valueP, valueQ, barWidth - 2, height);
      int labelWidth = labelFontMetrics.stringWidth(languages[j]);
      p = j * barWidth + (barWidth - labelWidth) / 2;
      graphics.drawString(languages[j], p, q);
    }
  }
 
 
 
 
   public static void main(String[] argv) {
    JFrame frame = new JFrame();
    frame.setSize(350, 300);
    double[] value= new double[5];
    String[] languages = new String[5];
    value[0] = 1;
    languages[0] = "Visual Basic";
 
    value[1] = 6;
    languages[1] = "PHP";
 
    value[2] = 3;
    languages[2] = "C++";
 
	value[3] = 4;
    languages[3] = "C";
 
    value[4] = 5;
    languages[4] = "Java";
 
    frame.getContentPane().add(new SimpleBarChart(value, languages, "Programming Languages"));
 
    WindowListener winListener = new WindowAdapter() {
      public void windowClosing(WindowEvent event) {
        System.exit(0);
      }
    };
    frame.addWindowListener(winListener);
    frame.setVisible(true);
  }
 
 
 
}
Et je voudrais réaliser ceci dans un JPanel a l'aide de Netbeans.

J'ai donc créer mon panel, et j'arrive avec se code la :

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
43
44
45
46
47
48
49
50
51
package barchartdemo;
 
import javax.swing.*;
import java.awt.event.*;
import barchartdemo.SimpleBarChart;
 
/**
 *
 * @author Benjamin
 */
 
 
public class maFenetre extends javax.swing.JFrame {
    private static final long serialVersionUID = 1L;
 
 
    /** Creates new form maFenetre */
    public maFenetre() {
        initComponents();
 
    JFrame mafenetre = new JFrame();
    mafenetre.setSize(350, 300);
    double[] value= new double[5];
    String[] languages = new String[5];
    value[0] = 1;
    languages[0] = "Visual Basic";
 
    value[1] = 6;
    languages[1] = "PHP";
 
    value[2] = 3;
    languages[2] = "C++";
 
    value[3] = 4;
    languages[3] = "C";
 
    value[4] = 5;
    languages[4] = "Java";
 
    mafenetre.getContentPane().add(new SimpleBarChart(value, languages, "Programming Languages"));
 
    WindowListener winListener = new WindowAdapter() {
            @Override
      public void windowClosing(WindowEvent event) {
        System.exit(0);
      }
    };
    mafenetre.addWindowListener(winListener);
    mafenetre.setVisible(true);
 
 }
Mais bon voila je sait pas trop se qui va pas si vous pouviez aider un pauvre débutant

Cordialement.