473,386 Members | 2,129 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Help with java listeners or something similiar

Hello everybody,

I understand the basics of Java, but not such features as are helpful in an applet namely Listeners.

I wanted to create a feature like this:

A program would be displayed in the regular old System.out.
It would be looping continuously doing something unimportant, say counting how many times it could count to a billion, until the user enters a command, and then it would simply delay what it was doing, display something unimportant ("hello") and then go back to what it was doing.

At current I only know how to make the program Stop and Wait for the user to enter something, and then do it again.

I know that a key listener or something similar is what I'm after, but I don't know how to use them or if I need one, because I only want input from System.in (which I would usually use a Scanner to get).

Could someone point me to a proper tutorial, or perhaps crack out an example for me?

All in all I'm looking for:

Something that will listen for the user to hit the Enter key, then read in whatever they typed before it in the command line, rather than some newly created and displayed text box.

Thanks everyone for your time.
Jul 11 '08 #1
5 1537
ajos
283 100+
Hold on. I didnt go beyond the first line, you really need to learn the language first before doing anything.

Start here Sun Tutorials

regards,

ajos
Jul 11 '08 #2
Thanks, I used the wrong wording.
I know Java well enough to create a text only spreadsheet application displayed in the cmd window. I know queues, stacks, binary search trees, how to create iterators and all that good stuff used for ordering and manipulating info. I just don't know app development or how to get input without halting everything.
Jul 11 '08 #3
Nepomuk
3,112 Expert 2GB
OK, I'd say you should use threads (one constantly counting to a billion and one waiting for user input). Search google to find loads of tutorials and examples for thread programming.

As far as I know (but there's still a lot to learn about Java, so I could be wrong), listeners as known by Java, are only for GUIs, not for the command line (and therefore System.in).

Greetings,
Nepomuk
Jul 11 '08 #4
Laharl
849 Expert 512MB
I believe you're correct about Listeners being GUI only. Threads are probably the way to go here...
Jul 11 '08 #5
JosAH
11,448 Expert 8TB
I believe you're correct about Listeners being GUI only. Threads are probably the way to go here...
Listeners are a general purpose solution; they're not GUI only. Have a look
at the PropertyChangeSupport class for example: any bound property
can use it. And should use it most of the time to decouple parts of groups of
classes from eachother.

kind regards,

Jos
Jul 11 '08 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: C. Schwerdtfeger | last post by:
Hi group. I'm trying to use DCOM with Java, but haven't found any help searching the list, all entries where about 2 years of age or older, so I'm posting ;) * I've read in a posting from '97...
0
by: gg | last post by:
I was playing with some free java code but I was miffed. In the current working directory, I have xyz.jar and a subdirectory coresrvlets. The classes of the package coreservlets are naturally...
0
by: news | last post by:
My question is for the software, IDE and programming in general. Is there an add-in or a program that is similiar to the search bar function in the Office Xp software where you type in any...
9
by: F. GEIGER | last post by:
I've dev'ed a Python prototype of an app, that besides the internals making it up has a gui. While test-driven dev'ing the app's internals in Python is fun as usual, dev'ing the GUI is not so...
8
by: Tim923 | last post by:
The code in C# looks very similiar to what I remember from Java, but we haven't done much manual coding yet. How similiar are they?
458
by: wellstone9912 | last post by:
Java programmers seem to always be whining about how confusing and overly complex C++ appears to them. I would like to introduce an explanation for this. Is it possible that Java programmers...
7
helpwithcode
by: helpwithcode | last post by:
Hi people, I am just learning java.I have been creating a project which involves JDBC Connectivity.I find that the statements, String string_dob=text_dob.getText(); //Converting string to...
4
by: slikrik98 | last post by:
Greetings, I have an application that subscribes to an intensive data feed, constantly receiving messages, and then routes those messages to various "listeners." My first attempt was to just...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.