I want to display many text in the same windows but only the last text is displayed, there is my 2 class :
import Test.Graph;
import javax.swing.JFrame;
public class InterfaceGraphique extends JFrame {
private static final long serialVersionUID = 1L;
public InterfaceGraphique() {
this.setTitle("My first Window");
this.setSize(800,1000);
this.setLocationRelativeTo(null);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setContentPane(new Graph("test 1", 150,300,"erreur"));
this.setContentPane(new Graph("test 2 ", 250,400,"normal"));
this.setContentPane(new Graph("test3", 350,500,"valide"));
this.setVisible(true);
}
}
import java.awt.Graphics;
import javax.swing.JPanel;
import java.awt.Color;
import java.awt.Font;
public class Graph extends JPanel {
private static final long serialVersionUID = 1L;
private String fichier;
private int x;
private int y;
String etat;
public Graph(String fichier, int x, int y, String etat) {
this.fichier = fichier;
this.x = x;
this.y = y;
this.etat= etat;
}
@Override
public void paintComponent(Graphics g){
System.out.println("Je suis exécutée !");
if(etat.contentEquals("erreur")) {
Font font = new Font("Courier", Font.BOLD, 20);
g.setFont(font);
g.setColor(Color.red);
}
if(etat.contentEquals("normal")) {
Font font = new Font("Courier", Font.BOLD, 20);
g.setFont(font);
g.setColor(Color.black);
}
if(etat.contentEquals("valide")) {
Font font = new Font("Courier", Font.BOLD, 20);
g.setFont(font);
g.setColor(Color.green);
}
g.drawString(fichier, x, y);
}
public static void main(String[] args){
@SuppressWarnings("unused")
InterfaceGraphique ig = new InterfaceGraphique();
}
}
When I compile the test class I have a window with only displayed "test 3" in green. Thanks for help and sorry for bad english. PS: I'm new in JAVA especially in GUI so you can tell me other error to fix thanks!