Non-GUI events in Java
I was wondering how I would have to go about writing an event handling mechanism on something that is not GUI-based (non-AWT/SWING)!
Supposing one wanted to write an event listener that would tell them when a data structure is updated - e.g: in a typical producer-consumer model, where the consumer is to be notified of fresh entries whenever a producer writes integers to some data structure...
Does Java have classes/methods to handle such non-GUI-based 'events'? Is this a commonly found scenario in Java programming?
Thank you!
What you're looking for is the Observer-interface. Check out http://java.sun.com/j2se/1.4/docs/api/java/util/Observer.html
and
http://java.sun.com/j2se/1.4/docs/api/java/util/Observable.html
Similar Messages
-
Hi there.I'm looking for a good tutorial regarding how an object can 'throw' an event to be caught by another object which listens on the source object. If anyone knows where I can find one or how it's done, I'll thank him foe sharing the info.
You can take a look at how it is done for Beans. There is a utility class in the API called PropertyChangeSupport that you may be able to use directly in your classes:
http://java.sun.com/j2se/1.4.1/docs/api/java/beans/PropertyChangeSupport.html
You should also try searching for "oberver observable pattern" on Google. -
Non-gui/swing event in java possible ?
Dear Members :
Is it possible in java to raise and catch business events, as is possible in other languages, I know.
For instance - when I create a vehicle instance, that will trigger an event which will add that vehicle to vehicle_list(List) - something like that ? I am aware of Observer/Observable, but that is only if the source changes.
Could someone please explain with syntax if that's possible, I mean, tackling any kind of business events in java ?
Thanks in advance
AtanuThere is no out of the box event model... and be careful how you phrase these things... and in you are pedantic enough the pattern reveals itself.
What notifies the sales people that a new car is ready? It's not the Car itself is it? How about the factory? You're getting warmer... Who else does the factory tell? Maybe the tax man?
Yeah... Observe/r/able was a good first thought.
And... You might want to look into the Spring framework... I think you're groping for AOP.
Cheers. Keith. -
Event handling in custom Non-GUI components
I have a class which needs to fire events to outside. These events maybe captured by several objects in outside world. How can I achieve this? In so many places I read, they always refer to AWT and Swing whereas my objects don't have any dependency to GUI.
I simply need to fire an event from an object, and capture that event from other objects by registering event handlers.
I have experience in .Net programming with Events and Delegates (function pointers), but cannot find something like that in Java. All it offers is various kinds of GUI related Listeners where I can't find a proper help resource using them in Non-GUI components.ravinsp wrote:
I have a class which needs to fire events to outside. These events maybe captured by several objects in outside world. How can I achieve this? In so many places I read, they always refer to AWT and Swing whereas my objects don't have any dependency to GUI.
I simply need to fire an event from an object, and capture that event from other objects by registering event handlers.
I have experience in .Net programming with Events and Delegates (function pointers), but cannot find something like that in Java. All it offers is various kinds of GUI related Listeners where I can't find a proper help resource using them in Non-GUI components.If you want to make your own Listener make your Listener. Create an event class that encapsulates the event as you want, create a listener interface that has a method like handleMyEvent(MyEvent me) and then add addMyEventListener, removeMyEventListener methods to your original class. Add a List<MyEvent> to your original class and add the listeners to it and then when events happen
MyEvent someEvent = new MyEvent();
for(MyEventListener mel : eventlisteners)
mel.handleMyEvent(someEvent); -
Issue: non-root access to Java Desktop System
Hello,
Rookie here. i have been using Solaris 10 with no problem and accessing the GUI thru the Java Desktop system with no problem. i created a new non-root user 'user1' on the system with all default parameters assigned to the user when doing 'useradd user1'. these default parameters assume a default home directory is assigned to the user, correct? i am able to access the system with 'user1' via console and remote, but i cannot access the GUI thru the Java Desktop system with this user. It accepts my credentials then it flashes a couple of times and sends me back to the welcome log-in screen.
Are there additional permission that i need to grant this user to access GUI via JDS? i'm able to do everything else as normal. Any help is appreciated.doing 'useradd user1'. these default parameters assume a default home directory is assigned to the user, correct? i am Incorrect. man useradd paying attention to -d and -m. Solaris defaults to /export/home and will usually throw an error if you try to use /home as it's controlled by the automounter.
If it's just a test user account then userdel followed by useradd again.
alan -
Hi
I want to make an Object listen to an Event created by another Object, I mean :
Object1 --- Event ---> Object2 ---method---> Finish
so that Object1 is an instance of a class A, Object2 an instance of a class B, and when A creates an Event "CalculDone", B receives it and starts the AfterCalculIsDone method. Unfortunately I don't know how I can handle events that are not created by components but that are created by not-in-a-GUI running code. Could you help me ?Ok, the thing is, when you say "event" in java, we're specifically referring to GUI stuff. like without events, how would we find out when a button was pressed, etc. it doesn't make sense in java to talk about events outside of that area, as far as I know.
what im thinking is, you need an algorithm that needs to call certain methods upon certain things happening. honeslty, maybe i'm being dense but I still can't understand why you can't say this:
if(test_your_constraint)
call_all_the_other_methods_that_should_know_about_this_to_update_their_class_info
but I'm thinking that if that's not what you're talking about maybe you're talking about a branching algorithm or a backtracking algorithm. ie. when you find out certain constraints, you're equations need to take a different direction or when you find out they're going in the wrong direction, backtrack to start a new way.
btw, what's your programming background, maybe that'll help me figure out what you need. -
How to run an iPhone non-GUI application in background
Hi All,
While looking into the web fouond that only one application can be run at a time in iPhone. So is there any way or work around to run a non-GUI app in iPhone in Background.
This app will continuously query certain requests to iPhone regardign some internal iPhone events.
Thanks in advance.
Regards.
AmitNo.
-
Need help writing non-gui JMF program
I need to write a program that will convert a WAV file from a ULAW format to a GSM WAV file format. I first tried this with the Java Sound API and the WAV file format of GSM was not supported so I stumbled across JMF.
I can use the JMStudio and Export GUI programs that come with JMF to convert the wav file as needed. But now I'm trying to write a batch program (non-gui) to convert the file on the fly.
First, is this possible. Second, does anyone have any code samples of a batch java program using JMF in batch.
Thanks,
ScottNot exactly what I was looking for. After 2 days of beating my head against the wall this is what I got to work. Include the jmf.jar in my project. Here is my code.
import java.io.IOException;
import javax.media.DataSink;
import javax.media.Manager;
import javax.media.MediaLocator;
import javax.media.NoDataSourceException;
import javax.media.Processor;
import javax.media.control.TrackControl;
import javax.media.format.AudioFormat;
import javax.media.protocol.DataSource;
import javax.media.protocol.FileTypeDescriptor;
import jmapps.util.StateHelper;
public class TestAudio5 {
public static void main(String[] args) {
try {
Processor p = null;
StateHelper sh = null;
DataSource inSource = Manager.createDataSource(
new MediaLocator("file:c:\\ASSURANCE_THREE_MINUTE.wav"));
p = Manager.createProcessor(inSource);
sh = new StateHelper(p);
// Configure the processor
if (!sh.configure(10000)) {
System.out.println("can't configure");
System.exit(-1);
p.setContentDescriptor(new
FileTypeDescriptor(FileTypeDescriptor.WAVE));
//AudioFormat(java.lang.String encoding, double sampleRate, int sampleSizeInBits, int channels)
//AudioFormat(
// java.lang.String encoding,
// double sampleRate,
// int sampleSizeInBits,
// int channels,
// int endian,
// int signed,
// int frameSizeInBits,
// double frameRate,
// java.lang.Class dataType)
AudioFormat outputFormat = new javax.media.format.AudioFormat(
AudioFormat.GSM_MS,
8000.0,
0,
1,
0,
1,
520,
1625.0,
null);
System.out.println("outputFormat: " + outputFormat.toString());
TrackControl tc[] = p.getTrackControls();
for ( int i = 0; i < tc.length; i++ ) {
tc.setEnabled(true);
System.out.println("before format: " + tc[i].getFormat().toString());
tc[i].setFormat(outputFormat);
System.out.println("after format: " + tc[i].getFormat().toString());
if (!sh.realize(10000)) {
System.out.println("can't realize");
System.exit(-1);
// get the output of the processor
DataSource source = p.getDataOutput();
// create a File protocol MediaLocator with the location
// of the file to which bits are to be written
MediaLocator dest = new MediaLocator("file://c:\\test.wav");
// create a datasink to do the file writing & open the
// sink to make sure we can write to it.
DataSink filewriter = null;
filewriter = Manager.createDataSink(source, dest);
filewriter.open();
// now start the filewriter and processor
filewriter.start();
sh.playToEndOfMedia(5000);
sh.close();
filewriter.close();
} catch (NoDataSourceException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
System.out.println("done!");
System.exit(-1); -
Non GUI alternative to PB10 Transaction (infpotypes 22 and 24)
Hi guys,
This is a java foreigner in the ABAP land.
I hope I am asking the correct question.
This is the situation:
In order to send a "candidates resume" (curriculum) in to SAP, the ABAP developers made for me a RFC which uses the transaction PB10 (applicant master data).
The RFC when tested in the SAP GUI works fine.
I wrote a java client which calls the RFC, send the parameters and expect the results. This client uses JCO to access SAP.
But, from the java client the RFC works PARTIALLY,
it doesnt fill the education a qualifications (infotypes 22 and 24), and throws error message:
"Exception condition "CNTL_ERROR" raised"
It seem there is an GUI missed, but from JCO I cannot use GUI.
So, I need a non-GUI alternative transaction to the PB10, which writes the data in the infotype 22 and 24.
So, the question here is:
Does somebody knows a non-GUI alternative to the PB10 in order to write the infotypes 22 and 24??
Thanks in advance,
Luisi do have a similar requirement ... from non sap system i am suppose to pass data which saves in table connected to pb10..can you send the RFC developed for your requirement.. it would be helpful for me..
thank you -
Hello again world.
I see that to produce output in a non-GUI environment, one uses
System.out.println(output)
I can't seem to get the other side of the coin for input.
As usual, thanx in advance.If you upgrade to 1.5 it's a little easier, for instance reading a word and then an integer is this simple: Scanner s=Scanner.create(System.in);
String param= s.next();
int value=s.nextInt();For further information see
http://java.sun.com/j2se/1.5.0/docs/api/java/util/Scanner.html
http://java.sun.com/developer/technicalArticles/releases/j2se15/ -
"Keith Patterson" <[email protected]> wrote:
<snip!>
... I would like to create several 'batch' Forte programs that perform
a select all from our tables at random intervals during our testing.
Has anyone done this sort of thing?? I'm not even sure how to start
building an app that I don't want any output from and any assistance
would be sincerely appreciated. You're going to be embarassed at how easy it is. At least, I was! ;-)
Assuming that you want is to kick a couple batch, detached, daemon, or
whatever processes to bang on your database, what you need to do is:
* Create a new project. Give this project, as contributors, all the
projects needed to get the functionality you want to test.
* In this new project, create a NON-GUI object with a method that
actually performs the test you want. Make this the initial
object/method for the project.
* Make distribution on this project.
* Run your project, applying the -fcons, -fnw, and/or -fterm qualifiers
as necessary.
If you want to force the action through the same Forte service objects
(rather than just copies of them), the above WILL NOT do what you want.
In theory you can get that with the above setup by putting the SOs in a
"reference partition" (I believe that's the term), but I have no actual
experience at that.
Alternatively, you could simply put a "test" button somewhere in your
app, that creates a new instance of the test object, and does a "start
task" on the relevant method. This is not, strictly speaking, a "batch"
run, but you also don't have to make distribution to do it.
Tom Wyant
E. I. DuPont de Nemours
Richmond, VA USAIf you upgrade to 1.5 it's a little easier, for instance reading a word and then an integer is this simple: Scanner s=Scanner.create(System.in);
String param= s.next();
int value=s.nextInt();For further information see
http://java.sun.com/j2se/1.5.0/docs/api/java/util/Scanner.html
http://java.sun.com/developer/technicalArticles/releases/j2se15/ -
Javafx for console (non-gui) applications?
Hi,
I am interested in using the JavaFX scripting language as a general purpose language to create console (non-gui) applications. But even running the following simple program seems to initiate some sort of GUI that quickly appears and disappears. Is there anyway to run a JavaFX script in "console-only" mode?
function run(args : String[]) {
println("hello")
}Thanks.Hi,
Yeah, that is pretty much exactly what I did.
I am running on Mac OS X 10.5.6, with Java 1.6.0_07 and JavaFX 1.1.0.
When I execute the program from Terminal, everything works, however a new application appears in the menu bar while the program is executing in the console. For example, if I add a java.lang.Thread.sleep(5000) invocation to the program mentioned earlier, you will see the application in the menu bar for 5 seconds. This is not the way a normal console-based java application typically works... there should be no application in the menu bar.
Thanks. -
How to tackle the dataflow problem when Value Change event always triggers after another GUI event
We know that Value change event always triggers after another GUI event. Eg, the user modifies string control, the user clicks on a boolean control. Then event boolean clicked is triggered before event string control value change.
Now suppose somehow the GUI event that must happen to subsequently trigger the Value change event can potentially affect the data that Value change event is supposed to work on. How can we tackle this problem ?
For example, in a mockup application that the grand purpose is to have user entered values in a textbox logged to a file (no missing information is accepted, and there is a boolean to determine how the information is logged).
There are 2 controls, boolean A when clicked (mouse down) will load random number in text box B. Text box B is designed with event structure VALUE change which saves whatever values user enters into text box B to a log file.
There are 3 problems when instead of clicking anywhere on the front panel after modifying text box B, the user ends up clicking on boolean control A.
1. Event mouse down on Boolean control A will execute first, modifying text box B content before the user entered values in B get saved.
2. The value of boolean A can potentially affect how textbox B is loggged.
3. The value of boolean A affects how the file is logged and this is indeterminate. Somehow when running this VI with no Highlighting, the textbox B Value change event executes -before- boolean A value is updated (F to T). When running this VI with Highlighting, the boolean A value is updated (F to T) (because we click on it) -before- textbox B value change event occurs. Why is it like this ?
Now the situation I made up seems non-sense, but I believe it resembles one way or another a problem that you might run into. How would you solve this problem elegantly ?
You can set the string control to "update while typing".
Are you sure appending the log to itself is reasonable? Wouldn't it grow without bounds if the users keeps entering strings or pressing the ingore button?
Why isn't the "constant" a diagram constant instead of a control. Is the user allowed to change it?
To reset just write empty strings or a false to local variables of the controls (renit to defaults" seems a bit heavy handed).
All you probably need is a single event case for "ignore:value change" and "String" value changed", no need for the local variable..
Also add a stop button and an event for it.
You don't need the timeout event.
-
"Error While Trying To Synchronise Audio And Midi"...non-tempo event found
"Error While Trying To Synchronise Audio And Midi"...non-tempo event found
now when I shutdown Logic And relaunch the Project, the notes hang and "WHAT THE FRIIGIN"
(this was a bug way back when Logic7 was first released)
this is bad!
SvKThanks Steven.
big help. In our session we keep getting this problem where the song counter stops, the music keeps playing and we get an error message saying:
Non Tempo-Event found in Sync Reference
We looked in the tempo list and somehow there was a tempo event of 0.00 tempo in there.
We deleted it, got the same error message, but the prob seems to be fixed.
Apple, please fix this!
Thanks
Felix -
Send an event from Java Web Service to BPEL
Hi,
I have a requirement where from an Async BPEL service I have to call a Java Web Service. After the completion of its task Java Web Service will fire an event that has to be consumed by the BPEL to initiate further process. Can anybody help me with how to send an event from Java Web Service and at the same time consume it in BPEL?
Thanks,
AnujSee the following posts for your answer
http://blogs.oracle.com/soabpm/entry/event_delivery_network_chapter
http://blogs.oracle.com/soabpm/entry/using_the_event_api_to_publish
http://guidoschmutz.wordpress.com/2010/01/12/using-the-event-api-to-publish-an-event-to-the-event-delivery-network-edn-the-spring-way/
Maybe you are looking for
-
System extension v.5 required ?
I updated my quicktime but when I try to use it it gives a pop up that says\I need a quicktime system extension version 5 or higher and gives me the www.apple.com/quicktime site to get it but can't figure out what I need or how to install it HELP
-
Links from applications in a new window
It use to be that when I clicked on a link in Mail, it would open in Safari within a new window right on top. Now it opens in a new window under the one that is already open. Is there anyway to fix this? I don't want to open something new in another
-
Last night, I ordered a Samsung Focus 2 4G for AT&T, and I got an email confirming the order, but when I check the order status on bestbuy.com, it says no orders found. However, when I call and check the order status, it says that it is being prepar
-
Rerunning installer after glibc2.1 patch fails
I followed the directions in ftp://ftp.oracle.com/pub/www/otn/linux/README to install the glibc2.1 patch for Oracle 8.05 on linux 6.2. Everything is great expect for step 4. It says to run the installer again and pick create/upgrade database objects.
-
just tryed to down load movie from Itunes, took 5-hrs, I was billed, however, the movie is not on my mac air