Taking a "screenshot" of a java applet - java

No. Not pressing PRT Screen. But here is what I want. And I need to know if it can be done and by what means :D
Okay so I have a java applet that runs and displays a walking man.
I need it so when I access a script (in some web scripting language) it takes a "screenshot" of that applet and then saves it on the server. Is this possible? and by what scripting means could I do it?
Thanks in advance!

If there are heavyweight components they might not come out, but the obvious way is:
Create a java.awt.image.BufferedImage
Call createGraphics to create a Graphics instance.
Call update(Graphics) on the applet.
Find a tutorial for converting the BufferedImage to a wire file format.
POST back to the web server.
You can use LiveConnect to connect both ways between Java and JavaScript. It's usually easy to add Java code to an applet simply by adding another reference to the archive attribute of the applet tag.
There are plenty of tutorials on the various parts. I've never done it myself.

Related

Control other applications using Java?

How can I control other applications using Java ?
I'm using the Mary Speech Synthesizer(Open source, Java). It can synthesize speech well , but it requires the text to be in a textbox in the application window itself and then a button to be clicked . For this project of mine
the text that needs to be realized is gonna be inbound from another java application . I need to know how I can place the text in the textbox and send a click to one of the buttons in the application .
I'm hoping to figure out a way to synthesize speech from a buffer later on but till then this seems like it's a way to get things working . Also , I'm pretty sure I'll be able to find other applications for this later on and this seems like a very interesting problem ..
Get the other application's API and call its methods accordingly.
If an application does not offer an API to interact with it, there is no simple solution to make it.
However, since the application is open source you can verify what type of licensing it has, and include a part of its source code in your Java application and call it properly.
I think your best option is to find a library that does the text synthesizing. Since controlling another java application required that java application to provide the necessary API for you to access it. As #Edmondo1984 told in his answer you can include the part of the code from the open source application(After checking the licence).

Reloading an iFrame which was running an Applet

I have a web page which is divided into several iFrames.
In each frame is a different solution, like JavaScript in one, flash in another, applet in another.
When a user interacts with the Applet, I am trying to provide a solution where if a certain event happens in the Applet, that the Applet will die and the same iFrame gets loaded with another solution (with an href like solution). I want to be able to load another Applet, or a raw HTML solution, or whatever.
I suspect I need to wrap these solutions in something else like JavaScript, but wondering what would this solution look like.
Thanks in advance.
See Applet.getAppletContext().showDocument(url, target).
Note that it is not guaranteed to be implemented in the JRE/browser combo. the applet is loaded in, let alone work. That is where the JavaScript comes in. ;)

Retrieving a Java object (List) from a Win32 application

I'm creating a Win32 application that controls another application which is coded in Java using AWT components. I figured that if I can retrieve the main List of the application and cast it with the JLIB library I'd be able to read its content.
First of all, am I right or I won't be able to get the real content of the List ? If I'm right I'd like to know how to achieve this since I didn't found any good spy software for Java and Spy++ only show a SunAwtComponent. Which I presume in the container for the whole Java application.
I'm not expecting someone to tell me how to do the whole thing but only a couple of direction would be really great since I've been looking for that for a while now.
Thanks for the replies !!!
Quite likely the Java application actually uses Swing, not AWT. Swing draws its own widgets on top of a single AWTComponent, so the list widget that you see doesn't exist from Windows point of view.
I assume you cannot modify this Java application so that it can be controlled over some reasonable API (e.g. JMX or REST)?
You can try running the JVM with JPDA debugging interface enabled. You can then use JPDA APIs to change data structures and directly call methods on any object in that program. Finding the right ones to call will be hard, though.
See http://download.oracle.com/javase/6/docs/jdk/api/jpda/jdi/index.html

web-browser based GUI

I am working on an application in Linux which will interfaces with hardware. One of the requirements is to create the GUI in Web-browser . the application will be c++ based. I m not familiar with web realted stuff so i want to know Is it possible to do such a thing (currently it's a console application take input from txt file/cmd line). gui will be simple using button and showing output messages on browser from the application. i want to know which technologies/languages are involved and how can it be done. some of the idea i read but havn't found anything concrete yet. if u have any idea about these or a better suggestion please share
run the app in background and communicate with browser ?
call library functions directly from browser ?
any other idea ?
I would start by setting up a regular HTTP server, like lighttp or Apache httpd.
You say you already have a command line program that does the actual work - As a first step, I would reuse that, and configure the web server to call your program using CGI - see forexample http://httpd.apache.org/docs/2.2/howto/cgi.html for apache
Finally, I'd pick some javascript framework like jQuery or YUI with Ajax capabilities to do requests to the server to call the CGI script from within a webpage. You could also create a form-based web application without ajax or any framework, but that would require you to stuff all kinds of logic in your program to generate HTML pages. By using Ajax, you can leave the command line application as is, and parse any responses it gives with javascript, and then use that to dynamically change the webpage in a way that would make sense to the user.
If this all works, then I would try to figure out how to package all these components. Perhaps you just want to create a simple archive with all the programs inside, or maybe you want to go as far as actually embedding the webserver in your program. Alternatively, you may want to do it the other way around and rewrite your program as an ISAPI module that you can plug into your webserver. Or if that's not integrated enough still you could write your own (partial) HTTP server. That's really up to you (I'd probably spend time and energy on searching for the leanest, meanest existing open source http serverr and use that instead)
At any rate, the prior steps won't be lost work. Most likely, developing the web page is going form a substantial part of the work, so I would probably create a quick and dirty working solution first using the age-old CGI trick, and then develop the webpage to my satisfaction. At that point you can already have an acceptable distributable solution by simply putting all programs in a single archive (of course you would have to tweak the webserver's configuration too, like changing the default port so it won't interfere with existing webservers.) Only after that I would spend time on creating a more integrated fancy solution.
I ended up using Wt though I'd update for future reference.
These are how I thought of doing this, in order of complexity for me:
Create a simple server-side-language (PHP/Python) website that can communicate with (ie launch and process the return of) your application
Modify your application to have a built-in webserver that just punched out HTML (command line parameters taken through the URL)
Modify the app to publish JSON and use javascript on a simple HTML page to pull it in.
You could write a Java applet (as you've tagged this thread) but I think you'd be wasting time. This can be quite simple if you're willing to spend 10 minutes looking up a few simple commands.
After 12 years, web browser-based GUI started to appear, WebUI is one of them.

how can you make sure that your applet isn't being used outside a specific page url?

I have a java applet, I want to make sure that nobody use it outside a specific url. How can I achieve that?
The applet connects to a Java server for data exchange. I want to check on the server side the page url that contains the applet. Is that possible?
I have a java applet, I want to make sure that nobody use it outside a specific url. How can I achieve that?
You can't.
You can make it less easy.
Plain Java is trivially decompiled and manipulated by any decent developer. Even after obfuscation, it wouldn't be very difficult to circumvent any protection; changing "boolean checkAppletOrigin()" to always return true is not very difficult.
Think about what you are trying to achieve, and you might be able to find an alternative solution.
In your applet you can call the applet method getCodeBase() which will give you what URL the applet is running on pass that along with the data passed to the server that will give you a check that the applet is being run from where you wanted.
There are a few problems such that the web traffic to the server if not encrypted or protect somehow could be spoofed and this check could be gotten around. But it would be much harder to do then just reposting the applet somewhere new.

Categories