java on valentines

love letter using java programming

  • (2 Pages)
  • +
  • 1
  • 2

21 Replies - 11649 Views - Last Post: 21 January 2009 - 10:54 PM Rate Topic: -----

#1 jencalma  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 89
  • Joined: 13-July 07

java on valentines

Posted 20 January 2009 - 03:04 AM

because valentines is near i would like to give my very special friend a love letter using the java programming,, and i don't know what will be the content of it,, and i would like to know your suggestion,,
Is This A Good Question/Topic? 0
  • +

Replies To: java on valentines

#2 Gloin  Icon User is offline

  • Expert Schmexpert...
  • member icon

Reputation: 235
  • View blog
  • Posts: 4,489
  • Joined: 04-August 08

Re: java on valentines

Posted 20 January 2009 - 04:40 AM

A love letter you say.. I hope you don't mean the infamous virus..

If you're talking about a normal love letter then I guess you know best yourself what should be the content since it should reflect upon what you feel, right?
If however, you just don't know how to present it, just tell us how you want it and we'll try to help you out with the practical part.
Was This Post Helpful? 0
  • +
  • -

#3 jencalma  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 89
  • Joined: 13-July 07

Re: java on valentines

Posted 20 January 2009 - 05:01 AM

hehe it's not the infamous virus,, haha it's just a normal love letter,, what i want is that how will i display a message using the thread sleep without a loop,, when they run the code the message will just appear, but one line after the another..
Was This Post Helpful? 0
  • +
  • -

#4 Gloin  Icon User is offline

  • Expert Schmexpert...
  • member icon

Reputation: 235
  • View blog
  • Posts: 4,489
  • Joined: 04-August 08

Re: java on valentines

Posted 20 January 2009 - 07:47 AM

You can use the sleep method like follows.

Thread thread = null; //Declare a variable of class Thread, assign it null.
try { // Must be within a try/catch block
  thread.sleep(2000); //Pauses for 2000ms = 2s.
} catch (InterruptedException e) {
  e.printStackTrace(); //Prints an error message if something goes wrong. This is optional.
}



Were you looking for something more specific?
Was This Post Helpful? 0
  • +
  • -

#5 nick2price  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 562
  • View blog
  • Posts: 2,826
  • Joined: 23-November 07

Re: java on valentines

Posted 20 January 2009 - 07:57 AM

How romantic, and i was going to give my girlfriend a hoover (She will so kill me if she saw this! lol). If they are going to run the program themselves, you could just staright away do System.out.println to the screen,
System.out.println("Roses are red");
System.out.println("Violets are blue");
System.out.println("I have a gift");
System.out.println("made only for you");


Or you could use the thread suggested to make each line appear after a time gap. Or you could make each line appear on an event (1 prints the first line, 2 prints second line etc). There are many things you can do.
Was This Post Helpful? 0
  • +
  • -

#6 ayman_mastermind  Icon User is offline

  • human.setType("geek");
  • member icon

Reputation: 126
  • View blog
  • Posts: 1,860
  • Joined: 12-December 08

Re: java on valentines

Posted 20 January 2009 - 08:03 AM

how about adding some ascii graphics since you will be using CLI? for example add this heart in your program:

		  .-"""-.	.-"""-.
		 /	   `..'		 \
		|					  |
		|					  |
		 \					/
		  \				 /
		   `\			/'
			 `\	   /'
				 `\/'


hope this helps, good luck ;)
Was This Post Helpful? 0
  • +
  • -

#7 TriggaMike  Icon User is offline

  • Using up all your 1's and 0's
  • member icon

Reputation: 85
  • View blog
  • Posts: 1,103
  • Joined: 26-September 08

Re: java on valentines

Posted 20 January 2009 - 12:02 PM

or you could technically use a Scanner object and use the .nextLine() method without feeding it into a variable to pause a thread until the user hits enter.

like this

Scanner keyIn = new Scanner(System.in);
System.out.print(/*type stuff here*/);
keyIn.nextLine();


This post has been edited by TriggaMike: 20 January 2009 - 12:09 PM

Was This Post Helpful? 0
  • +
  • -

#8 Locke  Icon User is offline

  • Sarcasm Extraordinaire!
  • member icon

Reputation: 521
  • View blog
  • Posts: 5,596
  • Joined: 20-March 08

Re: java on valentines

Posted 20 January 2009 - 12:09 PM

If you wanted to be really cool...you could write a GUI. In my opinion, that would show much more effort and planning than println() statements.

But that's just me.

I've actually had this same idea before, as I'm sure many other people have. My only suggestion...just don't go overboard. ;)

It's fairly easy to write a GUI, or you could just use JOptionPane or something. It's your choice. You can do whatever you think will work.

:)
Was This Post Helpful? 0
  • +
  • -

#9 TriggaMike  Icon User is offline

  • Using up all your 1's and 0's
  • member icon

Reputation: 85
  • View blog
  • Posts: 1,103
  • Joined: 26-September 08

Re: java on valentines

Posted 20 January 2009 - 12:14 PM

I agree with Locke, I think the easiest way would probably be JOptionPane and you could probably use the .showMessageDialog() method to output your message easily.
Was This Post Helpful? 0
  • +
  • -

#10 jencalma  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 89
  • Joined: 13-July 07

Re: java on valentines

Posted 21 January 2009 - 04:40 AM

View Postayman_mastermind, on 20 Jan, 2009 - 07:03 AM, said:

how about adding some ascii graphics since you will be using CLI? for example add this heart in your program:

		  .-"""-.	.-"""-.
		 /	   `..'		 \
		|					  |
		|					  |
		 \					/
		  \				 /
		   `\			/'
			 `\	   /'
				 `\/'


hope this helps, good luck ;)



oohh i like the heart idea,, nice one,, but how's that?? ehehe


View PostTriggaMike, on 20 Jan, 2009 - 11:02 AM, said:

or you could technically use a Scanner object and use the .nextLine() method without feeding it into a variable to pause a thread until the user hits enter.

like this

Scanner keyIn = new Scanner(System.in);
System.out.print(/*type stuff here*/);
keyIn.nextLine();




how can i show a lots of system.out,print with a gap pers 2 seconds?? i just copy the scanner keyin every sentences?
Was This Post Helpful? 0
  • +
  • -

#11 jencalma  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 89
  • Joined: 13-July 07

Re: java on valentines

Posted 21 January 2009 - 05:54 AM

here's the code that i already done,, and i use thread.sleep() to show a message one after the another..
public class love
{
	public static void main(String[] args)
	{
		System.out.println("you are on step to the right ");
			try
			{
				Thread.sleep(1000);
			}
			catch(InterruptedException ie)
			{
				System.out.println(ie.getMessage());
			}
		System.out.println("you are on step to the up");
			try
			{
				Thread.sleep(1000);
			}
			catch(InterruptedException ie)
			{
				System.out.println(ie.getMessage());
			}
		System.out.println("you are on step to the left ");
			try
			{
				Thread.sleep(1000);
			}
			catch(InterruptedException ie)
			{
				System.out.println(ie.getMessage());
			}
	}
}



how can i use the thread.sleep() without repeating the thread sleep command,, and this is all i know on how to delay time,, :D tnx
Was This Post Helpful? 0
  • +
  • -

#12 Gloin  Icon User is offline

  • Expert Schmexpert...
  • member icon

Reputation: 235
  • View blog
  • Posts: 4,489
  • Joined: 04-August 08

Re: java on valentines

Posted 21 January 2009 - 07:16 AM

What's the problem with using the thread.sleep() method repeatedly?
Was This Post Helpful? 0
  • +
  • -

#13 Gloin  Icon User is offline

  • Expert Schmexpert...
  • member icon

Reputation: 235
  • View blog
  • Posts: 4,489
  • Joined: 04-August 08

Re: java on valentines

Posted 21 January 2009 - 07:22 AM

If you wanna make the code shorter, you can create a static method instead.

public static void delay(int ms, boolean printerror) {
try
  {
  Thread.sleep(1000);
  }
  catch(InterruptedException ie)
  {
  if(printerror)  
	System.out.println(ie.getMessage());
  }
}



Invoke the method by putting delay(1000, false); in your code where you want a pause. The reason for the boolean parameter is that maybe if you make a loveletter and something goes wrong, you don't want an error message to appear, that wouldn't be very romantic, would it?
Was This Post Helpful? 0
  • +
  • -

#14 Locke  Icon User is offline

  • Sarcasm Extraordinaire!
  • member icon

Reputation: 521
  • View blog
  • Posts: 5,596
  • Joined: 20-March 08

Re: java on valentines

Posted 21 January 2009 - 09:04 AM

View PostGloin, on 21 Jan, 2009 - 06:22 AM, said:

The reason for the boolean parameter is that maybe if you make a loveletter and something goes wrong, you don't want an error message to appear, that wouldn't be very romantic, would it?


What if she enjoys exceptions so she can decompile the code and figure out where they went wrong? ;) :lol:

Yeah, Gloin's method is a good one. I suggest using it.

This post has been edited by Locke37: 21 January 2009 - 09:05 AM

Was This Post Helpful? 0
  • +
  • -

#15 Gloin  Icon User is offline

  • Expert Schmexpert...
  • member icon

Reputation: 235
  • View blog
  • Posts: 4,489
  • Joined: 04-August 08

Re: java on valentines

Posted 21 January 2009 - 09:43 AM

View PostLocke37, on 21 Jan, 2009 - 04:04 PM, said:

View PostGloin, on 21 Jan, 2009 - 06:22 AM, said:

The reason for the boolean parameter is that maybe if you make a loveletter and something goes wrong, you don't want an error message to appear, that wouldn't be very romantic, would it?


What if she enjoys exceptions so she can decompile the code and figure out where they went wrong? ;) :lol:

Yeah, Gloin's method is a good one. I suggest using it.


The boolean parameter provides that option, I really thought this through, didn't I?! :)
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2