java

simple java cookie question

I'm a .Net developer starting to dabble in Java. I have a simple question concerning cookies. In .Net, I can set the value of a cookie to a string with white space in it - new HttpCookie("myCookieName", "my value") - and when I read that value on the client side (javascript), I get the value I expected (my value). If I do the same thi...

Mouse Listener Question

I am developing a screen capturing utility in Java & I want to capture any background window, when I click on that particular window. But I am not getting how to add mouseClicked event to background window. Can somebody please help me? ...

Problem transmitting null character over sockets

I am writing a small Java server, and a matching client in C++, which implement a simple IM service over the STOMP protocol. The protocol specifies that every frame (message that passes between server and client, if you will) must end with a null character, which in code I refer to as '\0', both in Java and in C++. However, when I tran...

Applet is empty with absolute layout

Hi there, I want to create a hangman game as an applet, so I have some labels and buttons that will be initialized by the generated code of the gui designer but I also have some labels I create on my own, after knowing how long my word is. Therefore I use absolute layout for my applet. In netbeans my applet works finde when I run it bu...

Why EventDispatchThread in first place?

This is the design decision I don't understand. Both Android and JME follow the policy that the thread that started an app is the UI thread and you take care to offload resource-consuming stuff to another threads. In Swing, on the other hand, you use EventQueue.invokeLater(Runnable) for UI and SwingWorker for background processing. No...

showing images on jeditorpane (java swing)

I have a JEditorPane created by this way: JEditorPane pane = new JEditorPane("text/html", "<font face='Arial'>" + my_text_to_show + "<img src='/root/img.gif'/>" + "</font>"); I put this pane on a JFrame. Text is shown correctly, but I can't see the picture, there is only a square indicating that there should be an image (i.e.: "broke...

Java - Convert String to valid URI object

I am trying to get a java.net.URI object from a String. The string has some characters which will need to be replaced by their percentage escape sequences. But when I use URLEncoder to encode the String with UTF-8 encoding, even the / are replaced with their escape sequences. How can I get a valid encoded URL from a String object? http...

Thread safety in Java web application data access class

A hobby project of mine is a Java web application. It's a simple web page with a form. The user fills out the form, submits, and is presented with some results. The data is coming over a JDBC Connection. When the user submits, I validate the input, build a "CREATE ALIAS" statement, a "SELECT" statement, and a "DROP ALIAS" statement. ...

How do I change the JAVA_HOME for ant?

I'm doing java work on a class server where I don't have root. Whenever I try to compile using ant, it points to the wrong directory (/usr/tomcat instead of /usr/tomcat/jre ). One of the things we were told to do when setting up our user accounts was to add export JAVA_HOME=/usr/tomcat/jre to the .bashrc file. I don't know if that was ...

java swing close window without exiting app

I have a little frame where I ask user & password. This frame will be opened clicking over a button in a main window. Then I have two buttons: ok and cancel. When I click on "cancel" button, I need to close this frame without exiting the app. How can I do that? ...

How can I detect a free port on the server by code from client side?

Is there any way by which i can find out free port on the server by executing a code from client computer. Example for opening a port on my local machine: ServerSocket localmachine = new ServerSocket(0); int port = localmachine.getLocalPort(); This way I can retrieve a free port on my local machine. Now suppose I have my own server:...

managing parent frame from child frame on java swing

I have a jframe (parent) which creates an input frame (child) where I get some parameter. In the "child" frame I have "ok" and "cancel" buttons. When "ok" button is pressed, the parent frame needs to be updated with new data. What is the best way to do that?? ...

Why casting from a stack to int is not running in Java?

I'm trying to cast a char that is stored in stack to an interger and this is what I did. operands = new StackLinked(); if ( (a == '0') || (a == '1') || (a == '2') || (a == '3') || (a == '4') || (a == '5') || (a == '6') || (a == '7') || (a == '8') || (a == '9') ) { operands.push(a); /*Stor operands in the stack operands.*/ } ...

Is Java due for a reboot?

Java is now nearly 14 years old, and the age is starting to show. In my industry (banking), we joke that Java is the COBOL of the 21st century; except it's not much of a joke, it's the sad reality. Java has a lot of "baggage" that is kept for backwards-compatibility -- exactly the kind of stuff that is critical for clients like banks. B...

Is the C# "explicit implementation" of the interface present in Java?

In C#, if you have two base interfaces with the same method (say, F()) you can use explicit implementation to perform different impl. for F(). This alloes you to differently treat the object, corresponding to the current point of view: as IMyInterface1 or IMyInterface2. Is this possible in Java? Thanks ...

Locator and stub class while migrating client side application from Axis to Axis 2

Hi everyone, I’m trying to migrate a client side application from Axis to Axis 2. The application also supports connection through RMI so previously, we abstracted away the connection by using the stub and the locator file. For example, we did something like the following: AddFunctionLocator locator = new AddFunctionLocator (); AddF...

Swing: Which objects for a multi panel display and highlighting text

Hello, I plan on making a multi comparison program. It will compare multiple files by displaying N number of files in a grid where N = X * Y. X and Y are the width and height of the grid elements. Easy enough, I know how to do this pretty much. The question: How do and in what way is best to highlight individual characters in each of th...

open resource with relative path in java

In my java app I need to get some files and dirs. This is the program structure `./main.java ./package1/guiclass.java ./package1/resources/resourcesloader.java ./package1/resources/repository/modules/ -> this is the dir I need to get ./package1/resources/repository/SSL-Key/cert.jks -> this is the file I need to get` gui class lo...

Smack api and Java

I am using Tapestry 5, Smack api 3.1.0. I have established a connection and am able to communicate with a user through the xmpp server but the replies i get are sent to the standard output as they come in: Chat chat = connection.getChatManager().createChat("[email protected]", new MessageListener() { public void processMessage(Chat c...

Java: GUIs must be initialized in the EDT thread?

Hi, I'm Jason. I'm having a bit of a problem with the Substance look and feel (https://substance.dev.java.net/). My problem is more general. I've already got my GUI written and it works fine, but when I use a Substance Look-and-feel, it requires all GUI initialization to take place in the EDT thread (Event Dispatching Thread or somethin...