|
Dernière réponse | |
---|---|
Sujet : [Java/Swing/Graphics] pbl d'affichage | |
aurel | 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 |
Vue Rapide de la discussion |
---|