begin process at 2010 02 09 21:01:48
  Trouver un code source :
 
dans
 
Accueil > 

Code

 > 

Java2D

 > JPANEL TEXTE DÉFILANT : MARQEE EN JAVA

JPANEL TEXTE DÉFILANT : MARQEE EN JAVA


 Information sur la source

Note :
Aucune note
Catégorie :Java2D Classé sous :dessin, java2d, swing, thread, jpanel Niveau :Initié Date de création :03/07/2008 Date de mise à jour :03/07/2008 00:53:11 Vu :5 214

Auteur : co2_gaz

Ecrire un message privé
Commentaire sur cette source (0)
Ajouter un commentaire et/ou une note

 Description

Exemple de redéfinition d'un JPanel (Dessin, Thread)

Classe permettant de reproduire un effet page web TEXTE DÉFILANT
la classe contient un main tester pour voir

Source

  • import java.awt.AlphaComposite;
  • import java.awt.BasicStroke;
  • import java.awt.BorderLayout;
  • import java.awt.Color;
  • import java.awt.Component;
  • import java.awt.Font;
  • import java.awt.Graphics;
  • import java.awt.Graphics2D;
  • import java.awt.Image;
  • import javax.swing.JComponent;
  • import javax.swing.JFrame;
  • import javax.swing.JPanel;
  • /**
  • *
  • * @author NOURI
  • *
  • */
  • public class NPbrogressComponent extends JPanel{
  • private RenderingThread renderingThread = new RenderingThread();
  • private Component parent;
  • private Color backGround = Color.black;
  • private Color forgeGround = Color.red;
  • private Graphics2D g2d;
  • private Image image;
  • boolean intro;
  • int x = 0;
  • private int height=45;
  • private int width;
  • private float composite;
  • String msg1 = "NOURI";
  • String msg2 = "MARWEN";
  • /**
  • *
  • */
  • public NPbrogressComponent(JComponent parent){
  • this.setBackground(backGround);
  • this.parent= this.getParent();
  • this.setOpaque(false);
  • // if(parent!=null){
  • // this.parent = parent;
  • // System.out.println("zzzzzzzzzzzzzzz");
  • // height = parent.getHeight();
  • // width = parent.getWidth();
  • // }
  • }
  • public void start(){
  • renderingThread.start();
  • }
  • public void stop(){
  • renderingThread.stop();
  • }
  • /**
  • * utilisation de paint plutôt que paintComponet
  • * effet transparence oblige
  • */
  • public void paint( Graphics g ){
  • int h = height+6;
  • width = getWidth();
  • g2d = (Graphics2D) g;
  • //g2d.setColor(backGround);
  • if(!intro){
  • g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, composite ));
  • composite+=.1f;
  • //g2d.fillRect( 0, 0, width, height);
  • g2d.clearRect( 0, 0, width, height);
  • g2d.setColor(forgeGround);
  • g2d.setStroke(new BasicStroke( 2.0f ));
  • g2d.drawLine(0 ,h/2+5, width, h/2+5);
  • g2d.setFont(new Font("Arial",1,16));
  • g2d.drawString( " NOURI 2008", x, h/2 );
  • try {
  • Thread.sleep(160);
  • } catch (InterruptedException e) {
  • }
  • if(composite>.9f){
  • intro=!intro;
  • //g2d.clearRect(0, 0, width, height);
  • }
  • }else{
  • //g2d.fillRect( 0, 0, width, height);
  • g2d.clearRect( 0, 0, width, height);
  • g2d.setColor(forgeGround);
  • //g2d.drawString( "NOURIStyle", x, h/2 );
  • //g2d.setStroke(new BasicStroke( 9.0f ));
  • g2d.setFont(new Font("Arial",1,14));
  • g2d.drawString( msg1, x, h/2 );
  • //
  • if(x>(width/2)-10){
  • //g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.8f ));
  • if(x%2 == 0){
  • h-=2;
  • }else{
  • h+=2;
  • }
  • }
  • //System.out.println(height);
  • g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.7f ));
  • g2d.drawString(msg2, (width)-x, h/2 );
  • x++;
  • if(x>width){
  • x = 0;
  • String tmp = msg2;
  • msg2=msg1;
  • msg1=tmp;
  • }
  • }
  • //g.drawImage(image, 0, 0, this);
  • //g.drawImage(image2, (width), 0, this);
  • }
  • /**
  • *
  • * @param compotent
  • */
  • public void setParent(Component compotent){
  • this.parent= compotent;
  • }
  • class RenderingThread extends Thread {
  • /**
  • *
  • */
  • public void run(){
  • while(true){
  • try {
  • repaint();
  • sleep(15);
  • } catch ( Exception e ) {}
  • }
  • }
  • }
  • public static void main(String[] args){
  • JFrame f= new JFrame();
  • f.setLocationRelativeTo(null);
  • JPanel n = new JPanel(new BorderLayout());
  • NPbrogressComponent d =new NPbrogressComponent(n);
  • n.add(d);
  • f.add(n);
  • d.start();
  • f.setVisible(true);
  • f.setSize(400, 444);
  • //f.pack();
  • f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  • }
  • }
import java.awt.AlphaComposite;
import java.awt.BasicStroke;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;

import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.JPanel;

	/**
	 * 
	 * @author NOURI
	 *
	 */
public class NPbrogressComponent extends JPanel{

	private RenderingThread renderingThread = new RenderingThread();
	private Component parent;
	private Color backGround = Color.black;
	private Color forgeGround = Color.red;
	private Graphics2D g2d;
	private Image image; 
	boolean intro;
	int x = 0;
	private int height=45;
	private int width;
	private float composite;




	String msg1 = "NOURI";
	String msg2 =  "MARWEN";

	/**
	 * 
	 */
	public NPbrogressComponent(JComponent parent){
		this.setBackground(backGround);
		this.parent= this.getParent();
		this.setOpaque(false);
		//		if(parent!=null){
		//			this.parent = parent;
		//			System.out.println("zzzzzzzzzzzzzzz");
		//			height = parent.getHeight();
		//			width = parent.getWidth();
		//		}


	}


	public void start(){
		renderingThread.start();
	}

	public void stop(){
		renderingThread.stop();

	}


	/**
	 * utilisation de paint plutôt que paintComponet
         * effet transparence oblige
	 */
	public void paint( Graphics g ){

		int h = height+6;
		width  = getWidth();

		g2d = (Graphics2D) g;
		//g2d.setColor(backGround);

		if(!intro){
			g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, composite ));
			composite+=.1f;

			//g2d.fillRect( 0, 0, width, height);
			g2d.clearRect( 0, 0, width, height);
			g2d.setColor(forgeGround);
			g2d.setStroke(new BasicStroke( 2.0f ));
			g2d.drawLine(0 ,h/2+5, width, h/2+5);
			g2d.setFont(new Font("Arial",1,16));
			g2d.drawString( "    NOURI 2008", x, h/2 );
			try {
				Thread.sleep(160);
			} catch (InterruptedException e) {
			}
			if(composite>.9f){
				intro=!intro;
				//g2d.clearRect(0, 0, width, height);
			}
		}else{
			//g2d.fillRect( 0, 0, width, height);
			g2d.clearRect( 0, 0, width, height);
			g2d.setColor(forgeGround);

			//g2d.drawString( "NOURIStyle", x, h/2 );
			//g2d.setStroke(new BasicStroke( 9.0f ));	
			g2d.setFont(new Font("Arial",1,14));

			g2d.drawString( msg1, x, h/2 );

			//
			if(x>(width/2)-10){
				//g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.8f ));
				if(x%2 == 0){
					h-=2;
				}else{
					h+=2;
				}
			}
			//System.out.println(height);
			g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.7f ));
			g2d.drawString(msg2, (width)-x, h/2 );

			x++;
			if(x>width){
				x = 0;
				String tmp = msg2;
				msg2=msg1;
				msg1=tmp;
			}
		}
		//g.drawImage(image, 0, 0, this);
		//g.drawImage(image2, (width), 0, this);
	}

	/**
	 * 
	 * @param compotent
	 */
	public void setParent(Component compotent){
		this.parent= compotent;

	}


	class RenderingThread extends Thread {
		/**
		 * 
		 */
		public void run(){
			while(true){
				try {
					repaint(); 
					sleep(15);
				} catch ( Exception e ) {} 
			}
		}
	}   



	public static void main(String[] args){

		JFrame f= new JFrame();
		f.setLocationRelativeTo(null);
		JPanel n = new JPanel(new BorderLayout());
		NPbrogressComponent d =new NPbrogressComponent(n);
		n.add(d);

		f.add(n);
		d.start();
		f.setVisible(true);
		f.setSize(400, 444);

		//f.pack();
		f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

	}
}



 Historique

03 juillet 2008 00:53:11 :
rien

 Sources du même auteur

EXEMPLE PARSEUR DOM

 Sources de la même categorie

AFFICHER UNE ÉTOILE AVEC JAVA2D par 2mohamed2
TEXTE AVEC OMBRE par 2mohamed2
Source avec Zip Source avec une capture JBOXIKON PORTAGE DE BOXIKON par ulm950
Source avec Zip Source avec une capture AQUARIUM 2D AVEC DOUBLE-BUFFERING ET EN UTILISANT UNIQUEMENT... par Cornellus1985
Source avec Zip Source avec une capture JPANELTEXTEDEFILANT : FAIRE DEFILER DU TEXTE (PLUSIEURES MAN... par loloof64

 Sources en rapport avec celle ci

Source avec Zip Source avec une capture AQUARIUM 2D AVEC DOUBLE-BUFFERING ET EN UTILISANT UNIQUEMENT... par Cornellus1985
Source avec Zip PETITE ANIMATION EN JAVA par devmouad
Source avec Zip Source avec une capture LANCE REQUETES COMPLET par pouicky
Source avec Zip Source avec une capture JEU LE PENDU par momoSahli
Source avec Zip Source avec une capture OBSERVABLE DANS L'EDT (EVITE LE RECOURS À SWINGUTILITIES.INV... par pouicky

Commentaires et avis

Aucun commentaire pour le moment.

 Ajouter un commentaire


Discussions en rapport avec ce code source dans le forum

Afficher une image ... galère ... [ par Asrull ] Alors voilà j'ai un gros problème et je tourne en rond depuis deux plombes la dessus. Le but de maclasse c'est juste de créer un composant swing affic Composants swing et fond transparent !!! [ par wt ] Salut tlm,Comment affecte-t-on une couleur transparente à un composants swing, un JPanel par exemple ?Je dispose d'1 couleur en gradient : son intensi swing, gridbaglayout et dessin [ par nonoz ] Bonjour,j'utilise swing.je viens de faire en gridbaglayout dans lequel j'ai mis des boutons.Maintenant j'aimerais pouvoir avoir une zone dans laquel d Problème de dessin qui s'efface [ par Reeper ] Bonjour à tous, j'apprend le java pendant mes études et j'ai un petit programme a faire qui réalise divers opérations dont une con AU SECOURS: pb d'affichage swing [ par tlehoucq ] Bonjour, voila mon pb: comment faire pour afficher des composants swing au premier plan, je m'explique: je veux afficher un JLabel au des [Swing]JdesktopPane dans un JPanel [ par terminagroo ] Bonjour,Voilà je cherche à ajouter un JDesktopPane dans un JPanel. En fait ce que je veux c'est avoir un panel dans lequel je puisse avoir p Aide vrai débutant ! [ par assoul ] Bonjour, Voila je rencontre qqes difficultés pour un projet de la fac et j'aimerais avoir qqes explications sur certains points : Je n'arrive p Erreur "Unknow Source" : HELP ME !!!! [ par Foub12 ] Bonjour, je vous soumets un problème que je rencontre depuis ce matin et dontje ne vois vraiment pas comment m'en sortir...Jé développe [Swing] Comment regénérer un JPanel [ par coinki ] Bonjour,J'ai un JPanel qui suivant une certaine valeur contient des composants différents. Lorsque j'appuie sur un bouton, je voudrai que ça passe de Tit prob de base avec SWING dans eclipse et JPANEL [ par Nargzul ] Bonjour,Je me mets gentillement à java, et avec eclipse, je suis en train de créer une interface utilisateur.Donc comme on m'a dit, je cr&#2


Nos sponsors


Sondage...

Comparez les prix

CalendriCode

Février 2010
LMMJVSD
1234567
891011121314
15161718192021
22232425262728

Consulter la suite du CalendriCode

 
Développement réalisé par Nicolas SOREL (Nix) avec l'aide de : Cyril DURAND et Emmanuel (EBArtSoft), Merci à Vincent pour ses précieux conseils.
CodeS-SourceS.com© Toute reproduction même partielle est interdite sauf accord écrit du Webmaster
CodeS-SourceS.com© est une marque déposée tous droits réservés

Google Coop CodeS-SourceS Google Coop CodeS-SourceS
Temps d'éxécution de la page : 0,889 sec (4)

Nous contacter | Annoncer sur CodeS-SourceS | Mentions légales