Java program for scrolling text display

Source: Internet
Author: User
/**
* File name: scrollframe. Java
* Environment: GNU/Linux Ubuntu 7.04 + eclipse 3.2 + JDK 1.6
* Function: Scroll text display panel demo
* Version: 0.0.2.0
* Version change: the source code in version 0.0.1.0 is simplified, and the bug that text cannot be displayed at the beginning is fixed.
* Authors: 88250
* Date: 2007.5.3
* E-mail & MDN: DL88250@gmail.com
* QQ: 845765
*/

Import java. AWT .*;
Import javax. Swing .*;

Public class scrollframe extends jframe
{
Public static string [] textcontent = {"this", "is", "A", "simple", "Demo! "};

Public scrollframe ()
{
Super ("scroll text display by 88250 ");
Scrollpane news = new scrollpane ();
Setbounds (600,300,370,200 );
Setresizable (false );
Setdefaclocloseoperation (jframe. exit_on_close );
Jpanel pane = new jpanel ();
Pane. setlayout (New gridlayout (1, 1, 0, 0 ));
Pane. Add (News );
Setcontentpane (PANE );
Setvisible (true );
}

Public static void main (string [] arguments)
{
Scrollframe = new scrollframe ();
}
}

Class scrollpane extends jpanel implements runnable
{

/**
* Control the animation effect by referencing the ordinate coordinates
*/
Int y;

Public scrollpane ()
{
New thread (this). Start ();
}

/*
* In the run of the thread, it changes y every time and then calls the repaint () method. This method calls the paint method and then draws it again.
* When I draw another image, the Y coordinate in the image changes every time, which forms an animation effect.
*/
Public void run ()
{
While (true)
{
Y-= 1;
If (Y <0)
{
Y = 201;
}
Try
{
Thread. Sleep (20 );
}
Catch (interruptedexception E)
{
}

Repaint ();
}
}

Public void paint (Graphics comp)
{
Graphics2d com2d = (graphics2d) comp;
Font type = new font ("monospaced", Font. Bold, 14 );
Com2d. setfont (type );
Com2d. setcolor (getbackground ());
Com2d. fillrect (0, 0, getsize (). Width, getsize (). Height );
Com2d. setcolor (color. Black );
For (INT I = 0; I <scrollframe. textcontent. length; I ++)
{
Com2d. drawstring (scrollframe. textcontent [I], 5, Y + (20 * I ));
}
}
}

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.