Help with Event Handlers with Scope
I have a question of how I must implement the event handlers with scope, I have problems in the execution of processes BPEL (they are generating exceptions in the dehydration)
I have two models for event handlers and I need to know which is the best way to implement event handlers.
Another question is, in what it influences the "variableAccessSerializable" attribute.
Thanks!
1) Event Handlers with PartnerLink invocation OUTSIDE Scope
<invoke name="Invoke_1" partnerLink="PartnerLink1"/>
<scope name="Scope_1" variableAccessSerializable="yes">
<eventHandlers>
<onMessage partnerLink="PartnerLink1"/>
<onAlarm/>
</eventHandlers>
<sequence name="Sequence_1">
</sequence>
</scope>
2) Event Handler with PartnerLink invocation INSIDE scope
<scope name="Scope_1" variableAccessSerializable="yes">
<eventHandlers>
<onMessage partnerLink="PartnerLink1"/>
<onAlarm/>
</eventHandlers>
<sequence name="Sequence_1">
<invoke name="Invoke_1" partnerLink="PartnerLink1"/>
</sequence>
</scope>
Thanks -- indeed a crucial call might be missing. I was doing
this until 3 yesterday morning.
Would this be the correct sample code to use? :
http://livedocs.macromedia.com/flash/mx2004/main_7_2/wwhelp/wwhimpl/common/html/wwhelp.htm ?context=Flash_MX_2004&file=00000846.html
It seems to work (although someone cautions in the page
comments that it doesn't).
Part of my trouble in working with AS 2.0 is that I feel I
shouldn't have to do such complicated things (Delegate classes,
etc) in order to get simple things done (loading XML files). This
is not a complaint per se -- rather I feel that I must be missing
something, that it is my inexperience that is causing me to bend
through so many hoops: programming "should" be elegant and simple.
So, any links helpful. Thanks.
Similar Messages
-
Help me with event handling with this GUI
I have a project called AUTO ARCHIVING application GUI
These are the content of this GUI
1.Log In Page
2.Main Page -wherein the main page will contain 4 buttons wirh specific
functions,namely:
Button1=Auto Archive
Button2=Reports and Logs
Button3=Manual Archive
Button4=Log Off
This is where i need your help
Once the user successfully log in it will display the main form..will someone help me with this one....http://www.personal.psu.edu/ajs372/photos/random/bunny_pancake.jpg
-
OIM11g - Event handlers - picking up external libraries
Hi all,
I seem to be running into an issue with event handlers. I have to refer to some other custom libraries within them and they don't seem to be accessible by the event handlers.
I've put the libraries in JavaTasks and ThirdParty but I'm still getting NoClassDef found and in the worst case the Orcherstration engine seems to break preventing me from even logging into OIM and meaning I have to remove the event handler metadata manually.
Does anyone know how the event handler classpath works and where I can put libs such that event handlers can use them?
Thanks.
Wayne.From the WebLogic Administrator screen, you can go to the servers for your OIM Server, or SOA Server, whichever will be accessing the jar. Under the server start tab, add in the path in the classpath section for your jar file. User forward slashes. Now when your server starts, it will load those jar files and they should be accessible.
-Kevin -
Hello Friends;
I have a problem with event handlers. I have defined events for double_click, data_change and hotspot_click. At first run of the program everything runs fine but when I make a change at the screen (like pressing Enter or entering a value at a screen field) the handlers seem to be called a couple of times. For example at a hotspot click I call an accounting document display and when I want to return with back button the program seems to be stuck at document display. Actually it calls event handler over and over again. How can I solve this problem? Can refreshing grid be a solution?
Thx in advance
AliHello Ali
The problem is that after handling the hotspot event the current cell is still on the field with the hotspot. Thus, when you push ENTER the ALV grid checks the current cell which has a hotspot defined which, in turn, raises event HOTSPOT_CLICK.
Therefore, you have to move the current cell to another cell that has no hotspot defined. Have a look at the implementation of the event handler method. The hotspot is on field KUNNR. After calling transaction XD03 I shift the current cell to field BUKRS.
If you comment these lines you will see the same behaviour of the report as you described.
*& Report ZUS_SDN_TWO_ALV_GRIDS
REPORT ZUS_SDN_ALVGRID_EVENTS.
DATA:
gd_okcode TYPE ui_func,
gt_fcat TYPE lvc_t_fcat,
go_docking TYPE REF TO cl_gui_docking_container,
go_grid1 TYPE REF TO cl_gui_alv_grid.
DATA:
gt_knb1 TYPE STANDARD TABLE OF knb1.
PARAMETERS:
p_bukrs TYPE bukrs DEFAULT '1000' OBLIGATORY.
* CLASS lcl_eventhandler DEFINITION
CLASS lcl_eventhandler DEFINITION.
PUBLIC SECTION.
CLASS-METHODS:
handle_hotspot_click FOR EVENT hotspot_click OF cl_gui_alv_grid
IMPORTING
e_row_id
e_column_id
es_row_no
sender.
ENDCLASS. "lcl_eventhandler DEFINITION
* CLASS lcl_eventhandler IMPLEMENTATION
CLASS lcl_eventhandler IMPLEMENTATION.
METHOD handle_hotspot_click.
* define local data
DATA:
ls_knb1 TYPE knb1,
ls_col_id type lvc_s_col.
READ TABLE gt_knb1 INTO ls_knb1 INDEX e_row_id-index.
CHECK ( ls_knb1-kunnr IS NOT INITIAL ).
SET PARAMETER ID 'KUN' FIELD ls_knb1-kunnr.
SET PARAMETER ID 'BUK' FIELD ls_knb1-bukrs.
CALL TRANSACTION 'XD03' AND SKIP FIRST SCREEN.
* Set active cell to field BUKRS otherwise the focus is still on
* field KUNNR which will always raise event HOTSPOT_CLICK
ls_col_id-fieldname = 'BUKRS'.
CALL METHOD go_grid1->set_current_cell_via_id
EXPORTING
IS_ROW_ID = e_row_id
IS_COLUMN_ID = ls_col_id.
ENDMETHOD. "handle_hotspot_click
ENDCLASS. "lcl_eventhandler IMPLEMENTATION
START-OF-SELECTION.
SELECT * FROM knb1 INTO TABLE gt_knb1
WHERE bukrs = p_bukrs.
* Create docking container
CREATE OBJECT go_docking
EXPORTING
parent = cl_gui_container=>screen0
ratio = 90
EXCEPTIONS
OTHERS = 6.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
* Create ALV grid
CREATE OBJECT go_grid1
EXPORTING
i_parent = go_docking
EXCEPTIONS
OTHERS = 5.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
* Set event handler
SET HANDLER:
lcl_eventhandler=>handle_hotspot_click FOR go_grid1.
* Build fieldcatalog and set hotspot for field KUNNR
PERFORM build_fieldcatalog_knb1.
* Display data
CALL METHOD go_grid1->set_table_for_first_display
CHANGING
it_outtab = gt_knb1
it_fieldcatalog = gt_fcat
EXCEPTIONS
OTHERS = 4.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
* Link the docking container to the target dynpro
CALL METHOD go_docking->link
EXPORTING
repid = syst-repid
dynnr = '0100'
* CONTAINER =
EXCEPTIONS
OTHERS = 4.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
* ok-code field = GD_OKCODE
CALL SCREEN '0100'.
END-OF-SELECTION.
*& Module STATUS_0100 OUTPUT
* text
MODULE status_0100 OUTPUT.
SET PF-STATUS 'STATUS_0100'.
* SET TITLEBAR 'xxx'.
ENDMODULE. " STATUS_0100 OUTPUT
*& Module USER_COMMAND_0100 INPUT
* text
MODULE user_command_0100 INPUT.
CASE gd_okcode.
WHEN 'BACK' OR
'END' OR
'CANC'.
SET SCREEN 0. LEAVE SCREEN.
WHEN OTHERS.
ENDCASE.
CLEAR: gd_okcode.
ENDMODULE. " USER_COMMAND_0100 INPUT
*& Form BUILD_FIELDCATALOG_KNB1
* text
* --> p1 text
* <-- p2 text
FORM build_fieldcatalog_knb1 .
* define local data
DATA:
ls_fcat TYPE lvc_s_fcat.
CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
EXPORTING
* I_BUFFER_ACTIVE =
i_structure_name = 'KNB1'
* I_CLIENT_NEVER_DISPLAY = 'X'
* I_BYPASSING_BUFFER =
* I_INTERNAL_TABNAME =
CHANGING
ct_fieldcat = gt_fcat
EXCEPTIONS
inconsistent_interface = 1
program_error = 2
OTHERS = 3.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
READ TABLE gt_fcat INTO ls_fcat
WITH KEY fieldname = 'KUNNR'.
IF ( syst-subrc = 0 ).
ls_fcat-hotspot = abap_true.
MODIFY gt_fcat FROM ls_fcat INDEX syst-tabix.
ENDIF.
ENDFORM. " BUILD_FIELDCATALOG_KNB1
Regards
Uwe -
Event handlers in a template file in uix
Is it possible to define event handlers in a uix template file. I would like to define a global button kind of like the following code:
<globalButton source="toolbar_icon_prefs.gif" text="My Profile"
destination="UsersMyProfile_View.uix" event="event1" />
I would probably remove the destination field and let the java program called by the event decide the destination.
The event handler would need to not interfer with event handlers defined on individual pages.
Thanks, SteveSorry, Steve, but event handlers are not supported in templates.
- Ryan -
I need help with event structure.
I am trying to feed the index of the array, the index number can vary from 0 to 7.
Based on the logic ouput of a comparison, the index buffer should increment
or decrement every time the output of comparsion changes(event change). I guess I need to use event structure?
(My event code doesn't execute when there is an event at its input /comparator changes its boolean state.
Anyone coded on similar lines? Any ideas appreciated.
Thanks in advance!You don't need an Event Structure, a simple State Machine would be more appropriate.
There are many examples of State Machines within this forum.
RayR -
Hello!
I'm at my wits end: please help! It seems straight forward, and I sold my client on BC thinking this was doable in the events module, but it seems maybe not so without a ton of custom coding.
1. Book an event online,
with option for multiple (say 1-5 people at a fixed cost per person),
and checkout using only Pay Pal (standard or pro, doesn't matter, but I think Standard won't work without shopping cart).
2. The events are every day but Sunday all year long (just admission to an attraction), so is there a way to upload months in advance so they don't have to be manually entered?
I'm so grateful for any assistance.This is all very achievable:
• Events you can add multiple people to book.
• PayPal you use use our APP that's in the BC Appstore (Liam to confirm is works with bookings)
I'm sales and marketing at Pretty, so I'm not the person to advise on how all this fits together. But I'm sure Liam can point you in the right direction.
If you need some consulting or us to do it for you just let me know [email protected]
Brett
www.prettydigital.com.au -
Problems with .chart-plot-background and event handlers
Hello. I'm trying to add event handlers to my chart so that the user can be allowed click within the chart itself to perform certain actions like dragging, zooming, etc. To avoid having to deal with handling mouse clicks that lie outside the chart itself (for example on the axes), I've found that:
.chart-plot-background
is the Region that gives me the entire chart and nothing else. However, when I attach mouse listeners to this Region, the event is only registered on half of the cells in the chart. If you've seen the default JavaFX Chart background layout, you know that it contains alternating rows of cells with slightly different coloring. I've found that only the rows with the lightest gray coloring actually register a mouse click on them, which makes me believe the dark grey cells are not part of the .chart-plot-background, but something else on top.
To me, this feels like an oversight in how the regions of the chart are defined. Why can I not get a listener to work on the whole chart and nothing else? Currently the only workaround seems to be to take the Region:
.chart-content
instead, and compute the difference between this region and the .chart-plot-background in order to manually suppress mouse clicks that lie outside .chart-plot-background.
Anyone have suggestions? Is this worth issuing on the JavaFX Jira?Hello,
I'm not an expert on controls, but here is my guess based on your description: when you register an event handler on a "background" node, it is called only when the mouse hovers over the background node - I suppose the light gray is the background with the light gray cells being transparent and dark grey cells being filled. So the behavior seems correct - you can't expect the events to be delivered to background when it is covered by other nodes. I think you really should register the handler on the entire chart and filter out the events you don't want to handle. This however should not require much of computing the difference between the regions, it should be possible to do just something like
if (!background.contains(event.getX(), event.getY())) {
return;
Provided that the background doesn't reach under the axes as well. Note that if there are any different transforms between the background and the node with the handler registered on it, you may need to recompute the coordinates by
background.sceneToLocal(event.getSceneX(), event.getSceneY());
And use the contains method on that. -
Event Handlers which trigger functions with multiple arguments
I am playing two video clips back to back. I have a few
things which I need to do in between clips, so what I am doing for
each is adding a handler for VideoEvent.COMPLETE, at which time i
want to call a function which takes multiple arguments, like this:
video.addEventListener(VideoEvent.COMPLETE,
myFunction("1","2","3"));
private function myFunction(var1:String, var2:String,
var3:String):void
video.removeEventListeners(VideoEvent.COMPLETE, myFunction);
I've already figured out that getting rid of event handlers
that trigger anonymous functions is impossible. Please don't tell
me that it's impossible to remove them if functions require more
than 0 arguments..."muskiemania" <[email protected]> wrote in
message
news:gc0pk0$jfb$[email protected]..
>I am playing two video clips back to back. I have a few
things which I need
>to
> do in between clips, so what I am doing for each is
adding a handler for
> VideoEvent.COMPLETE, at which time i want to call a
function which takes
> multiple arguments, like this:
>
> video.addEventListener(VideoEvent.COMPLETE,
myFunction("1","2","3"));
>
> private function myFunction(var1:String, var2:String,
var3:String):void
> {
> video.removeEventListeners(VideoEvent.COMPLETE,
myFunction);
> }
>
> I've already figured out that getting rid of event
handlers that trigger
> anonymous functions is impossible. Please don't tell me
that it's
> impossible to
> remove them if functions require more than 0
arguments...
Any function that you add via addEventListener should expect
exactly ONE
argument, the event. And 99.958% of the time, you can take
that event
object and figure out exactly what you need to know.
HTH;
Amy -
Need Help with Event Handler Code - Doesnt come up in Event Handler Manager
Hello there,
Below is the code snippet that I am using to create a event handler:
package com.oracle.events;
import com.thortech.util.logging.Logger;
import com.thortech.xl.client.events.tcBaseEvent;
import com.thortech.xl.dataobj.tcDataObj;
import com.thortech.xl.util.logging.LoggerModules;
public class tcCheckOvrallProvStatusUDFs extends tcBaseEvent
private static Logger logger = Logger.getLogger(LoggerModules.XL_JAVA_CLIENT);
public tcCheckOvrallProvStatusUDFs()
setEventName("Generating tcCheckOvrallProvStatusUDFs");
* @Override
* @throws Exception
protected void implementation() throws Exception {
tcDataObj data = getDataObject();
String OIDProvStatus = data.getString("usr_udf_oidusrprovstatus");
String EBSProvStatus = data.getString("usr_udf_ebstcausrprovstatus");
if (OIDProvStatus.equals("Provisioned") && EBSProvStatus.equals("Provisioned")) {
setOverAllProvStatus(data);
* @param data
* @throws Exception
private void setOverAllProvStatus(tcDataObj data) throws Exception
data.setString("usr_udf_ovrrscprovstatus", "Provisioned");
Its a simple code that I am using to populate value of a UDF field depending on the value of other 2 fields. I want to trigger it on Post-Insert and Post-Update events.
But even if I restart the OIM server after placing the successfully compiled file (0 errors, 0 warnings) into the EventHandlers folder of OIM_HOME; it doesnt show up in the Design Console -> Development Tools -> Business Rule Definition -> Event Handler Manager. :( In order to create a event handler i need that file to show up in the lookup of event handlers/adapters. This JAR file doesnt come up over there.
Is there anything missing within the code ?
What else needs to be specified?
Please provide some guidance.
Thanks,
- jhb.Now I have placed this JAR file in JAVATasks folder - made an entity adapter - in the event handler manager - i gave the class name/event handler name as 'setUDFValue' and the package as 'project5'. But now im getting it 'DOBJ.EVT_NOT_FOUND - Event Handler not found' error.
package project5;
import java.util.Hashtable;
import Thor.API.Exceptions.tcAPIException;
import java.util.Hashtable;
import java.util.HashMap;
import com.thortech.xl.util.config.ConfigurationClient;
import Thor.API.tcResultSet;
import Thor.API.tcUtilityFactory;
import Thor.API.Operations.tcUserOperationsIntf;
import java.lang.System;
import Thor.API.Exceptions.tcUserNotFoundException;
import java.util.Properties;
import javax.mail.Message;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
public class setUDFValue {
private static final String SMTP_HOST_NAME="mail.smtp.host";
public setUDFValue() {
// public static void main(String[] args) {
// setUDFValue.setvalue("jatinbhatt");
// setUDFValue.sendemail("[email protected]","[email protected]");
public static void setvalue(String UserID) {
try
System.setProperty("XL.HomeDir", "F:/oim/oimserver/xellerate");
System.setProperty("log4j.configuration",
"F:/oim/oimserver/xellerate/config/log.properties");
System.setProperty("java.security.policy",
"F:/oim/oimserver/xellerate/config/xl.policy");
System.setProperty("java.security.auth.login.config",
"F:/oim/oimserver/xellerate/config/auth.conf");
System.out.println("Startup...");
System.out.println("Getting configuration...");
ConfigurationClient.ComplexSetting config = ConfigurationClient.getComplexSettingByPath("Discovery.CoreServer");
System.out.println("Login...");
Hashtable env = config.getAllSettings();
tcUtilityFactory ioUtilityFactory = new tcUtilityFactory(env,"xelsysadm","oimadmin1");
System.out.println("Getting utility interfaces...");
tcUserOperationsIntf moUserUtility = (tcUserOperationsIntf)ioUtilityFactory.getUtility("Thor.API.Operations.tcUserOperationsIntf");
HashMap userMap = new HashMap();
String str1 = null;
String str2 = null;
userMap.put("Users.User ID",UserID);
userMap.put("Users.Status", "Active");
tcResultSet userResultSet = null;
try {
userResultSet = moUserUtility.findAllUsers(userMap);
} catch (tcAPIException e2) {
// TODO Auto-generated catch block
e2.printStackTrace();
for (int i=0; i<userResultSet.getRowCount(); i++)
userResultSet.goToRow(i);
str1 = userResultSet.getStringValue("USR_UDF_OIDUSERPROV");
str2 = userResultSet.getStringValue("USR_UDF_EBSUSERPROV");
// System.out.println(userResultSet.getStringValue("USR_UDF_OIDUSERPROV"));
// System.out.println(userResultSet.getStringValue("USR_UDF_EBSUSERPROV"));
if (str1.equals("Provisioned") && (str2.equals("Provisioned") || str2.equals("NA")))
userMap.put("USR_UDF_OVRRSCPROVSTATUS","Provisioned");
moUserUtility.updateUser(userResultSet,userMap);
moUserUtility.close();
}catch (Exception e){
e.printStackTrace();
ERROR:
ERROR RMICallHandler-63 XELLERATE.SERVER - Class/Method: tcDataObj/ runEvent encounter some problems: project5.setUDFValue
java.lang.ClassCastException: project5.setUDFValue
at com.thortech.xl.dataobj.tcDataObj.runEvent(Unknown Source)
at com.thortech.xl.dataobj.tcDataObj.eventPostUpdate(Unknown Source)
at com.thortech.xl.dataobj.tcUSR.eventPostUpdate(Unknown Source)
at com.thortech.xl.dataobj.tcDataObj.update(Unknown Source)
at com.thortech.xl.dataobj.tcDataObj.save(Unknown Source)
at com.thortech.xl.dataobj.tcTableDataObj.save(Unknown Source)
at com.thortech.xl.ejb.beansimpl.tcUserOperationsBean.updateUserData(Unknown Source)
at com.thortech.xl.ejb.beansimpl.tcUserOperationsBean.updateUser(Unknown Source)
at com.thortech.xl.ejb.beans.tcUserOperationsSession.updateUser(Unknown Source)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at com.evermind.server.ejb.interceptor.joinpoint.EJBJoinPointImpl.invoke(EJBJoinPointImpl.java:35)
at com.evermind.server.ejb.interceptor.InvocationContextImpl.proceed(InvocationContextImpl.java:119)
at com.evermind.server.ejb.interceptor.system.DMSInterceptor.invoke(DMSInterceptor.java:52)
at com.evermind.server.ejb.interceptor.InvocationContextImpl.proceed(InvocationContextImpl.java:119)
at com.evermind.server.ejb.interceptor.system.TxRequiredInterceptor.invoke(TxRequiredInterceptor.java:50)
at com.evermind.server.ejb.interceptor.InvocationContextImpl.proceed(InvocationContextImpl.java:119)
at com.evermind.server.ejb.interceptor.system.SecurityRoleInterceptor.invoke(SecurityRoleInterceptor.java:47)
at com.evermind.server.ejb.interceptor.InvocationContextImpl.proceed(InvocationContextImpl.java:119)
at com.evermind.server.ejb.interceptor.system.DMSInterceptor.invoke(DMSInterceptor.java:52)
at com.evermind.server.ejb.interceptor.InvocationContextImpl.proceed(InvocationContextImpl.java:119)
at com.evermind.server.ejb.InvocationContextPool.invoke(InvocationContextPool.java:55)
at com.evermind.server.ejb.StatelessSessionEJBObject.OC4J_invokeMethod(StatelessSessionEJBObject.java:87)
at tcUserOperations_RemoteProxy_6ocop18.updateUser(Unknown Source)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at com.evermind.server.rmi.RmiMethodCall.run(RmiMethodCall.java:53)
at com.evermind.util.ReleasableResourcePooledExecutor$MyWorker.run(ReleasableResourcePooledExecutor.java:303)
at java.lang.Thread.run(Thread.java:595)
Thanks,
- jhb. -
Having an issue with event handling - sql & java
HI all am trying to construct this hybrid of java and mysql. the data comes from a mysql database and I want it to display in the gui. this I have achieved thus far. However I have buttons that sort by surname, first name, ID tag etc....I need event handlers for these buttons but am quite unsure as to how to do it. any help would be much appreciated. Thanks in advance.
/* Student Contact Database GUI
* Phillip Wells
import java.awt.BorderLayout;
// imports java class. All import class statements tell the compiler to use a class that is defined in the Java API.
// Borderlayout is a layout manager that assists GUI layout.
import javax.swing.*; // imports java class. Swing enables the use of a GUI.
import javax.swing.JOptionPane; // imports java class. JOptionPane displays messages in a dialog box as opposed to a console window.
import javax.swing.JPanel; // imports java class. A component of a GUI.
import javax.swing.JFrame; // imports java class. A component of a GUI.
import javax.swing.JButton; // imports java class. A component of a GUI.
import javax.swing.JScrollPane; // imports java class. A component of a GUI.
import javax.swing.JTable; // imports java class. A component of a GUI.
import java.awt.*; // imports java class. Similar to Swing but with different components and functions.
import java.awt.event.*; // imports java class. Deals with events.
import java.awt.event.ActionEvent; // imports java class. Deals with events.
import java.awt.event.ActionListener; // imports java class. Deals with events.
import java.sql.*; // imports java class. Provides API for accessing and processing data stored in a data source.
import java.util.*; // imports java class. Contains miscellaneous utility classes such as strings.
public class studentContact extends JFrame { // public class declaration. The �public� statement enables class availability to other java elements.
private JPanel jContentPane; // initialises content pane
private JButton snam, id, fname, exit; // initialises Jbuttons
String firstname = "firstname"; //initialises String firstname
String secondname = "secondname"; //initialises String
public studentContact() {
Vector columnNames = new Vector(); // creates new vector object. Vectors are arrays that are expandable.
Vector data = new Vector();
initialize();
try {
// Connect to the Database
String driver = "com.mysql.jdbc.Driver"; // connect to JDBC driver
String url = "jdbc:mysql://localhost/Studentprofiles"; //location of Database
String userid = "root"; //user logon information for MySQL server
String password = ""; //logon password for above
Class.forName(driver); //reference to JDBC connector
Connection connection = DriverManager.getConnection(url, userid,
password); // initiates connection
// Read data from a table
String sql = "Select * from studentprofile order by "+ firstname;
//SQL query sent to database, orders results by firstname.
Statement stmt = connection.createStatement
(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
//statement to create connection.
//Scroll sensitive allows movement forth and back through results.
//Concur updatable allows updating of database.
ResultSet rs = stmt.executeQuery(sql); // executes SQL query stated above and sets the results in a table
ResultSetMetaData md = rs.getMetaData(); // used to get the properties of the columns in a ResultSet object.
int columns = md.getColumnCount(); //
for (int i = 1; i <= columns; i++) {
columnNames.addElement(md.getColumnName(i)); // Get column names
while (rs.next()) {
Vector row = new Vector(columns); // vectors data from table
for (int i = 1; i <= columns; i++) {
row.addElement(rs.getObject(i)); // Get row data
data.addElement(row); // adds row data
rs.close();
stmt.close();
} catch (Exception e) { // catches exceptions
System.out.println(e); // prints exception message
JTable table = new JTable(data, columnNames) { //constructs JTable
public Class getColumnClass(int column) {
for (int row = 0; row < getRowCount(); row++) {
Object o = getValueAt(row, column);
if (o != null) {
return o.getClass();
return Object.class;
JScrollPane scrollPane = new JScrollPane( table ); // constructs scrollpane 'table'
getContentPane().add(new JScrollPane(table), BorderLayout.SOUTH); //adds table to a scrollpane
private void initialize() {
this.setContentPane(getJContentPane());
this.setTitle("Student Contact Database"); // sets title of table
ButtonListener b1 = new ButtonListener(); // constructs button listener
snam = new JButton ("Sort by surname"); // constructs Jbutton
snam.addActionListener(b1); // adds action listener
jContentPane.add(snam); //adds button to pane
id = new JButton ("Sort by ID"); // constructs Jbutton
id.addActionListener(b1); // adds action listener
jContentPane.add(id); //adds button to pane
fname = new JButton ("Sort by first name"); // constructs Jbutton
fname.addActionListener(b1); // adds action listener
jContentPane.add(fname); //adds button to pane
exit = new JButton ("Exit"); // constructs Jbutton
exit.addActionListener(b1); // adds action listener
jContentPane.add(exit); //adds button to pane
private JPanel getJContentPane() {
if (jContentPane == null) {
jContentPane = new JPanel(); // constructs new panel
jContentPane.setLayout(new FlowLayout()); // sets new layout manager
return jContentPane; // returns Jcontentpane
private class ButtonListener implements ActionListener { // create inner class button listener that uses action listener
public void actionPerformed (ActionEvent e)
if (e.getSource () == exit) // adds listener to button exit.
System.exit(0); // exits the GUI
if (e.getSource () == snam)
if (e.getSource () == id)
if (e.getSource () == fname)
public static void main(String[] args) { // declaration of main method
studentContact frame = new studentContact(); // constructs new frame
frame.setDefaultCloseOperation(EXIT_ON_CLOSE); //exits frame on closing
frame.setSize(600, 300); // set size of frame
frame.setVisible(true); // displays frame
}p.s. sorry about the untidy comments!OK, so you've got this code here:
private class ButtonListener implements ActionListener {
public void actionPerformed (ActionEvent e) {
if (e.getSource () == exit) {
System.exit(0); // exits the GUI
if (e.getSource () == snam) {
if (e.getSource () == id) {
}Perfect fine way to do this; although I think creating anonymous would be a bit cleaner:
snam.addActionListener(new actionListener() {
public void actionPerformed(ActionEvent ae) {
});But I think that the real question you have is "what do I put for logic when the JButtons are hit?", right?
I would answer that you want to dynamically build your SQL statement changing your ordering based on the button.
So you'd have a method that builds the SQL based on what you pass in - so it takes one argument perhaps?
private static final int NAME = 1;
ID = 2;
/* ... some code ... */
snam.addActionListener(new actionListener() {
public void actionPerformed(ActionEvent ae) {
buildSQL(NAME);
/* ... some code ... */
private void buildSQL(int type) {
if ( type == NAME ) {
/* ... build SQL by name ... */
else if ( type == ID ) {
/* ... build SQL by id ... */
}That kind of thing.
Or you might choose to have several build methods with no parameter type; each building the SQL differently, and calling whichever one you need. I did not read your entire pgm, so I don't know how you'd want to organize it. You need to ask more specific questions at that point.
~Bill -
Having an issue with event handling - sql database & java gui
HI all, have posted this on another forum but I think this is the correct one to post on. I am trying to construct this hybrid of java and mysql. the data comes from a mysql database and I want it to display in the gui. this I have achieved thus far. However I have buttons that sort by surname, first name, ID tag etc....I need event handlers for these buttons but am quite unsure as to how to do it. any help would be much appreciated. Thanks in advance.
/* Student Contact Database GUI
* Phillip Wells
import java.awt.BorderLayout;
// imports java class. All import class statements tell the compiler to use a class that is defined in the Java API.
// Borderlayout is a layout manager that assists GUI layout.
import javax.swing.*; // imports java class. Swing enables the use of a GUI.
import javax.swing.JOptionPane; // imports java class. JOptionPane displays messages in a dialog box as opposed to a console window.
import javax.swing.JPanel; // imports java class. A component of a GUI.
import javax.swing.JFrame; // imports java class. A component of a GUI.
import javax.swing.JButton; // imports java class. A component of a GUI.
import javax.swing.JScrollPane; // imports java class. A component of a GUI.
import javax.swing.JTable; // imports java class. A component of a GUI.
import java.awt.*; // imports java class. Similar to Swing but with different components and functions.
import java.awt.event.*; // imports java class. Deals with events.
import java.awt.event.ActionEvent; // imports java class. Deals with events.
import java.awt.event.ActionListener; // imports java class. Deals with events.
import java.sql.*; // imports java class. Provides API for accessing and processing data stored in a data source.
import java.util.*; // imports java class. Contains miscellaneous utility classes such as strings.
public class studentContact extends JFrame { // public class declaration. The �public� statement enables class availability to other java elements.
private JPanel jContentPane; // initialises content pane
private JButton snam, id, fname, exit; // initialises Jbuttons
String firstname = "firstname"; //initialises String firstname
String secondname = "secondname"; //initialises String
public studentContact() {
Vector columnNames = new Vector(); // creates new vector object. Vectors are arrays that are expandable.
Vector data = new Vector();
initialize();
try {
// Connect to the Database
String driver = "com.mysql.jdbc.Driver"; // connect to JDBC driver
String url = "jdbc:mysql://localhost/Studentprofiles"; //location of Database
String userid = "root"; //user logon information for MySQL server
String password = ""; //logon password for above
Class.forName(driver); //reference to JDBC connector
Connection connection = DriverManager.getConnection(url, userid,
password); // initiates connection
// Read data from a table
String sql = "Select * from studentprofile order by "+ firstname;
//SQL query sent to database, orders results by firstname.
Statement stmt = connection.createStatement
(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
//statement to create connection.
//Scroll sensitive allows movement forth and back through results.
//Concur updatable allows updating of database.
ResultSet rs = stmt.executeQuery(sql); // executes SQL query stated above and sets the results in a table
ResultSetMetaData md = rs.getMetaData(); // used to get the properties of the columns in a ResultSet object.
int columns = md.getColumnCount(); //
for (int i = 1; i <= columns; i++) {
columnNames.addElement(md.getColumnName(i)); // Get column names
while (rs.next()) {
Vector row = new Vector(columns); // vectors data from table
for (int i = 1; i <= columns; i++) {
row.addElement(rs.getObject(i)); // Get row data
data.addElement(row); // adds row data
rs.close();
stmt.close();
} catch (Exception e) { // catches exceptions
System.out.println(e); // prints exception message
JTable table = new JTable(data, columnNames) { //constructs JTable
public Class getColumnClass(int column) {
for (int row = 0; row < getRowCount(); row++) {
Object o = getValueAt(row, column);
if (o != null) {
return o.getClass();
return Object.class;
JScrollPane scrollPane = new JScrollPane( table ); // constructs scrollpane 'table'
getContentPane().add(new JScrollPane(table), BorderLayout.SOUTH); //adds table to a scrollpane
private void initialize() {
this.setContentPane(getJContentPane());
this.setTitle("Student Contact Database"); // sets title of table
ButtonListener b1 = new ButtonListener(); // constructs button listener
snam = new JButton ("Sort by surname"); // constructs Jbutton
snam.addActionListener(b1); // adds action listener
jContentPane.add(snam); //adds button to pane
id = new JButton ("Sort by ID"); // constructs Jbutton
id.addActionListener(b1); // adds action listener
jContentPane.add(id); //adds button to pane
fname = new JButton ("Sort by first name"); // constructs Jbutton
fname.addActionListener(b1); // adds action listener
jContentPane.add(fname); //adds button to pane
exit = new JButton ("Exit"); // constructs Jbutton
exit.addActionListener(b1); // adds action listener
jContentPane.add(exit); //adds button to pane
private JPanel getJContentPane() {
if (jContentPane == null) {
jContentPane = new JPanel(); // constructs new panel
jContentPane.setLayout(new FlowLayout()); // sets new layout manager
return jContentPane; // returns Jcontentpane
private class ButtonListener implements ActionListener { // create inner class button listener that uses action listener
public void actionPerformed (ActionEvent e)
if (e.getSource () == exit) // adds listener to button exit.
System.exit(0); // exits the GUI
if (e.getSource () == snam)
if (e.getSource () == id)
if (e.getSource () == fname)
public static void main(String[] args) { // declaration of main method
studentContact frame = new studentContact(); // constructs new frame
frame.setDefaultCloseOperation(EXIT_ON_CLOSE); //exits frame on closing
frame.setSize(600, 300); // set size of frame
frame.setVisible(true); // displays frame
}OK, so you've got this code here:
private class ButtonListener implements ActionListener {
public void actionPerformed (ActionEvent e) {
if (e.getSource () == exit) {
System.exit(0); // exits the GUI
if (e.getSource () == snam) {
if (e.getSource () == id) {
}Perfect fine way to do this; although I think creating anonymous would be a bit cleaner:
snam.addActionListener(new actionListener() {
public void actionPerformed(ActionEvent ae) {
});But I think that the real question you have is "what do I put for logic when the JButtons are hit?", right?
I would answer that you want to dynamically build your SQL statement changing your ordering based on the button.
So you'd have a method that builds the SQL based on what you pass in - so it takes one argument perhaps?
private static final int NAME = 1;
ID = 2;
/* ... some code ... */
snam.addActionListener(new actionListener() {
public void actionPerformed(ActionEvent ae) {
buildSQL(NAME);
/* ... some code ... */
private void buildSQL(int type) {
if ( type == NAME ) {
/* ... build SQL by name ... */
else if ( type == ID ) {
/* ... build SQL by id ... */
}That kind of thing.
Or you might choose to have several build methods with no parameter type; each building the SQL differently, and calling whichever one you need. I did not read your entire pgm, so I don't know how you'd want to organize it. You need to ask more specific questions at that point.
~Bill -
Event recevier with another list
Can some one help how i can attached ItemAdding event in the the other list with minimal changes in code.
Hi Reddyraj,
i need to add the another recevier in element.xml file so that the event will execute on that list
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<Receivers ListTemplateId="100">
<Receiver>
<Name>CustomEventReceiversItemAdded</Name>
<Type>ItemAdded</Type>
<Assembly>$SharePoint.Project.AssemblyFullName$</Assembly>
<Class>MyApp.CustomEventReceivers.CustomEventReceivers</Class>
<SequenceNumber>10000</SequenceNumber>
</Receiver>
<Receiver>
<Name>CustomEventReceiversItemAdding</Name>
<Type>ItemAdding</Type>
<Assembly>$SharePoint.Project.AssemblyFullName$</Assembly>
<Class>MyApp.CustomEventReceivers.CustomEventReceivers</Class>
<SequenceNumber>10000</SequenceNumber>
</Receiver>
</Receivers>
</Elements>
Check the link below..http://www.expertsupdates.com/sharepoint-articles/create-sharepoint-event-handlers-using-vishal-studio-66.aspxPlease mark the answer and vote me if you think that it will help you resolved the issue -
Events problem with (Java and ActiveX)
Hi,
I use an ActiveX component with Java and i've got a problem with events.
Java classes were generated with Bridge2Java (IBM).
In order to manage events I added a listener in my application :
javaMyActiveX = new MyActiveX();
javaMyActiveX.add_DMyActiveXEventsListener(new _DMyActiveXEventsAdapter());
I also added a constructor in the _DMyActiveXEventsAdapter class and I fill the body of methods.
The ActiveX generates two types of events :
- The ones are directly generated by methods.
- The others are generated by a thread.
With MS Products (VB, Visual C++, Visual J++), I catch all events.
With java (jdk 1.4), I catch only events generated by methods.
Can anyone help me.I'm not 100% sure, but the last time I used that bridge, it only worked if you ran your Java app within a Microsoft VM.
-
Hello all,
I have a problem with event handling. I have two buttons in my GUI application with the same name.They are instance variables of two different objects of the same class and are put together in the one GUI.And their actionlisteners are registered with the same GUI. How can I differentiate between these two buttons?
To be more eloborate here is a basic definition of my classes
class SystemPanel{
SystemPanel(FTP ftp){ app = ftp};
FTP app;
private JButton b = new JButton("ChgDir");
b.addActionListener(app);
class FTP extends JFrame implements ActionListener{
SystemPanel rem = new SystemPanel(this);
SystemPanel loc = new SystemPanel(this);
FTP(){
add(rem);
add(loc);
pack();
show();
void actionPerformed(ActionEvent evt){
/*HOW WILL I BE ABLE TO KNOW WHICH BUTTON WAS PRESSED AS THEY
BOTH HAVE SAME ID AND getSouce() ?
In this case..it if was from rem or loc ?
} It would be really helpful if anyone could help me in this regard..
Thanks
Hari VigenshHi levi,
Thankx..
I solved the problem ..using same concept but in a different way..
One thing i wanted to make clear is that the two buttons are in the SAME CLASS and i am forming 2 different objects of the SAME class and then putting them in a GUI.THERE IS NO b and C. there is just two instances of b which belong to the SAME CLASS..
So the code
private JButton b = new JButton("ChgDir");
b.setActionCommand ("1");
wont work as both the instances would have the label "ChgDir" and have setActionCommand set to 1!!!!
Actually I have an array of buttons..So I solved the prob by writting a function caled setActionCmdRemote that would just set the action commands of one object of the class differently ..here is the code
public void setActionCommandsRemote()
for(int i = 0 ; i <cmdButtons.length ; i++)
cmdButtons.setActionCommand((cmdButtons[i].getText())+"Rem");
This just adds "rem" to the existing Actioncommand and i check it as folows in my actionperformed method
if(button.getActionCommand().equals("DeleteRem") )
deleteFileRemote();
else if(button.getActionCommand().equals("Delete") )
deleteFileLocal();Anyway thanx a milion for your help..this was my first posting and I was glad to get a prompt reply!!!
Maybe you are looking for
-
How necessary is a separate scratch drive??
Greetings from cold, windy Humboldt, I'm looking into buying a new 15" macbook pro w/ my student discount and using FCP 5.1 to edit a short film on it. I do not have any form of external drive and quite honestly I won't have any money left to buy one
-
Today's update deleted my bluetooth connection
There was a Verizon Wireless update today on my Samsung Galaxy SIII and it is affecting my Bluetooth. Not sure if anyone else is having this problem. I have had to connect and disconnect everytime I get in and out of the car.. This is rediculious!! I
-
Database Connection Information for OAS SOA suite 10.1.3.1.0
Hi! I'm having a bit of trouble that I hope you can please help with... I've just installed oracle database and am now attempting to install oracle application server. Unfortunately everytime I attempt the install I receive a: "Install cannot connect
-
HI I have one WF doubt in CRMD_ORDER. I want to know whenever user change the Message Processor at the the mail triggured and the same time status automatically change like ASSIGNED.? How can i do? Is any function modules available for message proce
-
Music store error message- please help!
I've read previous posts regarding this error- just want to make sure I have the same problem before I uninstall the software. I am able to access the music store, but as soon as I hit the search or power search mode, I receive the error message " It