JFrame JPanel java

JFrame JPanel java - Java - Programmation

Marsh Posté le 28-03-2019 à 19:45:17    

Bonjour je n'arrive pas a placer une image en fond dans mon JFrame et je n'ai rien trouvé qui marche sur d'autre site pourriez vous m'aidez.
voici mes classes
Main.java

Citation :


 
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import java.awt.Graphics;
import java.awt.Color;
import java.awt.Component;
import java.awt.Container;
import java.awt.Image;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.image.ImageObserver;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
 
public class Main {
 public static void main(String[] args) {
  JFrame fenetre = new JFrame();
 
   
  Utils util = new Utils();
 
 }
 
}

 
Utils.java

Citation :

import java.awt.Graphics;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.Font;
 
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.border.EmptyBorder;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import java.awt.Image;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.image.ImageObserver;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
 
public class Utils extends JFrame{
 public Utils() {
  this.setTitle("culturos" );
  this.setSize(702, 502);
  this.setLocationRelativeTo(null);
  this.setIconImage(new ImageIcon(getClass().getResource("/Sans titre.png" )).getImage());
  this.setContentPane(new System());
  this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);    
  this.setVisible(true);
   
 }
 
 
}


et System.java

Citation :


import java.awt.Graphics;
import java.awt.Color;
import javax.swing.JPanel;
import javax.swing.JFrame;
import java.awt.Image;
import java.awt.image.ImageObserver;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
 
public class System extends JPanel{
  public void contentPane(Graphics g) {
   try {
    Image img = ImageIO.read(new File("Capture.png" ));
    g.drawImage(img, 0, 0, this);
   } catch (IOException e) {
    e.printStackTrace();
   }
   
  }
}

Reply

Marsh Posté le 28-03-2019 à 19:45:17   

Reply

Sujets relatifs:

Leave a Replay

Make sure you enter the(*)required information where indicate.HTML code is not allowed