can we run two applets concurrently - java

i want two use output from one applet as an input for another applet running in parallel..

There is no problem to run as many as you want applets simultaneously on one page. But you wish to make applets communicate with each other.
Each applet can access applet context that has API to access other applets on the page:
applet.getAppletContext().getApplets()
applet.getAppletContext().getApplet("appletName")
Then you can call any public method you want.

Like AlexR said, you can run all the apps you want(as long as CPU can handle it). Another 2 options for communicating between them would be
1: To use the 'Model-View-Controller' Design Pattern described in the book "Advanced ActionScript 3 with Design Patterns."
2:Create an Applet that will Encapsulate all the other applets, then with this applet start up all the other applets. Inside each applet declare an instance of each (applet)class you need it to communicate with then create a set method for it. now from your Encapsulating class use the set methods to pass the instances of the applets to each applet that needs it....(yes, I know it's confusing but it works well if you get it right)

Related

Java Web Application AWT or Swing?

When developing a Java web-based application, is it necessary to use AWT?
I've been researching this question and the answers are confusing. Take for example, Runescape. The user visits the website and can play the game right there. They can also download a desktop application to play the game with.
If I am developing a game application, and my main window is created in a JFrame but all of my graphics are processed in a JPanel inside the main window, will I be able to implement this inside of a web page without much difficulty in the future? I want my game to be accessible simply by visiting the website and running the application.
Additionally, I've seen people reference "Java Web Start". Will this load the java application inside of the website, or does it install/run Java and execute the program (so if my main function opens a JFrame, it would appear on your taskbar). Perhaps I'm having some confusion between a Java application and a Java applet.
..will I be able to implement this inside of a web page without much difficulty in the future?
No. The security environment around applets was made much stronger in recent times, but even then, browsers tend to put further hurdles between applets and 'onscreen, loaded applets'. Chrome is set to remove the plug-in which would normally embed applets and a few other things.
I want my game to be accessible simply by visiting the website and running the application.
Additionally, I've seen people reference "Java Web Start". ..
Yes, offering a link to a JWS launched JFrame will be a lot easier, and a better experience for the end user.

Call Applet methods from outside the browser

Here's the overall flow of the use case:
User navigates to page with a third party applet
Another program sees that the browser URL has changed and fires a custom Java app that I have written.
That custom app needs to be able to call methods on the Applet
Is it possible to call the Applet from an application outside of the browser?
I've seen lots of questions and answers around calling applets from JS in the page, but that not the case here. That being said, however, if it were possible to inject JS into the page at runtime and have THAT make the call to the applet, that might be a workaround.

Looking for possible strategies for avoiding applet reloads

I've implemented an interactive map applet, which is embedded in a web application. The application uses some Ajax, but has a predominantly page based structure.
The problem is, navigating away from and back to the page containing the applet causes an applet reload, which takes several seconds.
Possible ways to alleviate this problem I thought of are:-
Make the applet run continuously in a separate browser window (I lose integration with the main web app though)
Convert the web app to use Ajax exclusively to avoid page reloads
Implement the map view as a standalone desktop app
If there is some way of preventing applet reloads in the browser I would be very interested to hear about it, but I don't think this is possible due to the applet lifecycle.
I think that you enumerated all options, their advantages and disadvantages.
I'd like to suggest you a combination of options you suggested.
You can separate you applet into 2 components. First, heavy-weight application that will be started using a java web start. It will contain all application logic and will run in minimized (or even transparent) window. It will prepare image and send it via network to light-weight applet that just shows it.
I this case you do not loose your application integrity: map is shown in browser. The applet is very light weight, so it starts fast. The stand-alone app implements the most of programming logic.
Here is how to make window transparent: http://java.sun.com/developer/technicalArticles/GUI/translucent_shaped_windows/

How to invoke an applet from within a a piece of code?

I am making a simple examination app! The questions for various examinations will be present on the server. The clients will access them using RMI, and the UI for client side is being implemented in Applets! (that's according to the spec of the project!).
I want to have multiple applets for various stuff! I want to be able switch from one applet to other depending on the return value of the methods called on the server. I also want to be able to pass information if necessary!
Please tell me how can I do it!
An applet is equivalent to your workspace. You generally have one JApplet per application.
Now, you can have various JPanels within your JApplet. These JPanels can switch depending on the return value of the methods called on the server.
This Oracle tutorial should help you get started: How to Make Applets.

Block all other input to an application and control it from a wrapper in Java

I have a windows application which has a complex GUI that I would like to hide from users. In order to do this, I would like to create a wrapper with an extremely simple interface that overlays this application and automates a number of actions when a user clicks a single button on the wrapper. (I hope "wrapper" is the proper term.) Is it possible to use Java to block input to the underlying application so that users cannot inadvertently mess up the automation? How would I go about this? Also, how can I automate key presses and clicks to the application without hijacking the mouse? Is this possible in Java?
I have looked at java.awt.Robot, but it appears to hijack the mouse.
I have also looked at AutoIT, but it too hijacks the mouse and does not integrate with Java.
Neither of these options seem powerful enough for what I need, but I do not know how else to proceed.
I recommend that automation via the GUI only as the last resort if you really have no other alternative.
If there is an API that your application exposes, I would try to use that. For example, if the GUI is implemented in one DLL and the logic in another, then you can use JNA to load your application logic DLL and invoke the application functions directly from java. Even better would be if your application exposes a COM/OLE interface - there are plenty of Java<>COM briges, that will alow you to call this interface directly, e.g. Jacob.
If you really have no choice but to automate via the GUI, then here's how to go about doing that:
Use JNA to access the windows shell API. You can then use ShellExecute to launch your wrapped application. Specifically, passing SW_HIDE as the window mode should help ensure that the application does not appear.
Use JNA to access the windows API FindWindow to find your application window. You can also make it invisible using the ShowWindow API, just in case step 1 did not work (not all applications are written to use the nCmdShow parameter.)
You can now post messages to the application window using PostMessage. You can send keystrokes and mouse events using windows messages. E.g. See WM_KEYUP, WM_LBUTTONDOWN.
Because the wrapped application window is made invisible, you don't need to "block" that application, The user simply cannot access it's GUI. But you can still programmatically send input to it.

Categories

Resources