diff options
author | toma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2009-11-25 17:56:58 +0000 |
---|---|---|
committer | toma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2009-11-25 17:56:58 +0000 |
commit | 90825e2392b2d70e43c7a25b8a3752299a933894 (patch) | |
tree | e33aa27f02b74604afbfd0ea4f1cfca8833d882a /qtjava/javalib/examples/forever | |
download | tdebindings-90825e2392b2d70e43c7a25b8a3752299a933894.tar.gz tdebindings-90825e2392b2d70e43c7a25b8a3752299a933894.zip |
Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features.
BUG:215923
git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdebindings@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'qtjava/javalib/examples/forever')
-rw-r--r-- | qtjava/javalib/examples/forever/Forever.java | 120 | ||||
-rw-r--r-- | qtjava/javalib/examples/forever/README | 3 |
2 files changed, 123 insertions, 0 deletions
diff --git a/qtjava/javalib/examples/forever/Forever.java b/qtjava/javalib/examples/forever/Forever.java new file mode 100644 index 00000000..24cebcd3 --- /dev/null +++ b/qtjava/javalib/examples/forever/Forever.java @@ -0,0 +1,120 @@ +/*************************************************************************** +* $Id$ +** +* Definition of something or other +** +* Created : 979899 +** +* Copyright (C) 1997 by Trolltech AS. All rights reserved. +** +* This file is part of an example program for Qt. This example +* program may be used, distributed and modified without limitation. +** +****************************************************************************/ +import org.kde.qt.*; +import java.util.Random; + + + +class Forever extends QWidget +{ +static final int numColors = 120; + +private int rectangles; +private QColor[] colors = new QColor[numColors]; +private Random generator = new Random(System.currentTimeMillis()); + + + +// +// Forever - a widget that draws rectangles forever. +// + +// +// Constructs a Forever widget. +// +Forever( ) +{ + this(null, null); +} + +Forever( QWidget parent, String name ) +{ + super( parent, name ); + for (int a=0; a<numColors; a++) { + colors[a] = new QColor( generator.nextInt(255), + generator.nextInt(255), + generator.nextInt(255) ); + } + rectangles = 0; + startTimer( 0 ); // run continuous timer + QTimer counter = new QTimer( this ); + connect( counter, SIGNAL("timeout()"), + this, SLOT("updateCaption()") ); + counter.start( 1000 ); +} + + +void updateCaption() +{ + String s = "Qt Example - Forever - " + rectangles + " rectangles/second"; + rectangles = 0; + setCaption( s ); +} + + +// +// Handles paint events for the Forever widget. +// + +protected void paintEvent( QPaintEvent e ) +{ + QPainter paint = new QPainter( this ); // painter object + int w = width(); + int h = height(); + if(w <= 0 || h <= 0) + return; + paint.setPen( NoPen ); // do not draw outline + paint.setBrush( colors[generator.nextInt(numColors)]);// set random brush color + +// QPoint p1 = new QPoint( generator.nextInt(w), generator.nextInt(h)); // p1 = top left +// QPoint p2 = new QPoint( generator.nextInt(w), generator.nextInt(h)); // p2 = bottom right + +// QRect r = new QRect( p1, p2 ); +// paint.drawRect( r ); // draw filled rectangle + paint.drawRect( generator.nextInt(w), generator.nextInt(h), + generator.nextInt(w), generator.nextInt(h) ); // draw filled rectangle +} + +// +// Handles timer events for the Forever widget. +// + +protected void timerEvent( QTimerEvent e ) +{ + for ( int i=0; i<100; i++ ) { + repaint( false ); // repaint, don't erase + rectangles++; + } +} + + +// +// Create and display Forever widget. +// + +public static void main( String[] args ) +{ + QApplication a = new QApplication( args ); // create application object + Forever always = new Forever(); // create widget + a.setMainWidget( always ); // set as main widget + always.setCaption("Qt Example - Forever"); + always.show(); // show widget + a.exec(); // run event loop + return; +} + +static { + qtjava.initialize(); +} +} diff --git a/qtjava/javalib/examples/forever/README b/qtjava/javalib/examples/forever/README new file mode 100644 index 00000000..00aeedc5 --- /dev/null +++ b/qtjava/javalib/examples/forever/README @@ -0,0 +1,3 @@ +The forever program draws filled rectangles with random color and random +position and size. + |