Forum |  HardWare.fr | News | Articles | PC | S'identifier | S'inscrire | Shop Recherche
1667 connectés 

  FORUM HardWare.fr
  Programmation

  [Java/Swing/Graphics] pbl d'affichage

 


 Mot :   Pseudo :  
 
Bas de page
Auteur Sujet :

[Java/Swing/Graphics] pbl d'affichage

n°18341
aurel
Fraggueur en liberté
Posté le 13-03-2001 à 11:59:31  profilanswer
 

J'ai réalisé une classe X qui extends JComponent
dans cette classe y'a notemment le constructeur
et une fonction paint.
dans le main, pour le test, je crée une jframe et cinq objets de la classe X
losque je fait myjframe.getcontentpane().add<nom de mes cinq objes 1 par 1>, y'a un objet qui s'affiche pas.
le layout est celui par défaut (flowlayout).
 
je vois pas dou ca vient, si vou voulez le source, dites, l'est pas dur a comprendre

mood
Publicité
Posté le 13-03-2001 à 11:59:31  profilanswer
 

n°18353
wouatouwou​atou
Posté le 13-03-2001 à 13:30:09  profilanswer
 

un peu limit ta description :D... code plz :jap:


---------------
"C'est le boulot qu'on ne commence jamais qui est le plus long à terminer"
n°18390
aurel
Fraggueur en liberté
Posté le 13-03-2001 à 16:34:58  profilanswer
 

en fait j'

n°18391
aurel
Fraggueur en liberté
Posté le 13-03-2001 à 16:38:12  profilanswer
 

en fait j'ai pigé une partie de mon probleme, ma question est maintenant: comment qu'on fait pour rajouter des drawline, fillrect..., sans les mettre dans la fonction paint() de la classe?
le paint est appelé par le contructeur, et je voudrais ajouter un rectangle quand on appele une certaine fonction de la classe (genre addrectangle)  
est ce clair ?
 
Merci

n°18396
aurel
Fraggueur en liberté
Posté le 13-03-2001 à 17:22:46  profilanswer
 

Ouais ba non j'es suis revenu a l'ancienne méthode, voila le code:package com.intoan.peditor.gui;
 
import javax.swing.JComponent;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Dimension;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.swing.JFrame;
 
public class ProcessorEditorButton extends JComponent
{
 public static final Color BACKCOLOR = new Color(150,150,150); // color of the Editor
 public static final int COMPACTSQUARE = 12; // Compactness of the scope of the square interior
 public static final int WIDHTSQUARE = 64; // Largeur et hauteur du carré
 public static final int COORDONATE = 50; // coordonnées of the top-left corner of the square
 public static final int TOP = 1;
 public static final int BOTTOM = 2;
 public static final int LEFT = 3;
 public static final int RIGHT = 4;
 public static final int ARCWIDHT = 8 ; //widht and height od the arc of the lttle square
 public int ALIGN;
 public int[] Coor;
 public int x,y,c,w;
 
 
 public ProcessorEditorButton(int align, int x, int y,int c, int w )
 {
  ALIGN = align;
  this.x = x;  //Coordonate x of the topbottom point of the interior square
  this.y = y;  //Coordonate y of the topbottom point of the interior square
  this.c = c;  //widht of the interior square
  this.w = w;  //compactness of the big square
  Coor = getCoordinate(ALIGN,x,y,c,w);
  setSize(new Dimension(100,100));
 }
 
 public void paint(Graphics g)
 {
 
  g.setColor(ProcessorEditorIcon.BACKCOLOR);
  g.fillRect(COORDONATE,COORDONATE,WIDHTSQUARE,WIDHTSQUARE);  
  g.setColor(Color.white);
  g.fillRect(COORDONATE+(COMPACTSQUARE/2),COORDONATE+(COMPACTSQUARE/2),WIDHTSQUARE-COMPACTSQUARE,WIDHTSQUARE-COMPACTSQUARE);  
  g.setColor(ProcessorEditorIcon.BACKCOLOR);
  switch (ALIGN)
  {
   case 1:
    g.fillRoundRect(Coor[0],Coor[1],(WIDHTSQUARE/2),(WIDHTSQUARE/4)+(WIDHTSQUARE/8),ARCWIDHT,ARCWIDHT);
    break;
   case 2:
    g.fillRoundRect(Coor[0],Coor[1],(WIDHTSQUARE/2),(WIDHTSQUARE/4)+(WIDHTSQUARE/8),ARCWIDHT,ARCWIDHT);
    break;
   case 3:
    g.fillRoundRect(Coor[0],Coor[1],(WIDHTSQUARE/4)+(WIDHTSQUARE/8),(WIDHTSQUARE/2),ARCWIDHT,ARCWIDHT);
    break;
   case 4:
    g.fillRoundRect(Coor[0],Coor[1],(WIDHTSQUARE/4)+(WIDHTSQUARE/8),(WIDHTSQUARE/2),ARCWIDHT,ARCWIDHT);
    break;
  }
 }
 
 
/* getCoordinate
* Return the coordonate of the top bottom point if the littke square to be displayed
*
*
**/
 
 public int[] getCoordinate(int a, int xx, int yy, int cc, int ww)
 {
  int xp,yp;
  int align = a;
  int x = xx;
  int y = yy;
  int c = cc;
  int w = ww;  
  xp = 0;
  yp = 0;
  switch (align)
  {
   case 1: // top
    xp = x + w/4;
    yp = y - w/4 -w/16;
    break;
   case 2: // Bottom
    xp = x + w/4;
    yp = y + w - w/16;
    break;
   case 3: // left
    xp = x -w/4 -w/16;
    yp = y +w/4;
    break;
   case 4: // right
    xp = x + w - w/16;
    yp = y + w/4;
   break;
  }
  int[] coord = new int[2];  
  coord[0] = xp;
  coord[1] = yp;
  return coord;    
 }
 
 
 public static void main (String[] args)
 {
  JFrame jf = new JFrame("Little Button Icon" );
  jf.getContentPane().setBackground(Color.white);
  jf.setBackground(Color.white);
  JComponent jc = (JComponent) jf.getContentPane();
  jc.setPreferredSize(new Dimension(200,200));
  ProcessorEditorButton peb1 = new ProcessorEditorButton(TOP,COORDONATE,COORDONATE,COMPACTSQUARE,WIDHTSQUARE);
  jf.getContentPane().add(peb1);
  ProcessorEditorButton peb3 = new ProcessorEditorButton(LEFT,COORDONATE,COORDONATE,COMPACTSQUARE,WIDHTSQUARE);
  jf.getContentPane().add(peb3);
  ProcessorEditorButton peb4 = new ProcessorEditorButton(RIGHT,COORDONATE,COORDONATE,COMPACTSQUARE,WIDHTSQUARE);
  jf.getContentPane().add(peb4);
  ProcessorEditorButton peb2 = new ProcessorEditorButton(BOTTOM,COORDONATE,COORDONATE,COMPACTSQUARE,WIDHTSQUARE);
  jf.getContentPane().add(peb2);
  System.out.println(jf.getContentPane().getComponents().length);
   
  jf.pack();
  jf.setVisible(true);
  jf.addWindowListener(new WindowAdapter(){
   public void windowClosing(WindowEvent we){ System.exit(0) ; }
  });
 }
}
 
 
 
 
ouais c comme meme un gros morceau, il  est compilable en direct j'import pas de classe a moi.si t'es motiv' wouatouwouatou,merci


Aller à :
Ajouter une réponse
  FORUM HardWare.fr
  Programmation

  [Java/Swing/Graphics] pbl d'affichage

 

Sujets relatifs
[JAVA]signature d'appletProblème de Java....
comment transformer un applet java en programme a par entiere ?utilisation JRE et java Urgent!!
[JAVA] lire les donnes d'un fichier textProbleme Applet Java
[JAVA] ScrollPanes...[Java] Recuperer l'ip d'un server irc...
[JAVA] Probleme avec les fonctions statiques[JAVA] Cherche doc complete !
Plus de sujets relatifs à : [Java/Swing/Graphics] pbl d'affichage


Copyright © 1997-2022 Hardware.fr SARL (Signaler un contenu illicite / Données personnelles) / Groupe LDLC / Shop HFR