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.

Similar Messages

  • Accidently Moved all my events into one event

    My Mac was running slow so accidently dropped all my events into one.
    I then closed and reopened Iphoto hoping the changes wouldnt take effect.
    Urgently need to undo the action.  The UNDO button is greyed out.
    I clicked on Autosplit events, but how can i get my last copy of the library back and reload?  Where is it saved? 
    Please help

    No, it doesn't.  You must be proactive in setting up a backup strategy like using Time Machine with an external HD.  If you haven't setup a backup plan then you have no backup of the library to fall back on.
    So you're only course of action is to split (auto or manually) the one large event into events based on your criteria, i.e. by date, by photo opportunity, etc.  It could take a while.  One way to do it by date, i.e. by month is to use the Search function at the bottom of the window and do a search by each month of the year,  When you get the results for the first month, select them all and use the Events ➙ Create Event menu option.  This way you can create an event for each month of each year.

  • Split an event into mini-events by date?

    I recently went on a trip to Mexico with a large group, and afterwards I received a DVD with all of the pictures from the trip. Unfortunately the pictures were not split up by date. I would like to do this by the day the pictures were taken. Is there any way iPhoto can split all of the pictures into separate events by the imbedded data in the pictures?

    Select the event and go to the event menu ==> autosplit event
    or open the event and scan up from the bottom until you find a spot where you want to split - select the photo that you want to end the new event and click on the split button - continue up and splitting until you have it like you want
    in the future you can use the iPhoto preferences to do this on import (check the "split items imported from the finder into events" option
    LN

  • Help!! iphoto consolidated all of my events into one event!

    15 years of organization all ruined!! What can I do? Is there a "go back" or history fix for this?
    I have not down a recent time machine back up. Am I screwed? If I auto-split the events, that might be just as bad. I have organized all of these photos by hand over the years.

    1 - iPhoto does not change organization - users do - you may have done something inadvertenly
    2 - with no backup you have no backjup - the reason you must always have a backup is to "go Back" after an error - be it user, software or hardwary - no matter the reason with no backup you have no backup and no way to go back
    3 - since you have made the choice not to have a current backup your choices now are to autosplit or do it manually again
    4 - I strongly suggest that you start having Time Machine running all the time so you have an hourly backup available for the future - bad things will happen again sooner or later - and next time it may be total loss of everythign - not just of yoru organization
    LN

  • How do I split a single event with many clips into multiples events, one event per date?

    I archived the video from my AVCHD camera into a Final Cut video archive. Later I imported this into iMovie. All the clips from this archive (spanning several months) are dumped into a single event. If I recall, older versions of iMovie would import video into separate events for each day. Then I would go through and give each event a meaningful name (e.g., "Mary's Birthday").
    This is what I would like. Is there a way to split this very long event into multiple events, one for each day that is present in the event?

    Not automatically but with imovie 10 you can create new events with any name you like then move clips into them from other events  (Just like FCP 10.1).   See:
    http://help.apple.com/imovie/mac/10.0/#mov1d890f00b
    You can also choose to display clips in an event grouped by date.
    Geoff

  • I can't split a home DVD into multiple events. Why?

    I have a DVD of old super 8 movies that I converted into a DVD years ago and want to extract selected segments as short movie clips. I have been able to load the entire DVD as a single event but I wanted to break this single event into multiple events based on various themes. My problem is that I don't seem to be able to split the content at all. The "Split event before selected Clip" always appears to be grayed out. What am I doing wrong?
    paulfromcrystal

    I just figured it out.  Somehow I didn't change it to the correct code of 1.  So on the second shot of 5 allowed I realized I didn't change and save.  Now the dvd played.

  • How do I merge events - not just combining pictures into one event?

    I have a iPhoto 09 and haven't upgraded yet. I have a bunch of events and it's hard to get through all of them. Can I combine the events while retaining the seperate events? Sort of an event within an event; not adding all the pictures from one event into anoher event and losing the deliniation.
    Or, can I archive them somewhere so they don't appear in my Event list?

    Can I combine the events while retaining the seperate events?
    No. If you merger events you'll end up with just one event representing those that you merged. 
    To make selected events invisible in the Events mode do the following:
    1 - select the events and double click on one of them to open all in the same window.
    2 - type Command+A to select all photos.
    3 - right or Control-click on any of the selected photos.
    4 - click on Hide in the window that comes up:
    That will hid those events from the list of other events in the Events mode and wherever else those photos are, i.e. albums, books, etc.
    To makes the Events visible again use the View ➙ Hidden Photos menu option:
    To make them permanently viewable you'll need to select those events and follow steps 1-4 above but click on the Show button this time.
    OT

  • Running Visual Basic macro

    Can I run a Visual Basic macro from Java? How do I do that?

    If your macro can be invoked from the command line, then you should be able to run it by using Runtime.exec()

  • Can I have a general daq event in visual basic while outputing in dma mode?

    Hardware: PCI-6711
    Software: Visual Basic 6.0
    NI-DAQ 6.9.3f3
    Windows 2000
    I can't get the GeneralDAQEvent_Fire subroutine to happen. I'm trying to output two synchronized waveforms on two channels at sampling rates that can be changed on the fly. To do this, I've set the clock source of the channels to be the GPCTR1. I output on a pulse train on the GPCTR1 and adjust the pulse widths to vary the frequency. I need to be able to switch to the new pulse width at a precise time so that the correct samples are output at the correct samplerate. I want to generate a general daq event which fires whenever a certain number of pulses (and thus samples) on the GPCTR1 have been output. I will
    then reset the event and output samplerate within the GeneralDAQEvent_Fire subroutine for the next section of samples. I need to output at up to 1 MSample/second, so I need to be using DMA mode. I have not read anywhere that DAQEvent 0 Aqcuired or Generated n Scans requires interrupt mode, am I wrong about this? I have set my Channel string to CTR1, does this reference the GPCTR1? I set the board, DAQTrigVal0 and enabled properties and then call the refresh method. Is there something else I should do?
    I have been reading the NIDAQ Function Reference Help and the NIDAQ for PC Reference manual and have not found a solution. Any suggestions? Also, where can I find info on what the ConfigureDaqEvent method is supposed to do?

    Roz,
    First of all, I think you will want to use DAQ Event 1 since you desire for a message to be sent after every N updates. This will be more efficient than removing the current message and adding a new message each time the event fires. Furthermore, DAQ Events 0-2 can all be used with DMA transfers. However, you will be unable to use a counter channel with DAQ Events 0-2. Instead you should use one of the analog output channel you are clocking with the counter's output.
    Good luck with your application.
    Spencer S.

  • ActiveMovie Control,Translating ActiveX calls from Visual Basic into Labview

    Hello,
    I want to use DirectX to display a movie. In the attached file is a Visual Basic example
    which I tried to translate into Labview.
    To play the movie IMediaControl from ActiveMovie control type library Version 1.0 C:\WINDOWS\system32\Quartz.dll) is used.
    To display the current Position I tried to wire the IMediaPostion. But I have no idea how to implement this in the Block Diagram.
    After opening it the following message is shown.
    Error 3005 occurred at Automation Open: Object specified is not creatable in Play Movie Current Possition.vi
    Attachments:
    Play_Movie_Current_Possition.vi ‏48 KB

    Hello Joe,
    the Windows Media Player has a lot of overhead. I also found it difficult to deal with the different Versions.
    I want to display data in a graph and show the connected video frame in a separate window.
    I used the QuartzTypeLib because it is on every Windows Computer and is easy to code in VB.
    With one call I can start the video in Labview., but I find no way to wire the current position. I do not really understand how ActiveX is implemented in Labview. I attached a LV 7.0 vi. I hope you can open it.
    Tiemo
    Attachments:
    Play_Movie_Current_Position.vi ‏63 KB

  • Can anybody translate this one-line Visual Basic into AppleScript?

    I have been pulling my hair out in trying to get InDesign CS4 to markup selected text with an XML tag. Supposedly this can be done using Visual Basic. Is there anybody out there that could possibly translate this seemingly simply code into AppleScript?
    myText.AssociatedXMLElements.Item(1).XMLElements.Add("break", myText)
    Here is another example:
    With myTSRangeText.AssociatedXMLElements.Item(1).Parent.XMLElements.Add("znak")
  Call .Markup(myTSRangeText)
End With
    I am still thinking that AS cannot do this… but it is worth a shot to ask.
    Thanks in advance,
    Jeff

    If it makes any difference
    This is what I have so far using AppleScript. It is very very close. But the result of running the script appends the tagged text to the end of the text in the frame. In other words, it looks like this: (assuming I had the characters "word" highlighted). This is because I can only seem to tell the story to markup using the tag. I cannot tell the selection to markup using the tag?
    This word is the item I want to tag.[word]
    I am wanting the result to tag the selected item. So it should look like this:
    This [word] is the item I want to tag.
    tell application "Adobe InDesign CS4"
        tell document 1
            set selText to object reference of (text from character 1 to character -1) of selection
            set selTextString to selText as string
            display dialog selText as string
            set parentStoryID to parent story of selection
            set myXMLTag to (get XML tag "theDate")
            set myXMLStoryTag to (get XML tag "Story")
            tell XML element 1
                set theStoryElement to make XML element with properties {markup tag:"Story"}
                tell theStoryElement
                    set myXMLElement to make XML element with properties {markup tag:"theDate", contents:selTextString}
                    tell parentStoryID to markup using theStoryElement
                end tell
            end tell
        end tell
    end tell

  • U00BFHow can I raise an event from visual basic to BW?

    Im looking for simple vb code that will raise and event that will trigger some process chains I have in bw.
    something similar to
    Set R3 = CreateObject("SAP.Functions")
    R3.RaiseEvent("myEvent")
    I'm sure I saw the code before, but I have looked for hours and couldnt find it again.
    Thanks!
    David G

    Hello, this is how I finally did it and it is working pretty well.
    In SAP
    1. In SM62 Create new Event: ZGDREV01
    2. In RSPC (Process Chain Maintenance)
    - Start Variant after Event : ZGDREV01
    Periodic Job: Checked (other wise it wil just trigger once)   
    3. In SE37 Created a new function module:
    Attributes: Remote-Enabled Module
    Import:  EVENTID (char string)
    Source Code:
    FUNCTION ZGDRFM08.
    *"*"Local Interface:
    *"  IMPORTING
    *"     VALUE(EVENTID) TYPE  ZTXTSH
      CALL FUNCTION 'BP_EVENT_RAISE'
      exporting
      eventid = EVENTID.
    ENDFUNCTION.
    4. In Visual Basic
    Public Const TRANDATA_EVENTID = "ZGDREV01" ' EventId to be Raised
    Private Sub cmdStartLoad_Click()
       Dim R3 as object
       Set R3 = CreateObject("SAP.Functions")
       Call TriggerLoadEvent(R3, TRANDATA_EVENTID)
    End Sub
    Public Function TriggerLoadEvent(ByRef R3 As Object, ByVal event_id As String) As Boolean
        Dim FuncVal As Object
        Dim param_event As Object
        On Error GoTo errHandler
        Set FuncVal = R3.Add("ZGDRFM08")
        Set param_event = FuncVal.Exports("EVENTID")
        param_event.value = event_id
        TriggerLoadEvent = FuncVal.call
        Exit Function
    errHandler:
        MsgBox Err.description
    End Function
    Edited by: David Guerra Farias on Feb 11, 2008 11:13 PM

  • Using the General DAQ Event control for Visual Basic

    HardwareCI_6711
    Software:Visual Basic
    running Windows 2000
    I'm trying to add the dacevent.ocx to my project and it won't install. I read off of http://digital.ni.com/public.nsf/3efedde4322fef198​62567740067f3cc/4dc40c5d3ff5e7cc862564a6007cf5c1?O​penDocument that the OC30.dll is required to do this. I can't find it on my system and I'm thinking that is why the ocx file won't load. Where can I find this dll? Are there any other requirements for adding the control? I may also be trying to install it the wrong way: I am just using the open file command in my project and selecting daqevent.ocx from the nidaq folder in WINNT. Any help would be much appreciated, thanks.

    Nevermind, I found it. And I was opening it wrong. I think I had actually already installed it as a reference and just forgot to add it to the components toolbar.
    ... wow, some days...

  • LabView TEDS library into DLL or ActiveX Control so that I can use it in C or Visual Basic?

    We are developing software in LabWindows/CVI and Microsoft C. I heard that LabView can generate DLLs. Can I turn LabView TEDS library into DLL or ActiveX Control so that I can use it in C or Visual Basic development environment?

    Technically what you are proposing is possible with LabVIEW. With LabVIEW's application builder, VIs can be built into dlls. Also, LV has ActiveX hooks and so you could create a system for calling into it from CVI. However, this is not what I would recommend.
    The LabVIEW VIs have been written to a preliminary version of the IEEE specification (1451.4) that describes the TEDS data which is primarily why I'm advising you against using them. Once the IEEE spec is approved (the current timeline is currently late March), it will become public and you can write your own code according to the specification (or wait for someone else to write it). To help you get started, the spec includes flex and bison code that describes the syntax and structure of the template files
    Internally, we've written some C, C++ and Java code to the preliminary version of the spec and we've found that we can duplicate the functionality of the TEDS Library for LV in roughly 2 weeks in any other language.

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

Maybe you are looking for