Creating a singleton Event Listener class
A typical singleton OO design pattern involved a protected (or private)
no-arg
constructor and a public instance() method that manages a private static
variable
referencing the single instance, internally invoking the no-arg constructor.
A class designated in web.xml as a <listener> must have a public no-arg
constructor.
(from http://e-docs.bea.com/wls/docs61/webapp/app_events.html#178593)
Anyone thoughts on how to accomplish both goals?
What I want to do: I'd like to set up a singleton to listen for session
events.
Other code will query this one-and-only-one session event listener for
various
information. Some of this info I can currently get from the runtime via
MBeans but
some I can't, hence my investigation into session event listeners.
TIA, matt.
Hi Matt,
This sounds like a case where you will need to have two classes -- your
singleton class, and then your session event listener class, which would use
the singleton class.
Dennis Munsie
Developer Relations Engineer
BEA Support
"Matt Hembree" <[email protected]> wrote in message
news:[email protected]..
A typical singleton OO design pattern involved a protected (or private)
no-arg
constructor and a public instance() method that manages a private static
variable
referencing the single instance, internally invoking the no-argconstructor.
>
A class designated in web.xml as a <listener> must have a public no-arg
constructor.
(from http://e-docs.bea.com/wls/docs61/webapp/app_events.html#178593)
Anyone thoughts on how to accomplish both goals?
Similar Messages
-
Creating custom event listener ?
Hello,
Is there anyone that have a link to a tutorial or have some information on what is needed to be able to create a custom event listener on a component ?
I am creating an interactive JSF chart library (JSFlot) and I would like to have events such as ChartDraggedEvent and ChartClickedEvent. I can create the events fine (and I can even queue them fine throught the standard action and actionListener interfaces), but I would like for the component to have attributes like chartDraggedListener and chartClickedListener, so that I can fire off the appropriate event to the appropriate listener.
Any help would be very much appreciated!Well, that is what I am doing. The Renderer:
if (event != null && event.equalsIgnoreCase("drag")) {
String componentValue = request.getParameter("componentValue");
//Cut out logic irrelevant for this example
FlotChartDraggedEvent dragEvent = new FlotChartDraggedEvent(component, dragValue);
dragEvent.setPhaseId(PhaseId.APPLY_REQUEST_VALUES);
dragEvent.queue();
} else if (event != null && event.equalsIgnoreCase("click")) {
//Cut out logic irrelevant for this example
FlotChartClickedEvent clickEvent = new FlotChartClickedEvent(component, clickedPoint, clickIndexInt, clickSeriesIndexInt, clickSeriesLabel);
clickEvent.setPhaseId(PhaseId.APPLY_REQUEST_VALUES);
clickEvent.queue();
}The problem though, is that both of these events gets delivered to the actionListener attribute of my component. What I assume is missing is functionality to register a custom listener for each event, and some code in the Tag-class and TLD to supply these listeners, and its these issues that I am unsure how is done. I may be missing something very basic here though :) -
Error trying to register a Java event listener
I'm trying to register a java event listener in 11g with the following piece of code:
DECLARE
b BOOLEAN := FALSE;
BEGIN
b := DBMS_XDB.createFolder('/public/resconfig');
b := DBMS_XDB.createResource(
'/public/resconfig/hr_event.xml',
'<ResConfig xmlns="http://xmlns.oracle.com/xdb/XDBResConfig.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.oracle.com/xdb/XDBResConfig.xsd
http://xmlns.oracle.com/xdb/XDBResConfig.xsd">
<event-listeners default-language="Java">
<listener>
<description>Category application</description>
<schema>HR</schema>
<source>xdbproject.OpenOfficeEventHandler</source>
<language>Java</language>
<events>
<Post-Create/>
<Post-LinkIn/>
</events>
</listener>
</event-listeners>
<defaultChildConfig>
<configuration>
<path>/public/resconfig/hr_event.xml</path>
</configuration>
</defaultChildConfig>
</ResConfig>');
END;
This results in the following error message
ORA-31146: Ugyldig lytterkilde HR.xdbproject.OpenOfficeEventHandler
ORA-06512: ved "XDB.DBMS_XDB", line 174
ORA-06512: ved line 5
which translates to Invalid listener source.
My class is loaded in the HR schema, and implements the XDBRepositoryEventListener
Does anybody have a suggestion to what I'm doing wrong, or how I can find out what makes my class invalid as a listener source?Check if it validates against the restrictions set in the XML Schema (Appendix A, Oracle XMLDB Developers Guide):
XDBResConfig.xsd: XML Schema for Resource Configuration
This section presents the Oracle XML DB supplied XML schema used to configure repository resources. This is accessible in Oracle XML DB Repository at path /sys/schemas/PUBLIC/xmlns.oracle.com/xdb/XDBResConfig.xsd.
XDBResConfig.xsd
<schema xmlns="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://xmlns.oracle.com/xdb/XDBResConfig.xsd"
xmlns:xdb="http://xmlns.oracle.com/xdb"
xmlns:rescfg="http://xmlns.oracle.com/xdb/XDBResConfig.xsd"
elementFormDefault="qualified" xdb:schemaOwner="XDB" version="1.0" >
<annotation>
<documentation>
This XML schema declares the schema of an XDB resource configuration,
which includes default ACL, event listeners and user configuration.
It lists all XDB repository events that will be supported.
Future extension can be added to support user-defined events and
XML events.
</documentation>
</annotation>
<simpleType name="language">
<restriction base="string">
<enumeration value="Java" />
<enumeration value="C" />
<enumeration value="PL/SQL" />
</restriction>
</simpleType>
<complexType name = "existsNode">
<all>
<element name="XPath" type = "string" minOccurs="1" maxOccurs="1" />
<element name="namespace" type = "string" minOccurs="0" maxOccurs="1" />
</all>
</complexType>
<!-- listener pre-condition element -->
<complexType name = "condition">
<all>
<element name="existsNode" type = "rescfg:existsNode" minOccurs="0" maxOccurs="1" />
</all>
</complexType>
<complexType name = "events">
<all>
<element name="Render" type="string" minOccurs="0" maxOccurs="1"/>
<element name="Pre-Create" type="string" minOccurs="0" maxOccurs="1"/>
<element name="Post-Create" type="string" minOccurs="0" maxOccurs="1"/>
<element name="Pre-Delete" type="string" minOccurs="0" maxOccurs="1"/>
<element name="Post-Delete" type="string" minOccurs="0" maxOccurs="1"/>
<element name="Pre-Update" type="string" minOccurs="0" maxOccurs="1"/>
<element name="Post-Update" type="string" minOccurs="0" maxOccurs="1"/>
<element name="Pre-Lock" type="string" minOccurs="0" maxOccurs="1"/>
<element name="Post-Lock" type="string" minOccurs="0" maxOccurs="1"/>
<element name="Pre-Unlock" type="string" minOccurs="0" maxOccurs="1"/>
<element name="Post-Unlock" type="string" minOccurs="0" maxOccurs="1"/>
<element name="Pre-LinkIn" type="string" minOccurs="0" maxOccurs="1"/>
<element name="Post-LinkIn" type="string" minOccurs="0" maxOccurs="1"/>
<element name="Pre-LinkTo" type="string" minOccurs="0" maxOccurs="1"/>
<element name="Post-LinkTo" type="string" minOccurs="0" maxOccurs="1"/>
<element name="Pre-UnlinkIn" type="string" minOccurs="0" maxOccurs="1"/>
<element name="Post-UnlinkIn" type="string" minOccurs="0" maxOccurs="1"/>
<element name="Pre-UnlinkFrom" type="string" minOccurs="0" maxOccurs="1"/>
<element name="Post-UnlinkFrom" type="string" minOccurs="0" maxOccurs="1"/>
<element name="Pre-CheckIn" type="string" minOccurs="0" maxOccurs="1"/>
<element name="Post-CheckIn" type="string" minOccurs="0" maxOccurs="1"/>
<element name="Pre-CheckOut" type="string" minOccurs="0" maxOccurs="1"/>
<element name="Post-CheckOut" type="string" minOccurs="0" maxOccurs="1"/>
<element name="Pre-UncheckOut" type="string" minOccurs="0" maxOccurs="1"/>
<element name="Post-UncheckOut" type="string" minOccurs="0" maxOccurs="1"/>
<element name="Pre-VersionControl" type="string" minOccurs="0" maxOccurs="1"/>
<element name="Post-VersionControl" type="string" minOccurs="0" maxOccurs="1"/>
<element name="Pre-Open" type="string" minOccurs="0" maxOccurs="1"/>
<element name="Post-Open" type="string" minOccurs="0" maxOccurs="1"/>
<element name="Pre-InconsistentUpdate" type="string" minOccurs="0" maxOccurs="1"/>
<element name="Post-InconsistentUpdate" type="string" minOccurs="0" maxOccurs="1"/>
</all>
</complexType>
<!-- event listener element -->
<complexType name = "event-listener">
<all>
<element name="description" type = "string" minOccurs="0" maxOccurs="1"/>
<element name="schema" type = "string" minOccurs="0" maxOccurs="1"/>
<element name="source" type = "string" minOccurs="1" maxOccurs="1"/>
<element name="language" type = "rescfg:language" minOccurs="0" maxOccurs="1"/>
<element name="pre-condition" type = "rescfg:condition" minOccurs="0" maxOccurs="1"/>
<element name="events" type = "rescfg:events" minOccurs="0" maxOccurs="1"/>
</all>
</complexType>
<complexType name="event-listeners">
<sequence>
<element name="listener" type = "rescfg:event-listener" minOccurs="1" maxOccurs="unbounded"/>
</sequence>
<attribute name = "default-schema" type = "string" xdb:baseProp="true" use="optional"/>
<attribute name = "default-language" type = "rescfg:language" xdb:baseProp="true"
use="optional"/>
<attribute name = "set-invoker" type = "boolean" xdb:baseProp="true" default="false" />
</complexType>
<complexType name="defaultPath">
<all>
<element name="pre-condition" type = "rescfg:condition" minOccurs="0" maxOccurs="1"/>
<element name="path" type="string" minOccurs="0" maxOccurs="1" xdb:transient="generated"/>
<element name = "resolvedpath" type = "string" minOccurs="1" maxOccurs="1"
xdb:baseProp="true" xdb:hidden="true"/>
<element name = "oid" type = "hexBinary" minOccurs="1" maxOccurs="1" xdb:baseProp="true"
xdb:hidden="true"/>
</all>
</complexType>
<complexType name="defaultACL">
<sequence>
<element name="ACL" type="rescfg:defaultPath" minOccurs="1" maxOccurs="unbounded"/>
</sequence>
</complexType>
<complexType name = "defaultConfig">
<sequence>
<element name="configuration" type="rescfg:defaultPath" minOccurs="1" maxOccurs="unbounded"/>
</sequence>
</complexType>
<simpleType name="link-type">
<restriction base="string">
<enumeration value="None"/>
<enumeration value="Hard"/>
<enumeration value="Weak"/>
<enumeration value="Symbolic"/>
</restriction>
</simpleType>
<simpleType name="path-format">
<restriction base="string">
<enumeration value="OID"/>
<enumeration value="Named"/>
</restriction>
</simpleType>
<simpleType name="link-metadata">
<restriction base="string">
<enumeration value="None"/>
<enumeration value="Attributes"/>
<enumeration value="All"/>
</restriction>
</simpleType>
<simpleType name="unresolved-link">
<restriction base="string">
<enumeration value="Error"/>
<enumeration value="SymLink"/>
<enumeration value="Skip"/>
</restriction>
</simpleType>
<simpleType name="conflict-rule">
<restriction base="string">
<enumeration value="Error"/>
<enumeration value="Overwrite"/>
<enumeration value="Syspath"/>
</restriction>
</simpleType>
<simpleType name="section-type">
<restriction base="string">
<enumeration value="None"/>
<enumeration value="Fragment"/>
<enumeration value="Document"/>
</restriction>
</simpleType>
<!-- XLinkConfig complex type -->
<complexType name="xlink-config">
<sequence>
<element name="LinkType" type = "rescfg:link-type"/>
<element name="PathFormat" type = "rescfg:path-format" minOccurs="0" default="OID"/>
<element name="LinkMetadata" type = "rescfg:link-metadata" minOccurs="0" default="None"/>
</sequence>
<attribute name="UnresolvedLink" type = "rescfg:unresolved-link" default="Error"/>
</complexType>
<!-- XIncludeConfig element -->
<complexType name="xinclude-config">
<sequence>
<element name="LinkType" type = "rescfg:link-type"/>
<element name="PathFormat" type = "rescfg:path-format" minOccurs="0" default="OID"/>
<element name="ConflictRule" type = "rescfg:conflict-rule" minOccurs="0" default="Error"/>
</sequence>
<attribute name="UnresolvedLink" type = "rescfg:unresolved-link" default="Error"/>
</complexType>
<!-- SectionConfig element -->
<complexType name="section-config">
<sequence>
<element name="Section" maxOccurs="unbounded">
<complexType>
<sequence>
<element name="sectionPath" type="string"/>
<element name="documentPath" type="string" minOccurs="0"/>
<element name="namespace" type="string" minOccurs="0"/>
</sequence>
<attribute name="type" type="rescfg:section-type" default="None"/>
</complexType>
</element>
</sequence>
</complexType>
<!-- ContentFormat element -->
<simpleType name="content-format" >
<restriction base="string">
<enumeration value="text"/>
<enumeration value="binary"/>
</restriction>
</simpleType>
<!-- resource configuration element -->
<complexType name = "ResConfig">
<all>
<element name="defaultChildConfig" type="rescfg:defaultConfig" minOccurs="0" maxOccurs="1"/>
<element name="defaultChildACL" type="rescfg:defaultACL" minOccurs="0" maxOccurs="1"/>
<element name="event-listeners" type = "rescfg:event-listeners" minOccurs="0" maxOccurs="1"/>
<element name="XLinkConfig" type="rescfg:xlink-config" minOccurs="0" maxOccurs="1"/>
<element name="XIncludeConfig" type="rescfg:xinclude-config" minOccurs="0" maxOccurs="1"/>
<element name="SectionConfig" type="rescfg:section-config" minOccurs="0" maxOccurs="1"/>
<element name="ContentFormat" type="rescfg:content-format" minOccurs="0" maxOccurs="1"/>
<!-- application data -->
<element name="applicationData" minOccurs="0" maxOccurs="1" >
<complexType>
<sequence>
<any namespace="##other" maxOccurs="unbounded" processContents="lax"/>
</sequence>
</complexType>
</element>
</all>
<attribute name = "enable" type = "boolean" xdb:baseProp="true" default="true" />
<attribute name = "copy-on-inconsistent-update" type = "boolean" use="optional" />
</complexType>
<element name="ResConfig" type="rescfg:ResConfig" xdb:defaultTable = "XDB$RESCONFIG" />
</schema>
acl.xsd: XML Schema for ACLs
This section presents the Oracle Database supplied XML schema used to represent access control lists (ACLs).
acl.xsd
<schema xmlns="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://xmlns.oracle.com/xdb/acl.xsd" version="1.0"
xmlns:xdb="http://xmlns.oracle.com/xdb"
xmlns:xdbacl="http://xmlns.oracle.com/xdb/acl.xsd"
elementFormDefault="qualified">
<annotation>
<documentation>
This XML schema describes the structure of XDB ACL documents.
Note : The "systemPrivileges" element below lists all supported
system privileges and their aggregations.
See dav.xsd for description of DAV privileges
Note : The elements and attributes marked "hidden" are for
internal use only.
</documentation>
<appinfo>
<xdb:systemPrivileges>
<xdbacl:all>
<xdbacl:read-properties/>
<xdbacl:read-contents/>
<xdbacl:read-acl/>
<xdbacl:update/>
<xdbacl:link/>
<xdbacl:unlink/>
<xdbacl:unlink-from/>
<xdbacl:write-acl-ref/>
<xdbacl:update-acl/>
<xdbacl:link-to/>
<xdbacl:resolve/>
<xdbacl:write-config/>
</xdbacl:all>
</xdb:systemPrivileges>
</appinfo>
</annotation>
<!-- privilegeNameType (this is an emptycontent type) -->
<complexType name = "privilegeNameType"/>
<!-- privilegeName element
All system and user privileges are in the substitutionGroup
of this element.
-->
<element name = "privilegeName" type="xdbacl:privilegeNameType"
xdb:defaultTable=""/>
<!-- all system privileges in the XDB ACL namespace -->
<element name = "read-properties" type="xdbacl:privilegeNameType"
substitutionGroup="xdbacl:privilegeName" xdb:defaultTable=""/>
<element name = "read-contents" type="xdbacl:privilegeNameType"
substitutionGroup="xdbacl:privilegeName" xdb:defaultTable=""/>
<element name = "read-acl" type="xdbacl:privilegeNameType"
substitutionGroup="xdbacl:privilegeName" xdb:defaultTable=""/>
<element name = "update" type="xdbacl:privilegeNameType"
substitutionGroup="xdbacl:privilegeName" xdb:defaultTable=""/>
<element name = "link" type="xdbacl:privilegeNameType"
substitutionGroup="xdbacl:privilegeName" xdb:defaultTable=""/>
<element name = "unlink" type="xdbacl:privilegeNameType"
substitutionGroup="xdbacl:privilegeName" xdb:defaultTable=""/>
<element name = "unlink-from" type="xdbacl:privilegeNameType"
substitutionGroup="xdbacl:privilegeName" xdb:defaultTable=""/>
<element name = "write-acl-ref" type="xdbacl:privilegeNameType"
substitutionGroup="xdbacl:privilegeName" xdb:defaultTable=""/>
<element name = "update-acl" type="xdbacl:privilegeNameType"
substitutionGroup="xdbacl:privilegeName" xdb:defaultTable=""/>
<element name = "link-to" type="xdbacl:privilegeNameType"
substitutionGroup="xdbacl:privilegeName" xdb:defaultTable=""/>
<element name = "resolve" type="xdbacl:privilegeNameType"
substitutionGroup="xdbacl:privilegeName" xdb:defaultTable=""/>
<element name = "all" type="xdbacl:privilegeNameType"
substitutionGroup="xdbacl:privilegeName" xdb:defaultTable=""/>
<!-- privilege element -->
<element name = "privilege" xdb:defaultTable="">
<complexType>
<sequence>
<any maxOccurs="unbounded" processContents="lax"/>
</sequence>
</complexType>
</element>
<!-- ace element -->
<element name = "ace" xdb:defaultTable="">
<complexType>
<sequence>
<element name = "grant" type = "boolean"/>
<choice>
<element name="invert" xdb:transient="generated">
<complexType>
<sequence>
<element name="principal" type="string"
xdb:transient="generated" />
</sequence>
</complexType>
</element>
<element name="principal" type="string" xdb:transient="generated"/>
</choice>
<element ref="xdbacl:privilege" minOccurs="1"/>
<!-- "any" contain all app info for an ACE e.g.reason for creation -->
<any minOccurs="0" maxOccurs="unbounded" namespace="##other"/>
<!-- HIDDEN ELEMENTS -->
<choice minOccurs="0">
<element name = "principalID" type = "hexBinary"
xdb:baseProp="true" xdb:hidden="true"/>
<element name = "principalString" type = "string"
xdb:baseProp="true" xdb:hidden="true"/>
</choice>
<element name = "flags" type = "unsignedInt" minOccurs="0"
xdb:baseProp="true" xdb:hidden="true"/>
</sequence>
<attribute name = "collection" type = "boolean"
xdb:transient="generated" use="optional"/>
<attribute name = "principalFormat"
xdb:transient="generated" use="optional">
<simpleType>
<restriction base="string">
<enumeration value="ShortName"/>
<enumeration value="DistinguishedName"/>
<enumeration value="GUID"/>
<enumeration value="XSName"/>
</restriction>
</simpleType>
</attribute>
<attribute name = "start_date" type = "dateTime" use = "optional"/>
<attribute name = "end_date" type = "dateTime" use = "optional"/>
</complexType>
</element>
<!-- acl element -->
<complexType name="inheritanceType">
<attribute name="type" type="string" use="required"/>
<attribute name="href" type="string" use="required"/>
</complexType>
<complexType name="aclType">
<sequence>
<element name = "schemaURL" type = "string" minOccurs="0"
xdb:transient="generated"/>
<element name = "elementName" type = "string" minOccurs="0"
xdb:transient="generated"/>
<element name = "security-class" type = "QName" minOccurs="0"/>
<choice minOccurs="0">
<element name="extends-from" type="xdbacl:inheritanceType"/>
<element name="constrained-with" type="xdbacl:inheritanceType"/>
</choice>
<element ref = "xdbacl:ace" minOccurs="1" maxOccurs = "unbounded"/>
<!-- this "any" contains all application specific info for an ACL,
e.g., reason for creation -->
<any minOccurs="0" maxOccurs="unbounded" namespace="##other" />
<!-- HIDDEN ELEMENTS -->
<element name = "schemaOID" type = "hexBinary" minOccurs="0"
xdb:baseProp="true" xdb:hidden="true"/>
<element name = "elementNum" type = "unsignedInt" minOccurs="0"
xdb:baseProp="true" xdb:hidden="true"/>
</sequence>
<attribute name = "shared" type = "boolean" default="true"/>
<attribute name = "description" type = "string"/>
</complexType>
<complexType name="rule-based-acl">
<complexContent>
<extension base="xdbacl:aclType">
<sequence>
<element name = "param" minOccurs="0" maxOccurs="unbounded">
<complexType>
<simpleContent>
<extension base="string">
<attribute name = "name" type = "string" use = "required"/>
</extension>
</simpleContent>
</complexType>
</element>
</sequence>
</extension>
</complexContent>
</complexType>
<element name = "acl" type="xdbacl:aclType" xdb:defaultTable = "XDB$ACL"/>
<element name = "write-config" type="xdbacl:privilegeNameType"
substitutionGroup="xdbacl:privilegeName" xdb:defaultTable=""/>
</schema>Message was edited by:
Marco Gralike -
Do we need a listener class?
I am trying to create a simple page just to display list of values using javaserver faces.I didn't create any application handler and servlet listener class.
Whenever i try to access the page I get this message "The requested resource (/clientList.jsp) is not available." http 404 error.but the file is there
Whether it's compulsary to create application handler and listener class.
any suggestions ?did you maybe forget to specify the /faces/* prefix within the URL?
You have to configure the faces servlet to a prefix path and specify it within your URLs... -
Unable to add the Listener class in project .
Hi friends ,
I'm using deploytool of Sun's AppServer 8.2.
I'm not abel to add the Eventlistener class in the project.
In the Help Menu the given following discription to Add the Event Listener call
Web Application WAR File -> Event Listeners tabbed pane
1. Click Add to add an event listener to the Event Listener Classes list.
Locate any event listener classes contained in this WAR file in the drop-down list in the Event Listener Classes pane.
(note:There is no any drop-down list in in the Event Listener Classes pane.)
2. If the event listener class is not in the list, in the General tab, click Edit and to go to the Edit Contents dialog box where the event listener class can be added to the contents of the WAR file. Upon return the event listener class will be in the pull-down list.
(note:But the listener class is present in General tab ,WEB-INF->classes->listeners(In the Contents of the General tab.))
How could i resolved this , i mean how to add Event Listener Classes in project ?
(Same problem while adding error page and filter classes which are also present in the General tab)
Regards,
Sachin Warang.I suggest using NetBeans IDE 5.5, which integrates easily with various appservers, including Sun Java System Application Server.
-cheng -
Newbe: Redirect from an event listener
We are using WLP 10.
I have created an event listener and I want to redirect the user when the attached event is triggered. I see that the handleEvent function receives a parameter of type Event, which has the session_id as a string parameter. But how do I actually make the redirection using that Event object? Or is there any way to retrieve the request?
I have looked through the documentation and searched for examples but without any luck...
Many thanks,
DanHaving a look at the Interaction documentation for WLP 10, apparently this should be possible. And it should also be possible to have real-time response from the listeners:
Understanding When to Create a Custom Event Listener
http://edocs.bea.com/wlp/docs100/interaction/interaction.html#wp1010357
Extact:
Create a custom event listener if you want to execute functionality not provided by the Campaign listener or the Behavior Tracking listener. For example, if you want to perform your own event data persistence, modify a User Profile, redirect the user to another part of a Page Flow, or provide any other type of real-time response to the event, create a custom event listener that provides the functionality you want. -
Error occured in invoking event "contextInitialized()" on listener class co
Hi All,
I am working on JSF 1.2 on SAP NetWeaver CE. I am able to execute sample JSF application successfully when NO java program is written in the application. When I write a java program inside the JSF application...I am getting following error. Please let me know how to proceed on this:
"Application error occurred during the request procession."
Error occured in invoking event "contextInitialized()" on listener class com.sun.faces.config.ConfigureListener.
Details:
java.lang.UnsupportedClassVersionError: Bad version number in .class file
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:654)
at com.sap.engine.boot.loader.ResourceMultiParentClassLoader.loadClassLocal(ResourceMultiParentClassLoader.java:198)
at com.sap.engine.boot.loader.MultiParentClassLoader.findClassInLoaderGraph(MultiParentClassLoader.java:302)
at com.sap.engine.boot.loader.MultiParentClassLoader.loadClass(MultiParentClassLoader.java:256)
at com.sap.engine.boot.loader.MultiParentClassLoader.loadClass(MultiParentClassLoader.java:228)
at com.sun.faces.config.ManagedBeanFactoryImpl.getManagedBeanClass(ManagedBeanFactoryImpl.java:227)
at com.sun.faces.config.ManagedBeanFactoryImpl.scanForAnnotations(ManagedBeanFactoryImpl.java:1130)
at com.sun.faces.config.ManagedBeanFactoryImpl.<init>(ManagedBeanFactoryImpl.java:156)
at com.sun.faces.config.ConfigureListener.configure(ConfigureListener.java:926)
at com.sun.faces.config.ConfigureListener.configure(ConfigureListener.java:507)
at com.sun.faces.config.ConfigureListener.contextInitialized(ConfigureListener.java:402)
at com.sap.engine.services.servlets_jsp.server.application.WebEvents.contextInitialized(WebEvents.java:74)
at com.sap.engine.services.servlets_jsp.server.deploy.ApplicationThreadInitializer.run(ApplicationThreadInitializer.java:198)
at com.sap.engine.core.thread.impl3.ActionObject.run(ActionObject.java:37)
at java.security.AccessController.doPrivileged(Native Method)
at com.sap.engine.core.thread.impl3.SingleThread.execute(SingleThread.java:152)
at com.sap.engine.core.thread.impl3.SingleThread.run(SingleThread.java:247)
Rgds,
PathanPathan wrote:
java.lang.UnsupportedClassVersionError: Bad version number in .class fileThe Java version of the Java compiler used is newer than the Java version of the Java runtime used.
E.g. compiling with JDK 1.6 and running with JRE 1.5 would cause this error. -
Adding an event listener to combo box
I am working on a mortgage calculator and I cannot figure out how to add an event listener to a combo box.
I want to get the mortgage term and interest rate to calucate the mortgage using the combo cox. Here is my program.
Modify the mortgage program to allow the user to input the amount of a mortgage
and then select from a menu of mortgage loans: 7 year at 5.35%, 15 year at 5.50%, and
30 year at 5.75%. Use an array for the different loans. Display the mortgage payment
amount. Then, list the loan balance and interest paid for each payment over the term
of the loan. Allow the user to loop back and enter a new amount and make a new
selection, with resulting new values. Allow user to exit if running as an application
(can't do that for an applet though).
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.event.*;
import java.text.NumberFormat;
import java.util.Locale;
//creates class MortgageCalculator
public class MortgageCalculator extends JFrame implements ActionListener {
//creates title for calculator
JPanel row = new JPanel();
JLabel mortgageCalculator = new JLabel("MORTGAGE CALCULATOR", JLabel.CENTER);
//creates labels and text fields for amount entered
JPanel firstRow = new JPanel(new GridLayout(3,1,1,1));
JLabel mortgageLabel = new JLabel("Mortgage Payment $", JLabel.LEFT);
JTextField mortgageAmount = new JTextField(10);
JPanel secondRow = new JPanel();
JLabel termLabel = new JLabel("Mortgage Term/Interest Rate", JLabel.LEFT);
String[] term = {"7", "15", "30"};
JComboBox mortgageTerm = new JComboBox(term);
JPanel thirdRow = new JPanel();
JLabel interestLabel = new JLabel("Interest Rate (%)", JLabel.LEFT);
String[] interest = {"5.35", "5.50", "5.75"};
JComboBox interestRate = new JComboBox(interest);
JPanel fourthRow = new JPanel(new GridLayout(3, 2, 10, 10));
JLabel paymentLabel = new JLabel("Monthly Payment $", JLabel.LEFT);
JTextField monthlyPayment = new JTextField(10);
//create buttons to calculate payment and clear fields
JPanel fifthRow = new JPanel(new GridLayout(3, 2, 1, 1));
JButton calculateButton = new JButton("CALCULATE PAYMENT");
JButton clearButton = new JButton("CLEAR");
JButton exitButton = new JButton("EXIT");
//Display area
JPanel sixthRow = new JPanel(new GridLayout(2, 2, 10, 10));
JLabel displayArea = new JLabel(" ", JLabel.LEFT);
JTextArea textarea = new JTextArea(" ", 8, 50);
public MortgageCalculator() {
super("Mortgage Calculator"); //title of frame
setSize(550, 350); //size of frame
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Container pane = getContentPane();
GridLayout grid = new GridLayout(7, 3, 10, 10);
pane.setLayout(grid);
pane.add(row);
pane.add(mortgageCalculator);
pane.add(firstRow);
pane.add(mortgageLabel);
pane.add(mortgageAmount);
pane.add(secondRow);
pane.add(termLabel);
pane.add(mortgageTerm);
pane.add(thirdRow);
pane.add(interestLabel);
pane.add(interestRate);
pane.add(fourthRow);
pane.add(paymentLabel);
pane.add(monthlyPayment);
monthlyPayment.setEnabled(false);
pane.add(fifthRow);
pane.add(calculateButton);
pane.add(clearButton);
pane.add(exitButton);
pane.add(sixthRow);
pane.add(textarea); //adds texaarea to frame
pane.add(displayArea);
setContentPane(pane);
setVisible(true);
//Adds Listener to buttons
calculateButton.addActionListener(this);
clearButton.addActionListener(this);
exitButton.addActionListener(this);
mortgageTerm.addActionListener(this);
interestRate.addActionListener(this);
public void actionPerformed(ActionEvent event) {
Object command = event.getSource();
JComboBox mortgageTerm = (JComboBox)event.getSource();
String termYear = (String)mortgageTerm.getSelectedItem();
if (command == calculateButton) //calculates mortgage payment
int year = Integer.parseInt(mortgageTerm.getText());
double rate = new Double(interestRate.getText()).doubleValue();
double mortgage = new Double(mortgageAmount.getText()).doubleValue();
double interest = rate /100.0 / 12.0;
double monthly = mortgage *(interest/(1-Math.pow(interest+1,-12.0 * year)));
NumberFormat myCurrencyFormatter;
myCurrencyFormatter = NumberFormat.getCurrencyInstance(Locale.US);
monthlyPayment.setText(myCurrencyFormatter.format(monthly));
if(command == clearButton) //clears all text fields
mortgageAmount.setText(null);
//mortgageTerm.setText(null);
//interestRate.setText(null);
monthlyPayment.setText(null);
if(command == exitButton) //sets exit button
System.exit(0);
public static void main(String[] arguments) {
MortgageCalculator mor = new MortgageCalculator();The OP already did this to both JComboBoxes.
mochatay, here is a new actionPerformed method for you to use.
I've improved a few things here and there...
1) You can't just cast the ActionEvent's source into a JComboBox!
What if it was a JButton that fired the event? Then you would get ClassCastExceptions (I'm sure you did)
So check for all options, what the source of the ActionEvent actually was...
2) You can't assume the user will always type in valid data.
So enclose the Integer and Double parse methods in try-catch brakcets.
Then you can do something when you know that the user has entered invalid input
(like tell him/her what a clumsy idiot they are !)
3) As soon as user presses an item in any JComboBox, just re-calculate.
I did this here by programmatically clicking the 'Calculate' button.
Alternatively, you could have a 'calculate' method, which does everything inside the
if(command==calculateButton) if-block.
This will be called when:
a)calculateButton is pressed
b)when either of the JComboBoxes are pressed.
public void actionPerformed (ActionEvent event)
Object command = event.getSource ();
if (command == calculateButton) //calculates mortgage payment
int year = 0;
double rate = 0;
double mortgage = 0;
double interest = 0;
/* If user has input invalid data, tell him so
and return (Exit from this method back to where we were before */
try
year = Integer.parseInt (mortgageTerm.getSelectedItem ().toString ());
rate = new Double (interestRate.getSelectedItem ().toString ()).doubleValue ();
mortgage = new Double (mortgageAmount.getText ()).doubleValue ();
interest = rate / 100.0 / 12.0;
catch (NumberFormatException nfe)
/* Display a message Dialogue box with a message */
JOptionPane.showMessageDialog (this, "Error! Invalid input!");
return;
double monthly = mortgage * (interest / (1 - Math.pow (interest + 1, -12.0 * year)));
NumberFormat myCurrencyFormatter;
myCurrencyFormatter = NumberFormat.getCurrencyInstance (Locale.US);
monthlyPayment.setText (myCurrencyFormatter.format (monthly));
else if (command == clearButton) //clears all text fields
/* Better than setting it to null (I think) */
mortgageAmount.setText ("");
//mortgageTerm.setText(null);
//interestRate.setText(null);
monthlyPayment.setText ("");
else if (command == exitButton) //sets exit button
System.exit (0);
else if (command == mortgageTerm)
/* Programmatically 'clicks' the button,
As is user had clicked it */
calculateButton.doClick ();
else if (command == interestRate)
calculateButton.doClick ();
//JComboBox mortgageTerm = (JComboBox) event.getSource ();
//String termYear = (String) mortgageTerm.getSelectedItem ();
}Hope this solves your problems.
I also hope you'll be able to learn from what I've indicated, so you can use similar things yourself
in future!
Regards,
lutha -
Help regarding event flow/event listening best practices
Hi, I'm making a flash memory card game to learn more about
to actionscript.
I have:
- a main class that loads on start. This class instantiates
a:
- CardLoader class that imports graphical assets and uses
these to create all my cards:
- Card class that represents individual card. Can dispatch
CardEvent when clicked:
- CardEvent contains info on the Card that dispatched it,
such as the cards ID number and the ID of it's matching card.
What I want to do is to have another object to act as a game
logic handler.
Example:
- Card 1 was clicked, dispatches CardEvent that ends up with
the LogicHandler.
- Card 2 was clicked and also dispatches event.
LogicHandler compares these two cards and does the
appropriate thing depending on they being a match or not.
Now, the big questions is, how do I get this event to the
LogicHandler?
My custom CardEvent has it's bubbles property set to true.
So, I can manage to get such an event all the way back to my main
class, in this order: CardEvent > Card > CardLoader >
Main.
The problem arises when I want to have my LogicHandler class
created by Main. When my CardEvent bubbles back, it does not go
through this LogicHandler since it is not part of the event flow on
it's way back.
Questions: How do I, following the best possible programming
practises, send the event the way I want it to go?
I can only think of one solution myself, being that inside my
Main method I set up an eventlistener that listens for this event
and passes it on downwards, in this case to the LogicHandler. Sure,
it's only a few lines of code in the main method, but what if you
have 50 different events in a larger project that needs the same
treatment?
Your main method will be a mess by then!
How would you do it?Ok let me see if I get this straight:
In my example, I would have to pass a reference of the
LogicHandler to my Card class.
In my Card class, I have something like:
logicHandler.addDispatcher(this);
this being the Card of course.
Inside LogicHandler class I have the addDispatcher method
that calls the addEventListener method.
So far so good?
The addDispatcher method adds an eventlistener to the Card
object, from what I can tell. But it does it inside the
LogicHandler, thus the method that is called by the
addEventListener can be inside the LogicHandler?
To put it in other words, what's confusing me is that the
Listener object adds an EventListener to the dispatching object.
Logically for me the listener should add a listener to itself?
The way I first did it in my Card class was:
testevent = new CardEvent(CardEvent.CLICK);
dispatchEvent(testevent);
And then set up the EventListener in the object that I wanted
to receive the event.
I'm sorry I don't understand this, despite your obviously
good explanations (I think I understand a lot more now, just not
the best approach). I will look into the callback functions, sounds
a lot interesting as well -
URGENT : EVENT Listener Problem
Hi All,
Thanks for your time. I am facing a Small issue with Event
dispatcher and Add Event listener. Well i will explain the problem.
I am having one MovieClip named BUTTON_SET and i gave
"ButtonSet.as" as linkage Class.
Inside that BUTTON_SET i am having some Buttons and they are
also having "UIButton.as" as linkage class
UIButton Dispatching press and release events, But unable to
capture it using ButtonSet Class. Here with i have attached the
Code and i gave the Source URL Too.
upto my Knowledge : UIButton class is not initiated When the
ButtonSet is ready to addListener.
Please Help me to fix this.
if i don't find a solution i need to change all my class
structures.
CLICK HERE FOR SOURCE
CODEAccording to your Code, When you are calling the InitHandler
Functionction the Buttons may/may not be Initiated. So use the
Enterframe to check whether its loaded or not.
Write down this in the ButtonSet to replace the init Handler
Call.
this.onEnterFrame = Delegate.create(this, initHandler);
inside the initHandler remove the function This will help you
if you are not using any Enterframe for any other manipulation)
delete this.onEnterFrame; -
Event Listener dispatcher giving an ClassCast Exception in C++ 3.6.1
Hi,
I have attached a Event listener to underlying NamedCache and when I update the cache entry I didn't get any alerts. But When I checked the
coherence log I found following Exception available. But I'm not doing any sort of Casting as mentioned below.
2012-01-17 11:12:55.793/0.320 Oracle Coherence for C++ RTC 3.6.1.0 <Info> (thread=main): Connected Socket to 169.52.37.237/169.52.37.237:9099
2012-01-17 11:13:04.859/9.386 Oracle Coherence for C++ RTC 3.6.1.0 <Error> (thread=ExtendTcpCacheService:coherence::component::util::TcpInitiator:coherence::component::util::Service::EventDispatcher): An exception occurred while dispatching the following event:
coherence::component::util::RunnableCacheEvent: coherence::util::MapListenerSupport::FilterEvent{coherence::component::net::extend::RemoteNamedCache::BinaryCache[source=coherence::component::net::extend::RemoteNamedCache::BinaryCache@0x69f090c4] updated: key=Binary(length=19), old value=Binary(length=713), new value=Binary(length=713), filters=[NULL]}
2012-01-17 11:13:04.860/9.387 Oracle Coherence for C++ RTC 3.6.1.0 <Error> (thread=ExtendTcpCacheService:coherence::component::util::TcpInitiator:coherence::component::util::Service::EventDispatcher): The following exception was caught by the event dispatcher:
2012-01-17 11:13:04.860/9.387 Oracle Coherence for C++ RTC 3.6.1.0 <Error> (thread=ExtendTcpCacheService:coherence::component::util::TcpInitiator:coherence::component::util::Service::EventDispatcher): NULL
coherence::lang::ClassCastException: attempt to cast from a "gce::coherence::CoherenceEventHandler" to a "coherence::util::MapListener" at void coherence::lang::coh_throw_class_cast(const std::type_info&, const std::type_info&)(ClassCastException.cpp:27)
at coherence::lang::coh_throw_class_cast(std::type_info const&, std::type_info const&)
at coherence::lang::TypedHandle<coherence::util::MapListener> coherence::lang::cast<coherence::lang::TypedHandle<coherence::util::MapListener>, coherence::lang::Object>(coherence::lang::TypedHandle<coherence::lang::Object> const&, bool)
at coherence::lang::TypedHandle<coherence::util::MapListener> coherence::lang::cast<coherence::lang::TypedHandle<coherence::util::MapListener>, coherence::lang::Object>(coherence::lang::TypedHolder<coherence::lang::Object> const&, bool)
at coherence::lang::TypedHandle<coherence::util::MapListener> coherence::lang::cast<coherence::lang::TypedHandle<coherence::util::MapListener>, coherence::lang::Object>(coherence::lang::MemberHolder<coherence::lang::Object> const&, bool)
When I wrote a sample application It works without any problem. Only difference of above exception coming program is this c++ library is loaded true JNI and relevant event listener is added during a JNI method call. Please explain me why this exception is coming. I have attached the relevant code as well.
CoherenceEventListener.hpp
* File: CoherenceEventHandler.hpp
* Author: srathna1
* Created on 05 January 2012, 10:15
#ifndef COHERENCEEVENTHANDLER_HPP
#define COHERENCEEVENTHANDLER_HPP
#include "coherence/util/MapEvent.hpp"
#include "coherence/util/MapListener.hpp"
#include <iostream>
//#include <map>
#include "coherence/lang.ns"
#include "mihelper.hpp"
#include "MiCoherence.hpp"
#include <string>
#include "MICoherenceDataObject.hpp"
using coherence::util::MapEvent;
using coherence::util::MapListener;
using namespace coherence::lang;
* A MapListener implementation that prints each event as it receives
* them.
namespace gce {
namespace coherence {
class CoherenceEventHandler
: public class_spec<CoherenceEventHandler,
extends<Object>,
implements<MapListener> > {
friend class factory<CoherenceEventHandler>;
public:
CoherenceEventHandler(CMiCoherence * miCoh) : mi(miCoh), msgSeqNo(1) {
virtual void entryInserted(MapEvent::View vEvent) {
Object::View vKey = vEvent->getKey();
String::View key = cast<String::View > (vKey);
Object::View vValue = vEvent->getNewValue();
char topic[100];
strcpy(topic, key->getCString());
Managed<gce::coherence::MICoherenceDataObject>::View pos = cast<Managed<gce::coherence::MICoherenceDataObject>::View > (vValue);
std::cout << key << " = " << pos << std::endl;
virtual void entryUpdated(MapEvent::View vEvent) {
Object::View vKey = vEvent->getKey();
String::View key = cast<String::View > (vKey);
Object::View vValue = vEvent->getNewValue();
char topic[100];
strcpy(topic, key->getCString());
Managed<gce::coherence::MICoherenceDataObject>::View pos = cast<Managed<gce::coherence::MICoherenceDataObject>::View > (vValue);
std::cout << key << " = " << pos << std::endl;
gce::coherence::MICoherenceDataObject msg = *pos;
virtual void entryDeleted(MapEvent::View vEvent) {
private:
CMiCoherence * mi;
int msgSeqNo;
#endif /* COHERENCEEVENTHANDLER_HPP */
Event Registration code
NamedCache::Handle miCoherenceCache = NULL;
try {
String::View cacheName = szConnect;
miCoherenceCache = CacheFactory::getCache(cacheName);
} catch (const std::exception& e) {
LOGERR("initializing coherence middleware cache error: %s", e.what());
return MI_ERR_BADSTATE;
nConnectState = miCoherenceCache->getCacheService()->isRunning() == true ? 1 : 0;
miCoherenceCache->addFilterListener(gce::coherence::CoherenceEventHandler::create(this));
Please give me a clue why Cohrence Internal Event Dispatcher giving exception.....
Thanks and regards,
SuraHi,
Even when I try to to test the MemberListener while closing the Coherene Java Cache Cluster I can see following Exception. Something similar to EventListener.
2012-01-18 20:06:18.868/44.346 Oracle Coherence for C++ RTC 3.6.1.0 <Error> (thread=ExtendTcpCacheService:coherence::component::util::TcpInitiator:coherence::component::util::Service::EventDispatcher): The following exception was caught by the event dispatcher:
2012-01-18 20:06:18.868/44.346 Oracle Coherence for C++ RTC 3.6.1.0 <Error> (thread=ExtendTcpCacheService:coherence::component::util::TcpInitiator:coherence::component::util::Service::EventDispatcher): NULL
coherence::lang::ClassCastException: attempt to cast from a "gce::coherence::CoherenceMemberListener" to a "coherence::net::MemberListener"
at void coherence::lang::coh_throw_class_cast(const std::type_info&, const std::type_info&)(ClassCastException.cpp:27)
at coherence::lang::coh_throw_class_cast(std::type_info const&, std::type_info const&)
at coherence::lang::TypedHandle<coherence::net::MemberListener> coherence::lang::cast<coherence::lang::TypedHandle<coherence::net::MemberListener>, coherence::lang::Object>(coherence::lang::TypedHandle<coherence::lang::Object> const&, bool)
at coherence::lang::TypedHandle<coherence::net::MemberListener> coherence::lang::cast<coherence::lang::TypedHandle<coherence::net::MemberListener>, coherence::lang::Object>(coherence::lang::TypedHolder<coherence::lang::Object> const&, bool)
at coherence::lang::TypedHandle<coherence::net::MemberListener> coherence::lang::cast<coherence::lang::TypedHandle<coherence::net::MemberListener>, coherence::lang::Object>(coherence::lang::MemberHolder<coherence::lang::Object> const&, bool)
at coherence::net::MemberEvent::dispatch(coherence::lang::TypedHandle<coherence::util::Listeners const>) const
at coherence::component::util::ListenerCallback::translateMemberEvent(coherence::lang::TypedHandle<coherence::net::MemberEvent const>)
at coherence::component::util::ListenerCallback::memberLeaving(coherence::lang::TypedHandle<coherence::net::MemberEvent const>)
at coherence::net::MemberEvent::dispatch(coherence::lang::TypedHandle<coherence::util::Listeners const>) const
at coherence::component::net::extend::RemoteService::dispatchMemberEvent(coherence::net::MemberEvent::Id)
at coherence::component::net::extend::RemoteService::connectionError(coherence::lang::TypedHandle<coherence::net::messaging::ConnectionEvent const>)
at coherence::component::net::extend::RemoteCacheService::connectionError(coherence::lang::TypedHandle<coherence::net::messaging::ConnectionEvent const>)
at coherence::net::messaging::ConnectionEvent::dispatch(coherence::lang::TypedHandle<coherence::util::Listeners const>) const
at coherence::component::util::Peer::DispatchEvent::run()
at coherence::component::util::Service::EventDispatcher::onNotify()
at coherence::component::util::Daemon::run()
at coherence::lang::Thread::run()
on thread "ExtendTcpCacheService:coherence::component::util::TcpInitiator:coherence::component::util::Service::EventDispatcher"
Seems to be like loading with JNI will giving some exceptions.
Please help me on this...
Thanks and regards,
Sura -
Extended Canvas, Event Listener - drag enter
I'm trying to add an eventListener to my extended Canvas
Class but seem to be having a slight problem.
I've created a loop which runs 16 times, adds an instance of
the canvas to a container and sets an drag enter event listener for
each one, however when i drag over only one of the canvas' reacts
to the drag enter (the last instance) - regardless of where i drag
the object.
heres some example code
for(var i = 0; i < 16;i++)
var foo:extendedCanvasObj = new extendedCanvasObj();
foo.setstyle.......
foo.addEventListener(dragEvent.DRAG_ENTER,function(event:DragEvent){
change the canvas backgroundcolour };
container.addChild(foo);
}Thanks for the quick reply,
I understand what you mean, but how would i stop it from doing this? I want the "new boxes" to know when a drag proxy has entered them but i don't want them to accept a drop.
Basically i'm building a form builder and the boxes represent fields. I want them to know when the proxy has just enter them to i can perform a collision detection and move them to create space to drop the new field.
Tom -
JTabbedPane single event handling class.
I have a list of proxyNames which are stored in a Vector.
These proxy names are then displayed as Tabs accordingly.
For every tab there is a specific action to be performed.
I want to write a single event handling class for handling all events.
What I have is this:
while(eNum.hasMoreElements()){
Object proxyName = eNum.nextElement();
tabbedPane.addTab(proxyName.toString(), null, null, "Proxy");
tabbedPane.addChangeListener(itemHandler);
panel4.add(tabbedPane2);
class ItemHandler implements ChangeListener{
public void stateChanged(ChangeEvent e){
for(int i=0; i < v.size(); i++){
// Perform action on choosing the concerned tab...
How do I have a single event listener?Yikes! Is that a minimal program? When I am trying to do something new, or facing a problem that causes me to get stuck for more than an hour, I create a short program to solve just that problem. In time, you create a directory of test programs that's useful, and with practice, solving a problem in isolation is a faster (and generally better) way to go about things that doing it all in a larger application.
Any way, here is your code, with a change listener added in method makeSubpanel. If you don't want the listener called the very first time, add it at the end of this method. I also fixed some bugs in createProxyList.
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.util.*;
import javax.swing.*;
import javax.swing.event.*;
public class TrialTabbed extends JPanel {
// Will hold all file names read from the /config directory.
private Vector v,v1;
JTabbedPane tabbedPane,tabbedPane2;
Object proxyName;
public TrialTabbed(){
tabbedPane = new JTabbedPane();
// Instantiate the Vector.
v1 = new Vector();
Component panel1 = makeTextPanel("Blah");
tabbedPane.addTab("Debug Mode", null, panel1, "Debug");
Component panel2 = makeSubPanel();
tabbedPane.addTab("Normal Mode", null, panel2, "Normal");
// Add the tabbed pane to this panel.
setLayout(new GridLayout(1, 1));
add(tabbedPane);
protected Component makeTextPanel(String text) {
JPanel panel = new JPanel(false);
JLabel filler = new JLabel(text);
filler.setHorizontalAlignment(JLabel.CENTER);
panel.setLayout(new GridLayout(1, 1));
panel.add(filler);
return panel;
private Component makeSubPanel(){
JPanel panel4 = new JPanel(false);
panel4.setLayout(new GridLayout(1, 1));
tabbedPane2 = new JTabbedPane();
//new code - a change listener for pane2
tabbedPane2.addChangeListener(new ChangeListener(){
public void stateChanged(ChangeEvent e){
int tab = tabbedPane2.getSelectedIndex();
if (tab == -1)
System.out.println("no tab selected");
else {
String filename = tabbedPane2.getTitleAt(tab);
File file = new File("..", filename); //brittle!
if (file.isDirectory()) {
String[] contents = file.list();
int size = contents == null ? 0 : contents.length;
System.out.println(filename + " contains " + size + " files");
} else
System.out.println(filename + " has length " + file.length());
//end of new code
ItemHandler itemHandler = new ItemHandler();
v = createProxyList();
// Enumerate thru the Vector and put them as tab names.
Enumeration eNum = v.elements();
while(eNum.hasMoreElements()){
proxyName = eNum.nextElement();
tabbedPane2.addTab(proxyName.toString(), null, null, "Proxy");
panel4.add(tabbedPane2);
return panel4;
// Display the file names in this directory as tab Names.
//new code: changed dirName to "..", fixed some obvious bugd
private Vector createProxyList(){
String dirName = "..";
File file = new File(dirName);
if(file.isDirectory()){
String[] s = file.list();
for(int i=0; i< s.length; i++){
v1.addElement(s);
} // End for.
} // End of if.
return v1;
} // End createProxyList().
class ItemHandler implements ChangeListener{
public void stateChanged(ChangeEvent e){
System.out.println(v.size());
System.out.println("IN CHANGE LISETENER" + proxyName.toString());
} // End actionPerformed.
} // End Inner class ItemHandler.
public static void main(String[] args) {
JFrame frame = new JFrame("TabbedPaneDemo");
frame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {System.exit(0);}
frame.getContentPane().add(new TrialTabbed(),BorderLayout.CENTER);
frame.setSize(500, 425);
frame.setVisible(true); -
Query regarding creating a Custom Event and Firing.
I have created a custom event,a custom listener and a custom button.
But when I click on custom button,my event is not being fired.
When and how do I need to invoke the fireEvent() ?
Please can any body tell me if I have overlooked any thing ?
Thanks,
// 1 Custom Event
import java.util.EventObject;
public class MyActionEvent extends EventObject{
public MyActionEvent(Object arg0) {
super(arg0);
// 2 Custom Listener
import java.util.EventListener;
public interface MyActionListener extends EventListener {
public void myActionPerformed(MyActionEvent myEvent);
// 3 Custom Button
public class MyButton extends JButton {
// Create the listener list
protected javax.swing.event.EventListenerList listenerList = new javax.swing.event.EventListenerList();
public MyButton(String str){
super(str);
public void addMyActionEventListener(MyActionListener listener) {
listenerList.add(MyActionListener.class, listener);
protected void fireMyActionEvent() {
MyActionEvent evt = new MyActionEvent(this);
Object[] listeners = listenerList.getListenerList();
for (int i = 0; i < listeners.length; i = i+2) {
if (listeners[i] == MyActionListener.class) {
((MyActionListener) listeners[i+1]).myActionPerformed(evt);
} // end of class MyButton.
// 4 Test my Custom Event,Listener and Button
public class MyButtonDemo extends JPanel {
protected MyButton b1;
public MyButtonDemo() {
b1 = new MyButton("Disable Button");
b1.setToolTipText("Click this button to disable the middle button.");
b1.addMyActionEventListener(new MyActionListener() {
@Override
public void myActionPerformed(MyActionEvent myEvent) {
System.out.println("My ActionEvent....");
add(b1);
private static void createAndShowGUI() {
JFrame frame = new JFrame("ButtonDemo");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
MyButtonDemo newContentPane = new MyButtonDemo();
newContentPane.setOpaque(true);
frame.setContentPane(newContentPane);
//Display the window.
frame.pack();
frame.setVisible(true);
public static void main(String[] args) {
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
createAndShowGUI();
}Hi Stan,
I would like to use my custom action listener rather that using the the normal actionPerformed(ActionEvent e)
But some how this event is not being fired.
Any suggestions to fire this?
b1.addMyActionEventListener(new MyActionListener() {
@Override
public void myActionPerformed(MyActionEvent myEvent) {
System.out.println("My ActionEvent triggered....");
}); -
Passing a string as the name of a Mouse Event Listener function?
Hello,
I am trying to essentially pass a string as a function name into an event listener, but I am not sure how to approach this. Is there a way to convert a string into a function? I am not sure how to word my question, so I apologize.
Here is some code I have for me to show you what I am doing.
package{
//some import statements
public class changes extends MovieClip{
var functionName:String
var aBox:Sprite;
public function changes(){
functionName = "testThis";
createButtonBox(16, 16, 32, 32, functionName);
public function createButtonBox(anX:Number, aY:Number, aWidth:Number, aHeight:Number, aFunction:String){
aBox = new Sprite();
//Some drawing box code
aBox.addEventListener(MouseEvent.CLICK,[aFunction]()?)
addChild(aBox)
public function aFunction(event:MouseEvent){
trace("test");
Am I on the right track or is this not possible?
Anyhow, thank you in advance.I guess I misworded my question. Essentially what I am trying to do is create buttons that have functions called to from an event listener, referenced by a string like this:
public class Document{
var functionName:String;
public function Document(){
createAButton("Test Button A", 32, 32, "testThis");
createAButton("Test Button B", 64, 64, "testThis2");
public function createAButton(textOnButton:String, anX:Number, aY:Number, functionToCallTo:String){
var aButton:Sprite = new Sprite();
//draw the button
//set a textfieldup for the button to have
aButton.addEventListener(MouseEvent.CLICK, functionToCallTo)
public function testThis(event:MouseEvent){
trace("testA");
public function testThis2(event:MouseEvent){
trace("testB");
Unfortunately aButton.addEventListener(MouseEvent.CLICK, functionToCallTo) gives me a coercian error, which is a given.
aButton.addEventListener(MouseEvent.CLICK, [functionToCallTo]()) gives me TypeError: Error #1006: value is not a function.
I mean I could create a bunch of if statements, but for the number of functions I plan to call to, like about 25 or so, that is pretty tedious.
Maybe you are looking for
-
Suddenly LED 24" Arrangement broken, only get 640 x 480 resolution
Yesterday, did a SuperDuper backup instructing "when finished shut down." This morning I fired up my MacBook Pro and the LED 24" and the latter will only display 640 X 480 resolution (very big with jaggies). Also the prior arrangement setting is gone
-
For my work I need to deliver all Adresses (groupwise) in an Excell file. Furthermore I need to put the Billing number (I strategically placed in the "note" section) to be visible Yes, I am a Apple apprentice and would like some help iBook G4 Mac O
-
hi i am putting photos in my project it will play the videos but not the photos i have not had a problem with this before
-
Hi Experts, Whenever any network issues or something happens so that connection between client and Oracle server has lost. Can that information store in client sqlnet.log file or do need to set some settings so that it'll write into sqlnet.log. Why i
-
Mac OS X could not be installed in your computer - Install failed
Wasup.. I have a macbook pro 13" (latest version) on mac os x 10.6.5 I was trying to reinstall the mac os x and I can't !! Here is the log file: http://img818.imageshack.us/i/erro1r.jpg/ The error appears in the beginning of the installation: http://