voilà le code--------->
package permis_conduire;
import java.awt.Checkbox;
import java.awt.Color;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.Graphics;
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.StringTokenizer;
import javax.swing.JPanel;
public class QuestionEtReponse extends JPanel {
BufferedReader bis ;
BufferedReader bis2 ;
String ligne;
String ligne2;
StringTokenizer t;
Checkbox [] cr = new Checkbox[3];
JPanel pan2;
public QuestionEtReponse() {
this.setBackground(Color.red);
this.setVisible(true);
try
{
bis=new BufferedReader(new FileReader("qcm.txt"));
}
catch(FileNotFoundException e)
{e.printStackTrace();}
try
{
bis2=new BufferedReader(new FileReader("qcm2.txt"));
}
catch(IOException e)
{e.printStackTrace();}
}
public void paintComponent(Graphics g)
{
int i=0;
int j=0;
try
{
if((ligne=bis.readLine())!=null && (ligne2=bis2.readLine())!=null)
{ g.setColor(Color.red);
g.fillRect(0, 0, this.getWidth(), this.getHeight());
Font font =new Font("Thoma",Font.BOLD,25);
g.setColor(Color.BLACK);
g.setFont(font);
g.drawString(ligne, 50, 30);
pan2=new JPanel();pan2.setBounds(0, 0,30, 190);
pan2.setBackground(Color.black);
pan2.setVisible(true);
pan2.setLayout(null);
add(pan2);
t=new StringTokenizer(ligne2);
while(t.hasMoreElements())
{
cr[j]=new Checkbox();
cr[j].setBounds(5, 65+i,20,20);
pan2.add(cr[j]);
g.setColor(Color.blue);
g.setFont(new Font("thoma",Font.ITALIC,20));
g.drawString(t.nextToken().replace('_', ' '), 50, 80+i);
i+=40;
j++;
}
}
}
catch(IOException e)
{e.printStackTrace();}
}
}