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
Atanu

There 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.

Similar Messages

  • 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

  • Swing component fires an event to non-GUI code

    Hi all -- this is my first post in forums.sun.com.
    Question to get me started -
    I have a Swing component that fires an ActionEvent. I would like that ActionEvent to trigger code that does not run on the AWT Event Queue thread (some code that will take some time without impacting GUI rendering performance.)
    I know I could put that Event's action command into a synchronized Queue, and have a worker thread checking the queue and taking action when it finds a command there. Likewise, I could flag a volatile boolean as true, and have a worker thread check the flag and take action when true.
    Or (and I suspect this is best), I could create a new SwingWorker thread right in actionPerformed().
    Any opinions on what makes sense?

    pkwooster: Yep. That's what I meant.
    As for the design pattern, Observer was the pattern I was intending to use (and have already implemented). Would anyone argue that another method is more efficient or "correct"?
    My sample project is:
    Business Object -> Main Dialog -> Embedded Dialog
    The Main Dialog contains no business logic - just simple navigation events. The Embedded Dialog contains the real controls and reports any interaction using Swing events, which the Main Dialog picks up.
    I then set up the Observer pattern between the Main Dialog and the Business Object.

  • 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);

  • Swing event queue, modal dialogs, event threads, etc...

    Hey all,
    So I am playing around with the focus manager, swing event thread and event queue, etc. Learned quite a bit. I am also playing around with test automation of our UI, using jfcUnit. I have written a few simple apps to play aorund with record/playback, coding tests, etc. What this thread is about though, is figuring out how modal and non-modal dialogs "take over" the event thread/queue? The reason I ask is, if I put a simple test harness like tool embeded in my app as a separate pop-up modal dialog, and from within it there is a GUI that I can use to select a "Test" to run. Now, when I run this test, jfcUnit needs to run on the main window, not within my non-modal dialog. What I am not sure of, however, is that if by using a non-modal dialog all events will go to the main event thread? I mean, I know if I mouse over my second non-modal frame (spawned from the application frame), that events will trigger for that dialog. I remember reading somewhere that modal dialogs "block" the main event queue, all left over events are given to the newly added event queue (presumably by the modal dialog) and existing left-over events get moved to the event queue. If that is the case, I am curious why events for the "old" queue are moved to the new queue if they were orginally intended for the old queue? I would think a "flush" before adding a new queue would be more appropriate so that the old queue can process all of its intended events.
    Now, I am just about to try this, but I am hoping a non-modal pop-up will not interfere with the jfcUnit running the UI of the main window. I am guessing, however, that it might. How are non-modal dialogs handled in terms of events and the event queue? Is it the same as modal dialogs? Or is there no blockage of the mainwindow event queue? If there is no blockage, than any sort of automation based on relative positions to a window may occur on the non-modal dialog, in which case it's best to hide the non-modal dialog during running of these tests.
    What are your thoughts, or better yet, knowledge of this topic? A decent explanation from a developer standpoint and not from the API's which dont give some of the more detailed info I am seeking is what I am hoping to get out of this.
    Thanks.

    Check this out. First, AWTListener has a LOT of
    different types you can register it for. I ORd all
    them together and when I ran my app, it took almost 30
    minutes for it to show up because of the huge stream
    of events being spit out via System.out. ...Yes, that doesn't surprise me in the least. There's hundreds of events that are fired around, usually unbeknownst to the user for every little thing. Lots of component and container events, in particular.
    Just make sure you OR ( using | not || ) ALL the
    "mask" values you want to watch for. That may be why
    you aren't seeing anything. When I did all that, and
    opened a menu, a ton of events came out.Maybe, I'll try that again, but I did specifically add an ActionEvent mask to get action events, and that should be all I need to get action events on buttons or menu items, and it wasn't getting them for either. It was only getting events on buttons when I used SwingEventMonitor, but not menu items.
    So I don't quite understand enough of the underlying event handling. Although, I suspect it could have something to do with the fact that these are Swing components, not AWT components (which their native peers) and it's pretty clear from AbstractButton (or was it DefaultButtonModel) how ActionEvents are fired, and they don't seem to have any connection to the code that deals with AWTListeners.
    My problem is that I kinda need a way to catch events without having a listener attached directly. Normally, I would have a listener, but there's this situation whereby an action may be triggered before I can get hold of the component to attach my listener to it. Perhaps I can get mouse press/release and just deal with it that way.
    Let me know if you did that and still didn't see what
    you were looking for. After playing with this, I am
    guessing the main reason for AWTListener is to
    register a listener for a specific type of event,
    instead of listening to them all, hence avoiding lots
    of extra overhead. Then again, the main event
    dispatcher must do a decent amount of work to fire off
    events to listeners of specific awt event types.Yes, it's definitely that. There's no point in sending events if no one is listening for it, so it does save some time.
    You are right, popup menus I think are dialogs, I
    don't know for sure, but you can access them via the
    JMenu.getPopupMenu() and JMenu.isPopupShowin().
    However, I am still not getting my test stuff working
    quite right.
    Yes, for menu popups. For a JPopupMenu on a right-click on any component (tree or whatever), I had a need to know about that from any arbitrary application (it's this GU testing app I'm working on), and since the popup menu doesn't belong to any component before it's shown, I couldn't necessarily know about it til it was displayed. I managed to use a combination of HierarchyEvents (using an AWTEventListener) and "component added" ContainerEvents. Not a simple matter, but it seems to work well.

  • A doubt in SWING event handling

    Hi all,
    I'm a beginner in JAVA studying SWING. I learned that if we want to handle an event for a event source(say JButton) we should implement corresponding Event Listener(say ActionListener) .
    I also understood that we should register the Listener with that event source.
    With that knowledge I tried this program
    import javax.swing.*;
    import java.awt.event.*;
    public class SimpleGui2 implements MouseListener,ActionListener {
       SimpleGui2 insGui;
       JButton button= new JButton("Click me");
         public static void main(String[] args) {
              SimpleGui2 gui = new SimpleGui2();
              gui.start();
       public void start() {
            JFrame frame = new JFrame();
            //button.addMouseListener(this);   
            //button.addActionListener(this);
            button.addActionListener(insGui);
            frame.getContentPane().add(button);
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.setSize(300,300);
            frame.setVisible(true);
       public void actionPerformed(ActionEvent ae) {
            button.setText("Triggered");
       public void mouseClicked(MouseEvent me) {
          button.setText("I have been clicked");
       public void mouseEntered(MouseEvent me) { }
       public void mouseExited(MouseEvent me) { }
       public void mousePressed(MouseEvent me) { }
       public void mouseReleased(MouseEvent me) { }  
    }but It's is not working as I expected.
    or precisely why when we clicked the actionPerformed/mouseClicked method is not invoked ?
    if i change the same with argument "this" it's working .
    I guess "this" refers to current object (which is also of type SimpleGui2 which implemented ActionListener)
    Can any one please clarify me what happens behind the scenes ?
    Thanks in advance

    first of all, you never initialize insGui. YOu just declare it, and never use it.
    SimpleGui2 insGui;However, you dont need it anyways. As you suspected, using 'this' when you add your actionListener is what you need.
    button.addActionListener(insGui);
    Can any one please clarify me what happens behind the scenes ?Well my professor always said it was 'black magic'. All I know is that you click a button with an event listener, and an event is fired doing whatever you want it to do. For example, if I want my event to print "Hey" then when I click the button, "Hey" is printed. Simple enough eh? You will probably find a better answer using Google though. It's amazing.

  • 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,
    Scott

    Not 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);

  • Package javax.swing.event not found in import.

    I'm receiving the above error message when compiling a Java application which begins with the following import statements:
    * 1.1+Swing version.
    import javax.swing.*;
    import javax.swing.event.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.util.*;
    My Classpath System variables are as follows:
    C:\IBMCON~1\CICS\Classes\CTGCLI~1.JAR;.;C:\PROGRA~1\MQSeries\java\lib\COMIBM~2.JAR;C:\PROGRA~1\MQSeries\java\lib\COMIBM~1.JAR;C:\PROGRA~1\MQSeries\java\lib\COMIBM~3.JAR;C:\PROGRA~1\MQSeries\tools\javaclnt\samples\en_us;C:\Program Files\SQLLIB\java\db2java.zip;C:\Program Files\SQLLIB\java\runtime.zip;C:\Program Files\SQLLIB\bin;C:\Program Files\SQLLIB\java\SQLj.zip
    I have Java(TM) 2 SDK, Standard Edition, Version 1.4.0 installed and am running Windows 2000.
    I'd appreciate any ideas as to why this compiler error occurs. Thanks very much.

    What error message?
    As stated, looks like something's not where it's supposed to be.
    Here's the search order of your classpath:
    C:\IBMCON~1\CICS\Classes\CTGCLI~1.JAR
    C:\PROGRA~1\MQSeries\java\lib\COMIBM~2.JAR
    C:\PROGRA~1\MQSeries\java\lib\COMIBM~1.JAR
    C:\PROGRA~1\MQSeries\java\lib\COMIBM~3.JAR
    C:\PROGRA~1\MQSeries\tools\javaclnt\samples\en_us
    C:\Program Files\SQLLIB\java\db2java.zip
    C:\Program Files\SQLLIB\java\runtime.zip
    C:\Program Files\SQLLIB\bin
    C:\Program Files\SQLLIB\java\SQLj.zip

  • Calling SAP GUI Client from a Java Webdynpro app.

    Hello experts,
    We would like to call the SAP GUI client from a java WebDynpro application running without portal or ITS. Can it be done by having a web link, with mime registration in internet explorer to kick off the SAP GUI ? (similar behavior with a SAP favorite link saved on the desktop).
    many Thanks.

    Hi,
    Webdynpro possibilities:
    1. You can try to use LinkToUrl.
    with reference to file://<exefile> or your weblink with the mime type (possibly some java coding can be required; I can try to help).
    2. other option is to use IFrame and you can use either href to your exe or weblink
    Web Explorers:
    1. IE: It should work. if you point to exe file popup window will be displayed asking for action (run, save, cance).
    2. Firefox: the only way I know to make it work is to modify nsHelperAppDlg.js file (if you need Firefox I can tell you how to modify the file).
    Kind Regards, Jack

  • Exception occurred during event dispatching:java.security.AccessControlExce

    Hi,
    I' m getting an error while connecting to database ORACLE 9i.
    I'm using JDK 1.6.0
    Actually the code is about how an Japplet connects to database ORACLE 9i
    when i was connecting using normal program i had got the connection easily .
    When i used this JApplet ,i'm getting this error.
    CODE:
    import java.awt.*;
    import javax.swing.* ;
    import java.sql.*;
    import java.awt.event.*;
    import java.util.*;
    /*<applet code="jln" width=400 height=400></applet>*/
    public class jln extends JApplet
    public void init()
    JTabbedPane jtp=new JTabbedPane();
    jtp.addTab("View Marks",new VmPanel());
    getContentPane().add(jtp);
    try {
    Class.forName("oracle.jdbc.driver.OracleDriver");
    } catch (Exception e)
    {              e.printStackTrace();
    System.out.println("Failed to load driver.");
    class VmPanel extends JPanel implements ActionListener
    JButton b1,b2;
    TextArea ta1;
    JTextField jtf1;
    Connection con=null;
    public VmPanel()
    b1=new JButton("ok!");
    b2=new JButton("clear");
    ta1=new TextArea();
    jtf1=new JTextField(10);
    add(jtf1);
    add(b1);
    add(b2);
    add(ta1);
    b1.addActionListener(this);
    b2.addActionListener(this);
    public void actionPerformed(ActionEvent ae)
    String str1=ae.getActionCommand();
    if(str1=="ok!")
    try
    con = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:jlngbldb", "scott", "tiger");
    Statement stmt = con.createStatement ();
    String ht=jtf1.getText();
    System.out.println("\nHello\n");
    ResultSet rs = stmt.executeQuery("SELECT * FROM jln WHERE ht='"+ht+"'");
    while(rs.next())
    ta1.setText ("");
    ta1.setText("Name:"+rs.getObject("name")+"HallTicket:"+rs.getObject("ht")+"C.G:"+rs.getObject("cg")+"C.D:"+rs.getObject("cd")+"UNIX:"+rs.getObject("unix")+" S.T.M:"+rs.getObject("stm")+"N.N:"+rs.getObject("nn")+"I.S:"+rs.getObject("ins"));
    rs.close();
    stmt.close();
    con.close();
    catch(SQLException ex)
    System.err.println("SQLException: " + ex.getMessage());
    if(str1=="clear")
    ta1.setText("");
    jtf1.setText("");
    if(str1==null)
    ta1.setText ("");
    ta1.setText("Please enter Hall Ticket Number above....");
    }//action performed close
    }//panel closed
    AND THE ERROR IS:
    Exception occurred during event dispatching:
    java.security.AccessControlException: access denied (java.util.PropertyPermissio
    n oracle.jserver.version read)
    at java.security.AccessControlContext.checkPermission (AccessControlConte
    xt.java:321)
    at java.security.AccessController.checkPermission(AccessController.java:
    546)
    at java.lang.SecurityManager.checkPermission(SecurityManager.java:532)
    at java.lang.SecurityManager.checkPropertyAccess(SecurityManager.java:12
    85)
    at java.lang.System.getProperty(System.java:627)
    at oracle.jdbc.driver.OracleDriver.getConnectionInstance(OracleDriver.ja
    va:433)
    at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:314)
    at java.sql.DriverManager.getConnection(DriverManager.java:548)
    at java.sql.DriverManager.getConnection(DriverManager.java :180)
    at VmPanel.actionPerformed(jln.java:60)
    at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:18
    63)
    at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.jav
    a:2183)
    at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel
    .java:420)
    at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:258
    at javax.swing.plaf.basic.BasicButtonListener.mouseReleased (BasicButtonL
    istener.java:234)
    at java.awt.Component.processMouseEvent(Component.java:5921)
    at javax.swing.JComponent.processMouseEvent(JComponent.java:3316)
    at java.awt.Component.processEvent (Component.java:5686)
    at java.awt.Container.processEvent(Container.java:1960)
    at java.awt.Component.dispatchEventImpl(Component.java:4360)
    at java.awt.Container.dispatchEventImpl(Container.java :2018)
    at java.awt.Component.dispatchEvent(Component.java:4194)
    at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4222
    at java.awt.LightweightDispatcher.processMouseEvent (Container.java:3886)
    at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3816)
    at java.awt.Container.dispatchEventImpl(Container.java:2004)
    at java.awt.Component.dispatchEvent (Component.java:4194)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java:592)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThre
    ad.java:270)
    at java.awt.EventDispatchThread.pumpEventsForFilter (EventDispatchThread.
    java:198)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThre
    ad.java:171)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:166)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:158)
    at java.awt.EventDispatchThread.run(EventDispatchThread.java:119)
    I'm getting this error when i pressed the OK! JButton.
    PLEASE ! help me by correcting this error.
    Thank You.

    Presumably you are running this via a browser where the applet is served from the server.
    Applets can only connect back to the origination server and using the name that the origination server was accessed with.
    And that has nothing to do with JDBC, all connections work that way.
    Your driver uses a connection thus it will not work unless it attempts to connect to the server that originated the applet.
    Solutions
    1. Connect to the server
    2. Sign the applet
    3. Modify the policy file of each client that will run the applet. This is not a good idea in an unsecure network.
    Note as well that in an unsecure network is most often a bad policy to have an applet directly accessing a database regardless.

  • 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.
    Amit

    No.

  • GUI/swing application doesn't appear under W2K

    Hi, all,
    I wrote a Java GUI application with JDK1.4.1_01, when I run it on Win2K Professional (SP3) the
    GUI doesn't appear without any exception.
    But when I ran the same application under XP and Win98, the GUI application run ok and the GUI appears.
    What is the problem?
    regards,
    Adam

    First I thought you had several jre's installed and windows used the wrong one when you type java ...
    Now I think it has to be someting wrong in your code.
    Can you try someting that should work?
    Compile and run the following code:
    javac testPanel.java
    java testPanel
    import javax.swing.*;
    import java.awt.*;
    public class testPanel extends Thread{
         public static void main(String[] args) {
              try{
                   // get out of the static context
                   new testPanel().start();
                   new testPanel().start();
                   new testPanel().start();
              }catch(Exception e){
                   e.printStackTrace();
         public void run(){
              // Create a container with a flow layout, which arranges its children
              // horizontally
              Panel panel = new Panel();
              // A container can also be created with a specific layout
              panel = new Panel(new FlowLayout(FlowLayout.RIGHT));
              // Add several buttons to the container
              panel.add(new Button("A"));
              panel.add(new Button("B"));
              panel.add(new Button("C"));
              // Create frame with a text area in the center
              Frame frame = new Frame();
              Component comp = new TextArea();
              frame.add(comp, BorderLayout.CENTER);
              // Add the container to the bottom of the frame
              frame.add(panel, BorderLayout.SOUTH);
              // Show the frame
              int width = 300;
              int height = 300;
              frame.setSize(width, height);
              frame.setVisible(true);
    }

  • Translating Visual Basic Events into Java Events

    I'm in the process of porting a Visual Basic application to Java. Now, most of it is pretty straight forward, since good OO practice is evident in the original VB source. With a good dose of refactoring along the way the Java version is looking pretty good too.
    However, I'm having a problem with events. Here's a snuppet of one of a VB class that generates events and one that uses it:
    (Invoices.cls)
    -=-=-=-=-=-=-=-=-
    Event AddItem(ItemID as String)
    Event RemoveItem(ItemID as String)
    Private m_Items as Collection
    Public Sub Add(ItemID as String)
       m_Items.Add ItemID
       RaiseEvent AddItem(ItemID)
    End Sub
    Public Sub Remove(ItemID as String)
       m_Items.Remove ItemID
       RaiseEvent RemoveItem(ItemID)
    End Sub
    -=-=-=-=-=-=-=-=-and
    (OrderBook.cls)
    -=-=-=-=-=-=-=-=-
    Private WithEvents m_Invoices as Invoices
    Private Sub m_Invoices_AddItem(ItemID as String)
       CalculateTotals
    End Sub
    Private Sub m_Invoices_RemoveItem(ItemID as String)
       CalculateTotals
    End Sub
    -=-=-=-=-=-=-=-=-Can anyone give me a few pointers on what the Java equivalent to this VB code is?
    Thanks,
    Vince.

    Hi,
    There are few main things involved in a Java event delivery
    1. The event source
    2. The event listener
    3. The even data
    4. Registration
    5. The event delivery process
    I don't know the VB syntax, but any way it gives a good idea of what you wish to achieve.
    Here the Invoice class is basically the event source. And the OrderBook class is the event listener. To proceed further you will have to specify (define) the event listener first. Secondly you will have to create an event object which contains the data to be delvered via the event.
    1. Specifying the event listener interface
    public Interface ItemOperationListener
    public void itemAdded (ItemOperationEvent ioe);
    public void itemRemoved (ItemOperationEvent ioe);
    2. The event class
    public class ItemOperationEvent extends java.util.EventObject
    String item = null;
    public ItemOperationevent(Object source, String Item)
    super(source);
    this.item = item;
    public String getItem()
    return item;
    3. Creating and firing the event from the event source.
    public class Invoice
    private collection items; // any collection
    // to hold all the event listeners , this way u can define > 1
    // listeners
    javax.swing.event.EventListenerList listenerList = new javax.swing.event.EventListenerList();
    public void addItem(String item)
    items.add(item);
    // update the listeners
    fireItemAdded(item);
    public void removeItem(String item)
    items.add(item);
    // update the listeners
    fireItemRemoved(item);
    public void addItemOperationListener(itemOperationListener ioe)
    listenerList.add(ioe);
    public void removeItemOperationListener(itemOperationListener ioe)
    listenerList.remove(ioe);
    public void fireItemAdded(String item)
    ItemOperationEvent e = null;
    Object[] listeners = listenerList.getListenerList();
    // Process the listeners last to first, notifying
    // those that are interested in this event
    for (int i = listeners.length-2; i>=0; i-=2) {
    if (listeners== ItemOperationListener.class) {
    if (e == null)
    e = new ItemOperationEvent(this,item);
    ((ItemOperationlistener)listeners[i+1]).itemAdded(e);
    public void fireItemRemoved(String item)
    ItemOperationEvent e = null;
    Object[] listeners = listenerList.getListenerList();
    // Process the listeners last to first, notifying
    // those that are interested in this event
    for (int i = listeners.length-2; i>=0; i-=2) {
    if (listeners[i] == ItemOperationListener.class) {
    if (e == null)
    e = new ItemOperationEvent(this,item);
    ((ItemOperationlistener)listeners[i+1]).itemRemoved(e);
    4. The listener and the registration .
    public class OrderBook implements ItemOperationListener
    private Invoice invoice; // invoice instance.
    public OrderBook()
    // register for event updates .
    invoice.additemOperationListener(this);
    public void itemAdded(ItemOperationEvent ioe)
    String tobeAdded = ioe.getItem();
    calculate();
    public void itemRemoved(ItemOperationEvent ioe)
    String tobeRemoved = ioe.getItem();
    calculate();
    public void calculate()
    I hope this gives a picture of the standard method of event delivery in java . However you can even follow the Observer, Observable pattern (see the documentation for java.util.Observer, Observable).
    Hope this helps,
    Manish.

  • 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,
    Luis

    i 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

  • Non GUI input

    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/

Maybe you are looking for

  • Is there a limit to the number of Apps you can download to your iPod touch?

    I just downloaded a batch of new free apps the the App store to my Mac and then synced my iPod and it showed in the progress bar that it was transferring the new Apps to my iPod but when I checked it most on the new Apps weren't on there. Is there a

  • Problem in Receiver File adapter :Module XML2PLAIN

    Hi Friends, I have a FILE -> FILE scenario ,In this when I am downloading the data in XML format it is getting downloaded successfully.The output look like this ... <b>I have only one field to be displayed in the output</b>. <?xml version="1.0" encod

  • Javadoc @return and @returns

    Does anyone know what's the difference between Javadoc @return and @returns? When do we use which tag to document the return type?

  • What is the best adobe program to do an interactive infographics?

    Hi! I need to do an interactive Infographic map with data, text etc.. What is the best Adobe program to do that?

  • TS3694 what's error 6?

    I just spent 45 minutes "upgrading" to iOS 7.02 on my 4s. At about 95% of the way through I got an error 6. There is no info on Apples help pages about this. The phone is connected via usb to my MBP and is showing the apple and the progress bar froze