Import java. AWT. color;
Import java. AWT. Font;
Import java. AWT. graphics;
Import java. AWT. graphicsenvironment;
Import java. AWT. image;
Import java. AWT. Panel;
Public class text3dpanel extends panel implements runnable {
Private image; // import java. AWT. color;
Import java. AWT. Font;
Import java. AWT. graphics;
Import java. AWT. graphicsenvironment;
Import java. AWT. image;
Import java. AWT. Panel;
Public class text3dpanel extends panel implements runnable {
Private image; // The image object for drawing text
Private graphics; // graphics object for drawing text
Private thread; // display 3D text threads
Private int width, height; // display width and height
Private string message; // display information
Private int fontsize; // text size
Private Font font; // font
Private string [] fonts;
Public text3dpanel (string message, int width, int height ){
This. Message = message;
This. width = width;
This. Height = height;
Init ();
Start ();
}
Public void Init (){
Image = createimage (width, height); // obtain the image instance
// Graphics = image. getgraphics (); // obtain the grahpics instance.
If (Message = NULL) {// if the information is null
Message = "3D text"; // set the default information
}
Fontsize = 30; // set the font size
Graphicsenvironment eq = graphicsenvironment. getlocalgraphicsenvironment ();
Fonts = Eq. getavailablefontfamilynames ();
// Fonts = toolkit. getdefatooltoolkit (). getfontlist ();
}
Public void start (){
If (thread = NULL ){
Thread = new thread (this); // instantiate the thread
Thread. Start (); // The Running thread.
}
}
Public void run () {// thread running entity
While (thread! = NULL ){
Try {
Thread. Sleep (300l); // thread sleep
} Catch (interruptedexception ex ){
}
Repaint (); // repaint the screen
}
}
Public void Update (Graphics g ){
Int Index = (INT) (math. Random () * fonts. Length );
Font = new font (fonts [Index], 1, fontsize); // get the font instance
// Font = new font ("timesroman", 1, fontsize); // get the font instance
G. setfont (font); // set the font.
Int J = (INT) (255 * Math. Random (); // variable used to generate gradient colors
Int K = (INT) (255 * Math. Random ());
Int L = (INT) (255 * Math. Random ());
// Int J = 200;
// Int K = 192;
// Int L = 200;
System. Out. println (J + "," + K + "," + L + "," + index );
G. setcolor (color. Black); // sets the current color.
G. fillrect (0, 0, width, height); // fill the background
// Draws a 6-layer background color string
For (INT I = 0; I <6; I ++) {// 3D depth
G. setcolor (// set the gradient color
New Color (
255-(255-j) * I)/10,
255-(255-k) * I)/10,
255-(255-l) * I)/10 ));
G. drawstring (message, 15-I, height-15-i); // draw a string
}
// Overwrite the string to the screen
G. drawimage (image, 0, 0, this); // draw the image to the screen
}
Public void paint (Graphics g ){
Update (g );
}
} Image object
Private graphics; // graphics object for drawing text
Private thread; // display 3D text threads
Private int width, height; // display width and height
Private string message; // display information
Private int fontsize; // text size
Private Font font; // font
Private string [] fonts;
Public text3dpanel (string message, int width, int height ){
This. Message = message;
This. width = width;
This. Height = height;
Init ();
Start ();
}
Public void Init (){
Image = createimage (width, height); // obtain the image instance
// Graphics = image. getgraphics (); // obtain the grahpics instance.
If (Message = NULL) {// if the information is null
Message = "3D text"; // set the default information
}
Fontsize = 30; // set the font size
Graphicsenvironment eq = graphicsenvironment. getlocalgraphicsenvironment ();
Fonts = Eq. getavailablefontfamilynames ();
// Fonts = toolkit. getdefatooltoolkit (). getfontlist ();
}
Public void start (){
If (thread = NULL ){
Thread = new thread (this); // instantiate the thread
Thread. Start (); // The Running thread.
}
}
Public void run () {// thread running entity
While (thread! = NULL ){
Try {
Thread. Sleep (300l); // thread sleep
} Catch (interruptedexception ex ){
}
Repaint (); // repaint the screen
}
}
Public void Update (Graphics g ){
Int Index = (INT) (math. Random () * fonts. Length );
Font = new font (fonts [Index], 1, fontsize); // get the font instance
// Font = new font ("timesroman", 1, fontsize); // get the font instance
G. setfont (font); // set the font.
Int J = (INT) (255 * Math. Random (); // variable used to generate gradient colors
Int K = (INT) (255 * Math. Random ());
Int L = (INT) (255 * Math. Random ());
// Int J = 200;
// Int K = 192;
// Int L = 200;
System. Out. println (J + "," + K + "," + L + "," + index );
G. setcolor (color. Black); // sets the current color.
G. fillrect (0, 0, width, height); // fill the background
// Draws a 6-layer background color string
For (INT I = 0; I <6; I ++) {// 3D depth
G. setcolor (// set the gradient color
New Color (
255-(255-j) * I)/10,
255-(255-k) * I)/10,
255-(255-l) * I)/10 ));
G. drawstring (message, 15-I, height-15-i); // draw a string
}
// Overwrite the string to the screen
G. drawimage (image, 0, 0, this); // draw the image to the screen
}
Public void paint (Graphics g ){
Update (g );
}
}