monstor_rox
Messages postés18Date d'inscriptionmardi 31 mai 2005StatutMembreDernière intervention15 janvier 2007
-
12 nov. 2005 à 11:38
bastet1978
Messages postés54Date d'inscriptionlundi 29 septembre 2003StatutMembreDernière intervention 4 décembre 2005
-
14 nov. 2005 à 23:49
Bonjour
J'ai besoin de votre aide car je n'ai jamais fait d'interfaces
graphiques en java et là j'ai un exercice qui va vous paraitre tout
bête mais je n'arrive pa a le faire.
Le voici : Créer une application
TestGraphic
, héritant de
JFrame
. Créer
un composant
DrawComponent
, inscrit dans
TestGraphic
,
qui affiche 3 cercles et un rectangle, dont voici les caractéristiques
:
Circle1 x 200,y 200,r = 100 ;
Circle2 x 160,y 150,r = 20 ;
Circle3 x 240,y 150,r = 20
et le Rectangle x 150,y 220,w = 100, h = 40. (voir 3.0)
bastet1978
Messages postés54Date d'inscriptionlundi 29 septembre 2003StatutMembreDernière intervention 4 décembre 2005 12 nov. 2005 à 15:53
Bonjour,
Les JFrame sont simples voici le minimum à faire:
JFrame placée au centre de l'écran de taille 800,600 nommée TestGraphics :
public class TestGraphics extends javax.swing.JFrame {
public CreerSculpture() {
super("TestGraphics"); // un titre
DrawComponent dc = new DrawComponent; // un panel pour dessiner.
Container c = getContentPane(); // de quoi ajouter le panel
c.setLayout(new BorderLayout()); // ajoute un layout (nors, sud, est, ouest, centre)
c.add(dc, BorderLayout.CENTER); // ajout du panel au JFrame au centre
// visualisation
int width = 800;
int height = 600;
int w = (int) Toolkit.getDefaultToolkit().getScreenSize().width;
int h = (int) Toolkit.getDefaultToolkit().getScreenSize().height;
setLocation((w/2)-(width/2), (h/2)-(height/2));
setVisible(true);
}
public static void main(String[] args) {
TestGraphics tg = new TestGraphics();
}
}
Class DrawComponent (un JPanel overwrited pour dessiner) voici le minimum:
import java.awt.Graphics;
import java.awt.Dimension;
public class DrawComponent extends javax.swing.JPanel {
public DrawComponent(){
}
// partie pour dessiner
protected void paintComponent(Graphics g) {
super.paintComponent(g);
// cercle
g.drawArc(200,200, 100, 100, 0, 360);
}
public Dimension getMinimumSize(){
return new Dimension(800, 600);
}
public Dimension getPreferredSize(){
return getMinimumSize();
}
public Dimension getMaximumSize(){
return getMinimumSize();
}
}
A toi de trouver le reste, ça devrait aller vite.
----
OS: Ubuntu 5.10(linux)
jdk : 1.5.0
MysqlConnector/J: 3.2
mysql Ver 12.22 Distrib 4.0.24, for pc-linux-gnu (i486)
----
monstor_rox
Messages postés18Date d'inscriptionmardi 31 mai 2005StatutMembreDernière intervention15 janvier 2007 13 nov. 2005 à 16:13
merci beaucoup mais j'ai 3 warning :
- The serializable class DrawComponent does not declare a static final serialVersionUID field of type long DrawComponent.
- The serializable class TestGraphic does not declare a static final serialVersionUID field of type long TestGraphic.java
- The local variable tg is never read TestGraphic.java