interface avec botton et backgroud

senquenceDiagram
NicolasFau 6 years ago
parent 0a11631aa9
commit e9b3a5aea6

@ -1,20 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<classpath> <classpath>
<classpathentry kind="src" path="src"/> <classpathentry kind="src" path="src"/>
<classpathentry exported="true" kind="lib" path="/home/nicolas/Bureau/jdbc-support-1.0.23-sources.jar"> <classpathentry kind="lib" path="/home/nicolas/eclipse-workspace/Projet_Java/JAVA/PROJET-PMT_STRI1A/src/jdbc.jar">
<attributes> <attributes>
<attribute name="module" value="true"/> <attribute name="module" value="true"/>
</attributes> </attributes>
</classpathentry> </classpathentry>
<classpathentry exported="true" kind="lib" path="/home/nicolas/Téléchargements/gson-2.8.5.jar"> <classpathentry kind="lib" path="/home/nicolas/eclipse-workspace/Projet_Java/JAVA/PROJET-PMT_STRI1A/src/gson-2.6.2.jar">
<attributes> <attributes>
<attribute name="module" value="true"/> <attribute name="module" value="true"/>
</attributes> </attributes>
</classpathentry> </classpathentry>
<classpathentry exported="true" kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-11"> <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
<attributes> <attributes>
<attribute name="module" value="true"/> <attribute name="module" value="true"/>
</attributes> </attributes>
</classpathentry> </classpathentry>
<classpathentry kind="lib" path="/home/nicolas/eclipse-workspace/Projet_Java/JAVA/PROJET-PMT_STRI1A/src/javatuples-1.2.jar"/>
<classpathentry kind="lib" path="/home/nicolas/Téléchargements/swt-linux-gtk-x64.jar/swt-linux-gtk-x64.jar"/>
<classpathentry kind="lib" path="swing2swt.jar"/>
<classpathentry kind="output" path="bin"/> <classpathentry kind="output" path="bin"/>
</classpath> </classpath>

@ -1,12 +1,12 @@
eclipse.preferences.version=1 eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=11 org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=11 org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.debug.lineNumber=generate org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.release=enabled org.eclipse.jdt.core.compiler.release=enabled
org.eclipse.jdt.core.compiler.source=11 org.eclipse.jdt.core.compiler.source=1.8

Binary file not shown.

After

Width:  |  Height:  |  Size: 939 KiB

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="src" path=""/>
<classpathentry kind="output" path=""/>
</classpath>

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>src</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>

@ -0,0 +1,33 @@
/**
*
*/
package gui;
import java.awt.FlowLayout;
import java.awt.Graphics;
import java.awt.GridBagLayout;
import javax.swing.ImageIcon;
import javax.swing.JPanel;
/**
* @author nicolas
*
*/
public class Background extends JPanel{
private ImageIcon image;
public Background(String path) {
super();
//this.setLayout(new FlowLayout());
this.image=new ImageIcon(path);
}
public void setBackground(ImageIcon back) {
this.image=back;
}
public void paintComponent(Graphics gr) {
super.paintComponent(gr);
gr.drawImage(image.getImage(),0,0,this);
}
}

@ -0,0 +1,30 @@
/**
*
*/
package gui;
import java.awt.Color;
import java.awt.FlowLayout;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.SwingConstants;
/**
* @author nicolas
*
*/
public class Boutton extends JButton {
public Boutton(String txt) {
super(txt);
//this.setLayout(new FlowLayout());
setForeground(Color.WHITE);
setOpaque(true);
setContentAreaFilled(false);
setBorderPainted(true);
setFocusPainted(false);
setHorizontalAlignment(SwingConstants.CENTER);
setVerticalAlignment(SwingConstants.CENTER);
}
}

@ -4,12 +4,23 @@
package gui; package gui;
import java.awt.BorderLayout; import java.awt.BorderLayout;
import java.awt.Color;
import gui.Boutton;
import gui.Background;
import java.awt.Dimension; import java.awt.Dimension;
import java.awt.FlowLayout; import java.awt.FlowLayout;
import java.awt.GraphicsConfiguration; import java.awt.GraphicsConfiguration;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.HeadlessException; import java.awt.HeadlessException;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.nio.file.attribute.AclEntry.Builder; import java.nio.file.attribute.AclEntry.Builder;
import javax.imageio.ImageIO;
import javax.swing.ImageIcon;
import javax.swing.JButton; import javax.swing.JButton;
import javax.swing.JFrame; import javax.swing.JFrame;
import javax.swing.JLabel; import javax.swing.JLabel;
@ -24,34 +35,46 @@ import org.eclipse.swt.SWT;
public class jeu extends JFrame { public class jeu extends JFrame {
public jeu() { public jeu() throws IOException {
super(); super();
build(); build();
} }
public void build() { public void build() throws IOException{
setTitle("Jeu"); setTitle("Jeu");
setSize(800,600); setSize(593,283);
setLocationRelativeTo(null); setLocationRelativeTo(null);
setResizable(false); setResizable(false);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JPanel center = new JPanel();
Dimension taille = new Dimension(200,200);
center.setPreferredSize(taille); JLabel container = new JLabel(new ImageIcon(this.image()));
center.add(new JButton("Jouer"));
this.setLayout(new BorderLayout());
this.getContentPane().add(buildContentPane(), BorderLayout.NORTH); container.setLayout(new GridBagLayout());
this.getContentPane().add(center, BorderLayout.CENTER); JButton test2 = new JButton("Nouvelle Partie");
JButton test =new JButton("Continuer");
GridBagConstraints c = new GridBagConstraints();
c.gridx = 0;
c.gridy = 0;
container.add(test);
c.gridx = 1;
c.gridy=0;
container.add(test2);
this.setContentPane(container);
this.setVisible(true);
} }
public JPanel buildContentPane() { public JPanel buildContentPane() {
JPanel panel =new JPanel();
Dimension preferredSize = new Dimension(200,200);
panel.setLayout(new FlowLayout());
JLabel label = new JLabel("Jeu Dragon Donjon");
panel.add(label);
return panel;
}
public BufferedImage image() throws IOException {
BufferedImage image = ImageIO.read(new File("/home/nicolas/eclipse-workspace/Projet_Java/JAVA/PROJET-PMT_STRI1A/test.jpg"));
return image;
} }

@ -4,6 +4,7 @@
package gui; package gui;
import java.awt.Dialog; import java.awt.Dialog;
import java.io.IOException;
import javax.swing.SwingUtilities; import javax.swing.SwingUtilities;
@ -21,7 +22,13 @@ public class main {
SwingUtilities.invokeLater(new Runnable(){ SwingUtilities.invokeLater(new Runnable(){
public void run(){ public void run(){
//On crée une nouvelle instance de notre JDialog //On crée une nouvelle instance de notre JDialog
jeu fenetre = new jeu(); jeu fenetre = null;
try {
fenetre = new jeu();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
fenetre.setVisible(true);//On la rend visible fenetre.setVisible(true);//On la rend visible
} }
}); });

Binary file not shown.

After

Width:  |  Height:  |  Size: 32 KiB

Loading…
Cancel
Save