Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 03-02-2008, 11:17 PM
Member
 
Join Date: Feb 2008
Posts: 10
anotsu is on a distinguished road
assignement change the java screensaver
I would like to change this screensaver that draw multiple lines in different and color in different positions, to a screensaver that put a picture (let's call it pict01) in the screensaver and change its position.
but i am new in java, can somebody help me

file number 1----->saver1.java

import javax.swing.JFrame;

public class Saver1
{
public static void main( String args[] )
{
// create frame for Saver1JPanel
JFrame frame = new JFrame( "Saver1" );
frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );

Saver1JPanel saver1JPanel = new Saver1JPanel();
frame.add( saver1JPanel ); // add saver1JPanel to frame
frame.setSize( 300, 300 ); // set frame size
frame.setVisible( true ); // display frame
} // end main
}



file number 2-------->Saver1JPanel

import java.awt.Color;
import java.awt.Graphics;
import javax.swing.JPanel;

public class Saver1JPanel extends JPanel
{
private final int DELAY = 9999999;

// draw lines
public void paintComponent( Graphics g )
{
super.paintComponent( g ); // call superclass's paintComponent

int x, y, x1, y1;

// draw 100 random lines
for ( int i = 0; i < 100; i++ )
{
x = ( int ) ( Math.random() * 300 );
y = ( int ) ( Math.random() * 300 );
x1 = ( int ) ( Math.random() * 300 );
y1 = ( int ) ( Math.random() * 300 );

g.setColor( new Color( ( float ) Math.random(),
( float ) Math.random(), ( float ) Math.random() ) );
g.drawLine( x, y, x1, y1 );

// slow the drawing down. the body of the for loop is empty
for ( int q = 1; q < DELAY; q++ ) ;
} // end outer for

repaint(); // repaint component
} // end method paintComponent
}


thank you
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 03-06-2008, 10:31 PM
Senior Member
 
Join Date: Jul 2007
Posts: 1,146
hardwired is on a distinguished road
Code:
import java.awt.*; import java.awt.image.BufferedImage; import java.io.*; import java.util.Random; import javax.imageio.ImageIO; import javax.swing.*; public class SaverRx extends JPanel implements Runnable { BufferedImage image; Random seed = new Random(); Point loc = new Point(); Thread thread; boolean running = false; private final int DELAY = 1000; public SaverRx(BufferedImage image) { this.image = image; start(); } protected void paintComponent( Graphics g ) { super.paintComponent( g ); g.drawImage(image, loc.x, loc.y, this); } private void start() { while(!isVisible()) { try { Thread.sleep(25); } catch(InterruptedException e) { System.exit(1); } } running = true; thread = new Thread(this); thread.setPriority(Thread.NORM_PRIORITY); thread.start(); } public void run() { while(running) { try { Thread.sleep(DELAY); } catch(InterruptedException e) { System.out.println("interrupted"); running = false; } int w = getWidth() - image.getWidth(); int h = getHeight() - image.getHeight(); loc.x = seed.nextInt(w); loc.y = seed.nextInt(h); repaint(); } } public static void main( String[] args ) throws IOException { String path = "images/hawk.jpg"; BufferedImage image = ImageIO.read(new File(path)); SaverRx test = new SaverRx(image); JFrame frame = new JFrame( "Saver1" ); frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE ); frame.add( test ); frame.setSize( 500, 500 ); frame.setVisible( true ); } }
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 03-07-2008, 01:28 AM
Member
 
Join Date: Feb 2008
Posts: 10
anotsu is on a distinguished road
thank you very much
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
I have c++ code for LUDO Game, Can anyone change it to Java file - Please help me Bhanu Sagar AWT / Swing 0 03-12-2008 07:39 PM
change the square to triangle java anotsu New To Java 2 02-06-2008 08:21 PM
How to change the default Java integrator New To Java 4 02-01-2008 04:19 PM
How to change JDK? mew Eclipse 2 12-01-2007 10:43 PM
Cast Error Caught (change) Class is really: java.lang.String barney Advanced Java 1 08-02-2007 05:07 PM


All times are GMT +3. The time now is 06:33 PM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org