JPanelDessin

This commit is contained in:
Antoine GAGNEUX 2019-02-04 15:44:44 +01:00
commit 409baab288
7 changed files with 124 additions and 0 deletions

6
.classpath Normal file
View File

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

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
/bin/

17
.project Normal file
View File

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>ExempleJPanelDessin</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>

View File

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

13
src/ClassePrincipale.java Normal file
View File

@ -0,0 +1,13 @@
import packageIHM.MaJFrame;
/**
* <p>Titre : Classe Principale</p>
* @author Antoine GAGNEUX
* @version 1.0
*/
public class ClassePrincipale {
public static void main(String[] args) {
MaJFrame maFen = new MaJFrame();
maFen.setVisible(true);
}
}

View File

@ -0,0 +1,40 @@
package packageIHM;
import java.awt.*;
import javax.swing.*;
public class JPanelDessin extends JPanel {
private static final long serialVersionUID = -4704888296894874299L;
public JPanelDessin() {
}
/**
* redéfinition de la methode paintComponent
* @param g
*/
public void paintComponent(Graphics g) {
super.paintComponent(g);
// Couleur du fond = blanc
this.setBackground(Color.white);
// Affiche une ligne bleue en diagonale
g.setColor(Color.blue);
g.drawLine(0, 0, this.getWidth(), this.getHeight());
// Affiche un cercle noir au centre
g.setColor(Color.black);
g.drawOval( this.getWidth() / 2, this.getHeight() / 2, 10, 10);
// Affiche un rectangle vide rouge
g.setColor(Color.red);
g.drawRect(100, 100, 20, 20);
// Affiche un rectangle plein vert
g.setColor(Color.green);
g.fillRect(200, 50, 20, 20);
}
}

View File

@ -0,0 +1,36 @@
package packageIHM;
import java.awt.BorderLayout;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JButton;
public class MaJFrame extends JFrame {
private static final long serialVersionUID = 7252959164975426293L;
private JPanel contentPane;
private JPanelDessin panel_1;
/**
* Create the frame.
*/
public MaJFrame() {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 450, 300);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
contentPane.setLayout(new BorderLayout(0, 0));
setContentPane(contentPane);
JPanel panel = new JPanel();
contentPane.add(panel, BorderLayout.NORTH);
JButton btnNewButton = new JButton("Ne fait Rien !");
panel.add(btnNewButton);
panel_1 = new JPanelDessin();
contentPane.add(panel_1, BorderLayout.CENTER);
}
}