| Constructors + Information Hiding |
|
 |
Index ‹ java-programmer
|
- Previous
- 3
- AWT -> Swing, blocked dispatch thread
Ok, so I'm finally modernizing my code and switching everything from AWT
to Swing. I keep getting errors like the one below. What might I be
doing that would be blocking the event dispatch thread? Or maybe I'm
doing something else? Is there some common noob mistake that causes
this?
Thanks.
Event
java.awt.event.MouseEvent[MOUSE_PRESSED,(17,93),mods=16,clickCount=1] on
frame0 not handled after 30 seconds. Are you blocking the event
dispatch thread?
java.lang.Exception: Stack trace
at java.lang.Thread.dumpStack(Thread.java:1004)
at
com.apple.mrj.internal.awt.basepeers.EventHandlingComponentPeer.pumaWorka
roundPostEvent(EventHandlingComponentPeer.java:931)
at
com.apple.mrj.internal.awt.basepeers.EventHandlingComponentPeer.mousePres
sed(EventHandlingComponentPeer.java:680)
at
com.apple.mrj.internal.awt.frames.SimpleFramePeer.handleClick(SimpleFrame
Peer.java:1729)
at
com.apple.mrj.internal.awt.framehosts.CarbonWindowFrameHost.handleClick(C
arbonWindowFrameHost.java:1113)
at
com.apple.mrj.internal.awt.framehosts.CarbonWindowFrameHost.handleClickCo
ntentRgn(CarbonWindowFrameHost.java:1073)
at
com.apple.buckyball.app.WindowEventHandler.handleEvent(WindowEventHandler
.java:101)
at
com.apple.buckyball.app.EventHandler$Adapter.EventHandler(EventHandler.ja
va:248)
--
Please take off your shoes before arriving at my in-box.
I will not, no matter how "good" the deal, patronise any business which sends
unsolicited commercial e-mail or that advertises in discussion newsgroups.
- 3
- 3
- Typing number from idle screenHi All,
Can anyone give me a sample code in J2ME how to bring a screen such
that you can type in numbers in the idle screen to make a call?
- 5
- JWS app does not update.Hi,
I'm familiar with the rules for JWS automatics updates, but my machine
doesn't seem to follow those rules and the application is frequently
stale (even when redeployed off the web).
What could be the cause of this?
For example, does one need to restart one's browser?
Restart one's computer?
Clear out temporary files?
Thanks!
Aaron Fude
- 7
- shrinkwrap JavaRoedy Green <email***@***.com> wrote or quoted:
> Java detractors seem to think Java is unsuited for writing anything
> visually complex.
>
> Take a peak at this stock market app. I think the authors went
> overboard with complexity, but it shows you what is possible and just
> how fast rendering can be. My guess is they use clipregions for
> re-rendering just two tall slivers to get that speed.
>
> http://www.downloadquotes.com/en/applet.phtml?key=Demo&id=3097
It's not exactly doing very much.
Give me http://www.ibiblio.org/lifepatterns/ any day ;-)
--
__________
|im |yler http://timtyler.org/ email***@***.com Remove lock to reply.
- 8
- any easy way to write out a XML DOM object to file?Hello!
I am using Document and DOM to hold a XML file, and make some changes
to the Document. After that, I just wonder is there any easy way to
write the modified XML file back to disk? (loop all the nodes and
print them out is one way of course, any other better way?)
The piece of node is:
String filename="mytest.xml";
DocumentBuilderFactory factory =
DocumentBuilderFactory.newInstance();
// Create the builder and parse the file
Document doc = factory.newDocumentBuilder().parse(new
File(filename));
// changes the doc, add, edit nodes, etc.
Now, I want to get the updated xml file from "doc", what to do?
Anything like doc.writeAsXMLFile("newFile.xml")?
Thanks and happy holiday. :-)
- 11
- HELP!! Iam new in JAVAI am geting this error in JGRASP:
Lab01.java:2: package edu.pace does not exist
How do I fix it......????
- 11
- crazy pooling jdbc driver on msaccessI swear that when using the Jakarta commons pooling code with the Sun
JDBC ODBC driver and Microsoft Access I have instances of it closing a
connection on me randomly.
Actually not so randomly - seems to happen regularly but not at the
same spot.
ugh, so tricky to troubleshoot...
- 11
- How to validate XSLT output in java?Howdi,
This should be simple but I am lost in the maze of java xml/xsl
classes. Given a dom Document and an xsl Templates object I want to
run the document through a transformer and validate the output against
a schema and then return the output xml as another Document.
At the moment the only way I can work out how to do this is by
writing the xslt output to a File, then parsing it back in from the
File with validation enabled.. How do I do it directly? Here is where
I have got too. I am working with Java 1.4.2 default implementation.
Regards,
Damon.
====================
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.transform.Templates;
import javax.xml.transform.Transformer;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.sax.SAXResult;
import org.w3c.dom.Document;
import org.xml.sax.InputSource;
public class ValidatingTransform {
public static Document transformXMLDocumentWithValidate(Document
in,
Templates template) throws Exception {
if (in == null)
throw (new Exception("Input document is null"));
// What goes here?
SAXResult result = null;
// Get a transformer from the template
Transformer transformer = template.newTransformer();
transformer.transform(new DOMSource(in), result);
// What goes here??
InputSource source = null;
// Parse the output into a dom with validation
// I am assuming the XSLT output will contain a valid
schemaLocation
DocumentBuilderFactory dbFactory =
DocumentBuilderFactory.newInstance();
dbFactory.setNamespaceAware(true);
dbFactory.setValidating(true);
DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
Document docResult = dBuilder.parse(source);
return docResult;
}
}
- 12
- Clever JNI solution neededOn Thu, 25 Mar 2004 20:01:32 -0500, Jim Sculley
<email***@***.com> wrote:
> I'm wrapping some Java around a large C++/COM API for a Windows
> application via JNI. I cannot see a way to implement one particular
> feature of this API, so I'm posting here to see if it is:
>
> a) impossible
> b) possible with a little cleverness
> c) trivial and I have simply missed something obvious.
>
> The API includes a function to add menu items to a Windows application.
> The COM API call in C++ looks like this:
>
> AddMenuItem("SomeMenuItem@SomeMenu","someFunctionToCall");
>
> The 'someFunctionToCall' parameter is the name of the method to be
> called in the native code. I cannot see a way to implement this on the
> Java side since the native code doesn't even know that Java is involved.
>
> The most I can do is point the native code to a single function for all
> added menu items, but then I have no way of knowing which menu item's
> action needs to be performed.
>
> I suspect that this is impossible but if anyone believes otherwise, feel
> free to comment.
How about generating the necessary C++ functions at build time, that all
just delegate to their Java counterparts? Shouldn't be too hard with Ant
and XDoclet, I reckon. Just tag the relevant methods and use a custom
doclet.
Michiel
- 14
- 14
- china wholesale chanel adidas prada sneakers UGG timberland boots,cheap nike jordan 11 15 21 22 23 shoes
( WWW.NikeChinaWholesale.Com ) china wolesale nike air force 1's, nike
air force one, air force one sneakers, nike air force ones air
forces, Nike Air Force 1 Premium (Barkley), Nike Air Force One Premium
'07, Nike Air Force One Mid '07, Nike Air Force One Supreme Max Air,
Nike Air Force One '07 (Auburn), Nike Air Force One '07, Nike Air
Force One Supreme Max Air '07, Nike Air Force One Supreme Max Air,
Nike Air Force One '07, Nike Air Force One Low, Nike Air Force One
Premium '07, Nike Air Force One '07, Nike Air Force One Mid Premium
(Barkley), Nike Air Force One Supreme MCO CB, Nike Air Force One '07,
Nike Air Force 1 Low (Barkley)
Wholesale Air Jordan 12 Fusions
china wholesaler Air Jordan 5 x AF1 Fusions Black/Red Sneaker
wholesale Air Jordan Force 12 Fusions
Air Jordan V x Air Force 1 Fusion
Nike Air Jordan Force XII Fusion
Air Jordan XII x AF1 Fusion www.nikechinawholesale.com
Nike AIR FORCE 1 AIR JORDAN V fusions
Nike Air Jordan XII Fusions
Nike AF1 Air Jordan Fusions wholesale
Nike Air Jordan Fusions XII Mid
Men's Nike Air Jordan Fusion XII Mid
Air Jordan "Fusions": AJ XII x Air Force 1
Sell Air Jordan 12 fusion sneakers
Air Jordan 5 (V) x Air Force 1 (One) - Fusion
air jordan 12 air force one 1 fusion www.nikechinawholesale.com
Air Jordan fusion XII
Wholesale cheap jordans and air force ones site at
wholesale Air Jordan 12 Fusion,air jordan 5 x air force 1 Fusion
Wholesale New Air Jordan 12 Fusion,Air
Jordan 12 X Air Force 1 Wholesale New Air Jordan 12 Fusion,Air Jordan
12 X Air Force 1
cheap Air Jordan 5 x Air Force one Fusion www.nikechinawholesale.com
discount Air Jordan 5 and Air Force one Fusion www.nikechinawholesale.com
Air Jordan 12 x Air Force One china online store
Air Jordan V x Air Force 1 Fusion www.nikechinawholesale.com
Air Jordan 12 x Air Force Ones Fusion
Nike AF1 x Air Jordan 5.
Nike Air Force Ones Shoes & Air Jordan 5. www. nikechinawholesale. com
wholesale Air Jordan 5 (V) x Air Force 1 Fusion
- 14
- Media Framework presenceHello,
Applications produced by my project, sometimes (not always) relys on
the presence of the Media Framework on the machine of the final user.
When an application created with my project uses Media framework, is
launched on a machine where JMF is not installed, it crashes badly
(hard reset necessary).
So my question : is there a way to detect if the JMF is installed on
the machine of the final user?
Thanks for you input,
Francois
- 15
- Problem with Look and FeelI have an applet in which i set the look and feel to that of the system.
This works when the applet is loaded but when the user selects another
page and then returns to the applet the look and feel has changed.
I have no ideas as to why this is happening.
Any help would be much appreciated.
Regards
Clive
--
Posted via Mailgate.ORG Server - http://www.Mailgate.ORG
- 15
- Threading In Java BeansHello, I was trying to find some information regarding Concurrency in
J2EE. In my application I simply put a lock on the session and the
accessor/mutator methods inside the bean. Is this the proper way of
ensuring data consistency in a large scale web site. Any opinions or
links would be appreciated.
thanks
|
| Author |
Message |
Murph

|
Posted: 2005-10-12 20:48:00 |
Top |
java-programmer, Constructors + Information Hiding
I have a random question about a constructor having access to a private
instance variable from an object of the same type.
Class:
public class VarTest {
private int x;
private String s;
public VarTest(){
x = 10;
s = "Testing";
}
public VarTest(int i, String str){
x = i;
s = str;
}
//I know why this would be a useful constructor,
// but why is this allowed if the instance variables for
// vt are private?????
public VarTest(VarTest vt){
x = vt.x;
s = vt.s;
}
public int getX(){
return x;
}
public String getS(){
return s;
}
}
Test Class:
public class Tester{
public static void main(String args[]){
VarTest var1, var2;
var1 = new VarTest(34, "Working?");
var2 = new VarTest(var1);
System.out.println("var2 - x:\t" + var2.getX());
//var2.getX() display 34... Why can is get that from var1?
}
}
Thanks In Advance Folks,
Josh
|
| |
|
| |
 |
Eric Sosman

|
Posted: 2005-10-12 22:51:00 |
Top |
java-programmer >> Constructors + Information Hiding
Murph wrote On 10/12/05 08:48,:
> I have a random question about a constructor having access to a private
> instance variable from an object of the same type.
>
> Class:
> public class VarTest {
> private int x;
> private String s;
>
> public VarTest(){
> x = 10;
> s = "Testing";
> }
>
> public VarTest(int i, String str){
> x = i;
> s = str;
> }
>
> //I know why this would be a useful constructor,
> // but why is this allowed if the instance variables for
> // vt are private?????
> public VarTest(VarTest vt){
> x = vt.x;
> s = vt.s;
> [...]
"private" does not mean "private to a particular
instance," but "private to the class." Any method or
constructor in the class has access to all the private
members of all the class' instances, assuming it can
get hold of references to those instances.
This is not only useful, as you say, but downright
necessary in many cases. Consider writing an equals()
method for your VarTest class, one that considers
two VarTest objects "equal" if their x and s members
are equal. How could equals() make the decision if
it didn't have access to the other object's x?
--
email***@***.com
|
| |
|
| |
 |
Fabien Bergeret

|
Posted: 2005-10-12 23:01:00 |
Top |
java-programmer >> Constructors + Information Hiding
Eric Sosman wrote:
>
> Murph wrote On 10/12/05 08:48,:
>
>>I have a random question about a constructor having access to a private
>>instance variable from an object of the same type.
>>
>>Class:
>>public class VarTest {
>> private int x;
>> private String s;
>>
>> public VarTest(){
>> x = 10;
>> s = "Testing";
>> }
>>
>> public VarTest(int i, String str){
>> x = i;
>> s = str;
>> }
>>
>>//I know why this would be a useful constructor,
>>// but why is this allowed if the instance variables for
>>// vt are private?????
>> public VarTest(VarTest vt){
>> x = vt.x;
>> s = vt.s;
>>[...]
>
>
> "private" does not mean "private to a particular
> instance," but "private to the class." Any method or
> constructor in the class has access to all the private
> members of all the class' instances, assuming it can
> get hold of references to those instances.
>
> This is not only useful, as you say, but downright
> necessary in many cases. Consider writing an equals()
> method for your VarTest class, one that considers
> two VarTest objects "equal" if their x and s members
> are equal. How could equals() make the decision if
> it didn't have access to the other object's x?
>
Just like any other method : by calling the getters, which can by either
public or private.
I consider it quite ugly to call directly the attributes ; it violates
the encapsulation paradigm.
|
| |
|
| |
 |
Eric Sosman

|
Posted: 2005-10-12 23:27:00 |
Top |
java-programmer >> Constructors + Information Hiding
Fabien Bergeret wrote On 10/12/05 11:01,:
> Eric Sosman wrote:
>>
>> "private" does not mean "private to a particular
>>instance," but "private to the class." Any method or
>>constructor in the class has access to all the private
>>members of all the class' instances, assuming it can
>>get hold of references to those instances.
>>
>> This is not only useful, as you say, but downright
>>necessary in many cases. Consider writing an equals()
>>method for your VarTest class, one that considers
>>two VarTest objects "equal" if their x and s members
>>are equal. How could equals() make the decision if
>>it didn't have access to the other object's x?
>>
>
> Just like any other method : by calling the getters, which can by either
> public or private.
> I consider it quite ugly to call directly the attributes ; it violates
> the encapsulation paradigm.
(I thought about writing something to forestall this
red herring, but foolishly imagined it wouldn't be dragged
across the trail ... Ah, well.)
The question was about what "private" access means,
not about how you would use or abuse whatever access you've
got. If "private" did in fact mean "private to the instance"
(which it doesn't; that was the crux of the O.P.'s question),
how, pray tell, could you invoke a private method -- whether
a getter or something else -- on any object other than "this"?
--
email***@***.com
|
| |
|
| |
 |
Mark Haase

|
Posted: 2005-10-13 0:33:00 |
Top |
java-programmer >> Constructors + Information Hiding
In article <434d254a$0$23007$email***@***.com>,
Fabien Bergeret <email***@***.com> wrote:
> Just like any other method : by calling the getters, which can by either
> public or private.
> I consider it quite ugly to call directly the attributes ; it violates
> the encapsulation paradigm.
I don't see this being a major problem...if you ever updated the class
and changed the data model, it would be trivial to update the equals
method since it resides inside the class as well. Its no different than
updating the getter and setter methods.
Accessing fields directly from another class can be a problem, because
then it complicates code maintenance (change a data model in one class
and it breaks another class, e.g.) and if somebody else relies on your
class they have to learn what the internal changes are as well.
--
|\/| /| |2 |<
mehaase(at)gmail(dot)com
|
| |
|
| |
 |
Chris Smith

|
Posted: 2005-10-13 3:04:00 |
Top |
java-programmer >> Constructors + Information Hiding
Eric Sosman wrote:
> > This is not only useful, as you say, but downright
> > necessary in many cases. Consider writing an equals()
> > method for your VarTest class, one that considers
> > two VarTest objects "equal" if their x and s members
> > are equal. How could equals() make the decision if
> > it didn't have access to the other object's x?
Fabien Bergeret <email***@***.com> wrote:
> Just like any other method : by calling the getters, which can by either
> public or private.
This assumes that the class exposes accessor methods. Accessor methods
are frequently necessary, but good code avoids using them out of habit.
Code that wants to "get" the values of another class's fields is quite
likely to belong in that other class, instead of wherever it currently
resides.
Of course, you could provide private accessors... but that ducks the
question here, and provides absolutely no extra encapsulation.
--
www.designacourse.com
The Easiest Way To Train Anyone... Anywhere.
Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation
|
| |
|
| |
 |
Roedy Green

|
Posted: 2005-10-13 4:20:00 |
Top |
java-programmer >> Constructors + Information Hiding
On 12 Oct 2005 05:48:00 -0700, "Murph" <email***@***.com> wrote
or quoted :
>//I know why this would be a useful constructor,
>// but why is this allowed if the instance variables for
>// vt are private?????
I don't think you understand what private means. See
http://mindprod.com/jgloss/private.html
--
Canadian Mind Products, Roedy Green.
http://mindprod.com Again taking new Java programming contracts.
|
| |
|
| |
 |
Stefan Schulz

|
Posted: 2005-10-13 18:50:00 |
Top |
java-programmer >> Constructors + Information Hiding
On Wed, 12 Oct 2005 17:01:29 +0200, Fabien Bergeret wrote:
> I consider it quite ugly to call directly the attributes ; it violates
> the encapsulation paradigm.
No, it doesn't. Encapsulation is about hiding implementation details from
users of the class. It never had been, or can be, about hiding
implementation details from the implementation itself.
If there is an accessor available, it should be called, since it might be
overridden by a subclass. However, creating a private accessor is just
silly.
--
You can't run away forever,
But there's nothing wrong with getting a good head start.
--- Jim Steinman, "Rock and Roll Dreams Come Through"
|
| |
|
| |
 |
Tim Smith

|
Posted: 2005-10-14 14:28:00 |
Top |
java-programmer >> Constructors + Information Hiding
In article <434d254a$0$23007$email***@***.com>,
Fabien Bergeret <email***@***.com> wrote:
> > This is not only useful, as you say, but downright
> > necessary in many cases. Consider writing an equals()
> > method for your VarTest class, one that considers
> > two VarTest objects "equal" if their x and s members
> > are equal. How could equals() make the decision if
> > it didn't have access to the other object's x?
> >
> Just like any other method : by calling the getters, which can by either
> public or private.
> I consider it quite ugly to call directly the attributes ; it violates
> the encapsulation paradigm.
Your approach is the object-oriented equivalent of a cargo cult.
--
--Tim Smith
|
| |
|
| |
 |
Roedy Green

|
Posted: 2005-10-15 12:06:00 |
Top |
java-programmer >> Constructors + Information Hiding
On Fri, 14 Oct 2005 06:27:40 GMT, Tim Smith
<email***@***.com> wrote or quoted :
>
>Your approach is the object-oriented equivalent of a cargo cult.
The principle of information hiding is to hide information from
outside clients if they don't need it, not to hide it from yourself.
--
Canadian Mind Products, Roedy Green.
http://mindprod.com Again taking new Java programming contracts.
|
| |
|
| |
 |
| |
 |
Index ‹ java-programmer |
- Next
- 1
- buggy regexpHello all!
The following line hangs in Java:
Pattern.matches("((<BR>)|([^<>]+))*", "aaaaaaaaaaaaaaaaaaaaaaaa
<BR><Bx>")
What's wrong with the regular expression?
Thanks in advance
Ilya
- 2
- Calling Stored procedure within the Orcale Server or outside clientHi all,
I have liitle confusion about the stored procedures. I am doing the
Database purging using stored procedures in Oracle 9g. can you tell is
it better to call stored procedures from outside client which i will
take care of the flow in which stored procedues are called or call it
from JAVA STORED PROCEDURS loaded in the database, which will take
care of flow in which stored procs will get executed which inturn is
set by UNIX CRON
- 3
- Applet no longer works in IE - problem fixedHi Andrew,
It seems that the source of my problem is the fact that I upgraded
from Eclipse 2.1.1. to 3.2.0. After testing with the latest working
version of my applet I found out that the compiler compliance setting
has to be 1.3 for the applet to work in IE. Default setting is 1.4.
:-|
thanks, Mark.
On Tue, 15 Nov 2005 22:35:10 +0100, Mark <email***@***.com> wrote:
>Sorry, yes I forgot. I don't like frames but how else can you prevent
>having to reload the applet every time you load another page?
>I have removed the redirection.
>This is the HTML:
>
><!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
> "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
><HTML xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
><HEAD>
><TITLE>Smorf applet 360x360</TITLE>
><META NAME="ROBOTS" CONTENT="NOINDEX, NOFOLLOW">
><META http-equiv="Content-type" content="text/html;
>charset=iso-8859-1" />
><meta http-equiv="imagetoolbar" content="no" />
><meta content="TRUE" name="MSSmartTagsPreventParsing" />
><link rel="stylesheet" type="text/css" href="styles.css" />
><script language="javascript">
> if(self.location==top.location)self.location="frames360.html";
></script>
></HEAD>
><BODY>
> <APPLET
> code="SmorfApplet.class"
> height=360 width=360
> name="smorf"
> archive="smorfob.jar, jazz3d3.jar, jazz3d3_primitives.jar"
> </APPLET>
></BODY>
></HTML>
>
>anyway I found out creating the package isn't the problem. I put all
>the classes in a single package and jar file, the problem is still
>there.
>
>Mark.
>
>On Tue, 15 Nov 2005 21:20:49 GMT, Andrew Thompson
><email***@***.com> wrote:
>
>>Mark wrote:
>>
>>> The applet I'm testing is here:
>>> http://www.smorf.nl/smorfde/frames360.html
>>
>>That's a frames based page, and when I try to get
>>the applet itself*, I get directed back to the frames
>>page.
>>
>>* I need to see the HTML source.
>>
>>Fix that and I'll help.
- 4
- MyEclipse - XDoclet problem Hi
I'm trying to create a simple EJB by the help of myeclipse
1. i've created EJB class
2. selected myeclipse - XDoclet standart EJB
and after running myeclipse - XDoclet only 'home' interface has been
generated
could anybody explain why 'object' interface hasn't been generated
I use
Eclipce Version: 3.0.0 Build id: 200310101454
MyEclipse Version: 3.6.4
code:
----------------------------------------------------------------------------
package hello;import java.rmi.RemoteException;import
javax.ejb.CreateException;import javax.ejb.EJBException;import
javax.ejb.SessionBean;import javax.ejb.SessionContext;/** * XDoclet-based
stateless session bean. The class must be declared * public, according to
the EJB specification. * * To generate code: * * * a.. Add Standard EJB
module to XDoclet project properties * b.. Customize XDoclet configuration
* c.. Run XDoclet * * * Please see the included XDoclet Overview * and
the XDoclet Reference in the help system for details * * @ejb.bean name =
"HelloWorld" * type = "Stateless" * display-name =
"HelloWorld" * description = "HelloWorld EJB" *
view-type = "remote" * jndi-name = "ejb/HelloWorldHome" */public
class HelloWorld implements SessionBean { /** The SessionContext */ private
SessionContext context; /** * An ejbCreate method as required by the EJB
specification. * * The container calls the instance's ejbCreate method
whose * signature matches the signature of the create method invoked *
by the client. The input parameters sent from the client are passed to *
the ejbCreate method. Each session bean class must have at * least one
ejbCreate method. The number and signatures * of a session bean's create
methods are specific to each * session bean class. * * @throws
CreateException Thrown if the instance could not perform * the function
requested by the container because of an system-level error. * *
@ejb.create-method */ public void ejbCreate() throws CreateException { }
/** * The ejbActivate() method as required by the EJB specification. * *
The activate method is called when the instance is activated from its *
passive" state. The instance should acquire any resource that it has *
released earlier in the ejbPassivate() method. * * This method is called
with no transaction context. * * @throws EJBException Thrown if the
instance could not perform * the function requested by the container
because of an system-level error. */ public void ejbActivate() throws
EJBException { } /** * The ejbPassivate() method as required by the EJB
specification. * * The activate method is called when the instance is
activated from * its "passive" state. The instance should acquire any
resource that * it has released earlier in the ejbActivate() method. *
* This method is called with no transaction context. * * @throws
EJBException Thrown if the instance could not perform * the function
requested by the container because of an system-level error. */ public void
ejbPassivate() throws EJBException { } /** * The ejbRemove() method as
required by the EJB specification. * * A container invokes this method
before it ends the life of the * session object. This happens as a result
of a client's invoking * a remove operation, or when a container decides
to terminate the * session object after a timeout. * * This method
is called with no transaction context. * * @throws EJBException Thrown
if the instance could not perform * the function requested by the
container because of an system-level error. */ public void ejbRemove()
throws EJBException { } /** * Set the associated session context. The
container calls this method * after the instance creation. * * The
enterprise bean instance should store the reference to the context *
object in an instance variable. * * This method is called with no
transaction context. * * @throws EJBException Thrown if the instance
could not perform * the function requested by the container because of an
system-level error. */ public void setSessionContext(SessionContext
newContext) throws EJBException { context = newContext; } /** * An
example business method * * @ejb.interface-method view-type = "remote" *
* @throws EJBException Thrown if the instance could not perform * the
function requested by the container because of an system-level error. */
public void m1() throws EJBException { // rename and start putting your
business logic here } /** * An example business method * *
@ejb.interface-method view-type = "remote" * * @throws EJBException
Thrown if the instance could not perform * the function requested by the
container because of an system-level error. */ public void m2() throws
EJBException { // rename and start putting your business logic here }}
----------------------------------------------------------------------------
Thanks a lot !
- 5
- replace scrollbar by buttonHi everybody
I would like to suppress scroll bar and replace it by narrow, let
explain me.
I' ve got a panel with flowlayout with many component, textarea,
combobox, button. it is impossible to see all.
I can use scroll panel but it's not nice in my opinion
So I would like a button with an arrow left, at the left of the panel
and a button with an arrow right at the right of the panel, everytime
visible
click on arrow left, let see the lefter components, click on arrow
right, let see the righter components. In brief I would to navigate on
components using the arrows. I hope it's clear.
My first idea is to create a parent panel with border layout, on west
and east the navigate button and in the center will contains my components.
Do you thing it's a good a way ?
Do you know some sources that always do it ?
Thank you helping me
Antoine
- 6
- New book on web services and Apache Axis availableHi,
A new book "Developing Web Services with Apache Axis" is now available.
If you'd like to learn to create web services (in particular, using
Apache Axis) and make some sense of various standards like SOAP, WSDL,
JAX-RPC, SOAP with attachments, WS-Security, XML Encryption and XML
Signature, then please check it out at http://www.agileskills2.org/DWSAA
- 7
- mail parser ?Hi
I am programming a smtp proxy and i would like to parse the email (in
rfc 822 format). Does a library already exist ?
many thanks
- 8
- how do i paste into eclipsei just downloaded eclipse 3, but i can't seem to paste text into it. all it
gives me is the first character. is there a way i can paste, because it
would be a headache to type out everything needed
- 9
- making indented XMLI could swear that this used to work for me, but when I run the
following code I get:
<?xml version="1.0" encoding="UTF-8"?>
<a><b><c/></b></a>
which is not the:
<a>
<b>
<c/>
</b>
</a>
that I want and was expecting. I'm running JDK 1.4.2_03 on W2K with
the latest Xalan and Xerces.
I've tried running it like the following:
java -classpath .;xercesImpl.jar;xalan.jar;xml-apis.jar PrintTest
java -Djava.endorsed.dirs=. -classpath
.;xercesImpl.jar;xalan.jar;xml-apis.jar PrintTest
java -Xbootclasspath/p:xercesImpl.jar;xalan.jar;xml-apis.jar
-classpath .;xercesImpl.jar;xalan.jar;xml-apis.jar PrintTest
I'm at a loss here. Can somebody throw me a bone?
Cheers.
Steve Maring
steve at maring dot org
import java.io.StringReader;
import java.io.PrintWriter;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.Transformer;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.OutputKeys;
import org.w3c.dom.Document;
import org.xml.sax.InputSource;
public class PrintTest
{
public static void main( String[] args )
{
try
{
String xml = "<a><b><c></c></b></a>";
PrintWriter printWriter = new PrintWriter( System.out, true
);
DocumentBuilderFactory factory =
DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
Document doc = builder.parse(
new InputSource( new StringReader( xml ) ) );
TransformerFactory transFactory =
TransformerFactory.newInstance();
Transformer transformer = transFactory.newTransformer();
transformer.setOutputProperty( OutputKeys.METHOD, "xml" );
transformer.setOutputProperty( OutputKeys.INDENT, "true" );
transformer.setOutputProperty(
OutputKeys.OMIT_XML_DECLARATION, "true" );
transformer.setOutputProperty(
"{http://xml.apache.org/xslt}indent-amount", "4" );
transformer.transform(
new DOMSource( doc ), new StreamResult( printWriter ) );
}
catch ( Exception e )
{
e.printStackTrace();
}
}
}
- 10
- SOLVED: How to read MANIFEST.MF from pluginHi,
here is a way to access "your" manifest, i.e. the manifest of the jar
your class is loaded from. It only works for SunPlugin. In other cases
you may have another ClassLoader not supporting a public
findResource-method. The always public getResource unfortunatly
prefers to return resources returned by the parent's getResource if it
is not null. That's why you would get the manifest of rt.jar. Is there
any good reason to revert the principle 'local hides global' in case
of getting resources? Anyway, here it is:
import java.util.jar.Manifest;
import sun.applet.AppletClassLoader;
...
AppletClassLoader cl = (AppletClassLoader)
getClass().getClassLoader();
URL manifest_url = cl.findResource("META-INF/MANIFEST.MF");
Manifest manifest = new Manifest(manifest_url.openStream());
Yours,
Albrecht
- 11
- Sound Recording - Runs out of memoryI think you may find examples from this website very helpful:
http://www.jsresources.org
Regards,
JM
"Christiaan" <email***@***.com> wrote in message
news:email***@***.com...
> Hi,
>
> Here is a simple sound recording program to record sounds via your
> mic.The problem is that you read the sound bytes into a
> ByteArrayOutputStream and if it becomes to big you get -
> java.lang.OutOfMemoryError.
>
> What can I do to overcome this , I have tried to write the incomming
> bytes to file 1st and then from the file into the audioInputStream ,
> but I couldn't get that to work - here is my code (I used jdk1.3 and
> jdk1.4):
>
>
>
> If you copy the code into a IDE the place where the exception are
> thrown are on line 236.
>
> /*
> Christiaan Pansegrouw
> 22/05/2003
> Simple Sound Recording app
> Contains a start & stop buttom & saves to a wave file -
> "userHomeDir"\SimpleMicRecording\SimpleSound.wav
>
> */
>
> import javax.swing.*;
> import java.awt.*;
> import java.awt.event.*;
> import javax.sound.sampled.*;
> import java.io.*;
>
>
>
>
> public class LaunchSimpleSound
> {
> public static void main(String [] args)
> {
> SimpleSound ss = new SimpleSound();
> }
> }
>
>
> class SimpleSound extends JFrame implements ActionListener
> {
>
> private String userHomeDir = System.getProperty("user.home");
> private String fileSeperator =
> System.getProperty("file.separator");
>
> private JPanel mainPanel;
> private JButton cmdStartRecord;
> private JButton cmdStopRecord;
> AudioInputStream audioInputStream;
> double duration;
> Capture capture = new Capture();
>
> public SimpleSound()
> {
> makeGUI();
>
> }
>
>
> public void makeGUI()
> {
> mainPanel = new JPanel();
> cmdStartRecord = new JButton("Start");
> cmdStopRecord = new JButton("Stop");
> cmdStopRecord.setEnabled(false);
>
>
> cmdStartRecord.addActionListener(this);
> cmdStopRecord.addActionListener(this);
>
>
> mainPanel.add(cmdStartRecord);
> mainPanel.add(cmdStopRecord);
>
> Container c = this.getContentPane();
>
> c.add(mainPanel , BorderLayout.CENTER);
> this.pack();
> this.setDefaultCloseOperation(EXIT_ON_CLOSE);
> this.setVisible(true);
>
> }
>
>
> public void actionPerformed(ActionEvent ae)
> {
> Object source = ae.getSource();
>
> if (source == cmdStartRecord)
> {
> cmdStartRecord.setEnabled(false);
> cmdStopRecord.setEnabled(true);
> capture.start();
>
> }
> else
> {
> cmdStartRecord.setEnabled(true);
> cmdStopRecord.setEnabled(false);
> capture.stop();
> // SaveToFile();
> }
> }
>
>
> public void SaveToFile()
> {
> if (audioInputStream == null)
> {
> System.out.println("Nothing to save ->someting bad happend !!!");
> System.out.println("cashing & burning . .. .");
> System.exit(0);
> }
> else
> {
>
> }
>
> try
> {
> audioInputStream.reset();
> }
> catch(Exception e)
> {
> System.out.println("Unable to reset audioStream in save method");
> System.out.println("Exitting . .. .");
> System.exit(0);
> }
> File x = new File(userHomeDir + fileSeperator +
> "SimpleMicRecording" + fileSeperator + "SimpleSound.wav");
> if (!(x.exists())){
> File dirs = x.getParentFile();
> dirs.mkdir();
> }
> File file = new File(userHomeDir + fileSeperator +
> "SimpleMicRecording" + fileSeperator + "SimpleSound.wav");
> try
> {
> if (AudioSystem.write(audioInputStream , AudioFileFormat.Type.WAVE
> , file) == -1)
> {
> System.out.println("Error");
> }
> }
> catch(Exception e)
> {
> System.out.println("Oh-no!!!");
> }
> }
>
> class Capture implements Runnable
> {
> private AudioFormat.Encoding encoding;
> private float rate;
> private int sampleSize;
> private int channels;
> private int frameSize;
> private boolean bigEndian;
>
>
>
> TargetDataLine line; //define a line - a line from witch audio can
> be read
> Thread thread;
>
> public void start()
> {
> thread = new Thread(this);
> thread.setName("Capture Audio");
> thread.start();
> }
>
>
> public void stop()
> {
> thread = null;
> }
>
> public void run()
> {
> duration = 0;
> audioInputStream = null;
>
> setupFormat();
>
> //define the required attributes for the line &
> //make sure a compatible line is supported
> AudioFormat format = new
> AudioFormat(AudioFormat.Encoding.PCM_SIGNED ,44100, 16,2 , 4 ,44100 ,
> true);
>
> //does not want to work !!!!????
> //AudioFormat format = new AudioFormat(encoding , rate , sampleSize
> , channels , frameSize , rate , bigEndian);
>
> DataLine.Info info = new DataLine.Info(TargetDataLine.class ,
> format);
>
> if (!AudioSystem.isLineSupported(info))
> {
> System.out.println("Line matching " + info +" not supported");
> System.out.println("Exitting the application . . .");
> System.exit(0);
> }
>
> //get & open target data line for capture
>
> try
> {
> line = (TargetDataLine) AudioSystem.getLine(info);
> line.open(format , line.getBufferSize());
> }
> catch(LineUnavailableException ex)
> {
> System.out.println("Unable to open the line");
> System.out.println("Exitting application . . .");
> System.exit(0);
> }
> catch(SecurityException ex)
> {
> System.out.println("A security exception occured");
> System.out.println("Exitting application . . .");
> System.exit(0);
> }
> catch(Exception ex)
> {
> System.out.println("Some exception occured");
> System.out.println("Exitting application . . .");
> System.exit(0);
> }
>
> ByteArrayOutputStream out = new ByteArrayOutputStream();
> int frameSizeInBytes = format.getFrameSize();
> int bufferLengthInFrames = line.getBufferSize() / 8;
> int bufferLengthInBytes = bufferLengthInFrames * frameSizeInBytes;
> byte [] data = new byte[bufferLengthInBytes];
> int numBytesRead;
>
> line.start();
>
> //while the thread is running , write whatever is comming
> //through the line(TargetDataLine) , to the ByteArrayOutputStream
> while (thread != null)
> {
> //Reads audio data from the data line's input buffer
> //if eoi then break out of the while-loop
>
> //The number of bytes to be read must represent an integral
> //number of sample frames, such that:
> // [ bytes read ] % [frame size in bytes ] == 0
> if ((numBytesRead = line.read(data , 0 , bufferLengthInBytes)) ==
> -1)
> {
> break;
> }
> //here is the problem
> out.write(data ,0 , numBytesRead);
> }
>
>
> //we reached the end of the stream . stop & close the line
> line.stop();
> line.close();
> line = null;
>
> //stop & close the output stream
> try
> {
> //Flushes this output stream and forces any buffered
> //output bytes to be written out. The general contract
> //of flush is that calling it is an indication that, if
> //any bytes previously written have been buffered by the
> //implementation of the output stream, such bytes should
> //immediately be written to their intended destination.
> out.flush();
> out.close();
> }
> catch(IOException ex)
> {
> System.out.println("IO Error occurered (flussing the
> BufferArrayOutputStream)");
> System.out.println(" . . . but carring on");
> }
>
> //load bytes in to audio input stream for saving
>
> byte audioBytes[] = out.toByteArray();
> ByteArrayInputStream bais = new ByteArrayInputStream(audioBytes);
> audioInputStream = new AudioInputStream(bais , format ,
> audioBytes.length / frameSizeInBytes);
>
> long milliseconds =
> (long)((audioInputStream.getFrameLength() * 1000) /
> format.getFrameRate());
> duration = milliseconds / 1000.0;
>
>
> try
> {
> audioInputStream.reset();
> }
> catch(Exception e)
> {
> System.out.println("Error resetting audioInputStream");
> System.out.println("Exitting application . . .. ");
> System.exit(0);
> }
>
> if (audioInputStream == null)
> {
> System.out.println("?????????");
> }
> SaveToFile();
>
> }
>
> private void setupFormat()
> {
> AudioFormat.Encoding encoding = AudioFormat.Encoding.PCM_SIGNED;
> rate = (float)44100;
> sampleSize = 16;
> channels = 2;
> frameSize = (sampleSize/8)*channels;
> bigEndian = true;
> }
> }
> }
- 12
- 13
- Positioning dialogboxes created with JOptionPaneThe dialog boxes created using JOptionPane like showConfirmDialog,
showInputDialog gets displayed in the centre of the screen. I need to change
its position. How to do this?
These methods return int or none.
How to get access to the dialog boxes so that they
can be positioned by using appropriate method? or I need to create a custom
dialog box so that they can be positioned?
- 14
- To class or to methodI have a class
public class CascadeAction {
...
public CascadeAction(JDesktopPane ... ) {
}
...
public void setIgnoreIconified(...) {
...
}
public void actionPerformed(ActionEvent evt) {
...
}
...
}
Instead of having a class, is the proper way to create a method :
public void cascadeFrames(JDesktopPane desktopPane, int layer, boolean
ignoreIconified) {
...
}
I don't think I should place this method in a subclass of JDesktopPane
since doing so will make it impossible for other users to use the
cascade feature if they already have their own custom JDesktopPane.
Please advice me on the proper way.
- 15
- Where to find web game programmer?Where is the best place for me to find a java programmer to write a
few games for a website? These would be mostly casino style games
that would interact with our existing database to take advantage of
the points/tokens our users already have obtained.
Please email me if interested, or, send me to the best place to find
such a person or group of people..
c b r o m l e y @ g m a i l . c o m
|
|
|