Developing a Java application that works both on the Internet and as an Android application?

I am working on a game that will work both on the Internet, in the applet, and on the Android phone, as an application.

Is this possible, and if so, what do I need to know about how to make this work (that is, if there are any settings that I should not hard code and instead define them based on the user device when the game is running or any java libraries that I shouldn't use?).

In addition, the game must accept the touch screen as an input for an Android application. Is it possible to build in the same game, which will also be launched as an applet? Maybe at run time the applet decides whether to use a mouse or touch screen to enter when it starts?

+4
source share
3 answers

Although Android applications are written in Java, the environment around the application is very different from the framework wrapped around an applet. You cannot have one .jar file that you can include as an applet and drop it onto your Android device, because that’s not how it works.

However, you can probably create all the game logic and objects and share them with the applet code and Android application. You can probably even leave with them in the same repository and project (although it will probably be an Android project, which you then wedge into your application build scripts).

To handle the various controls for your game, you probably have to abstract the input and your game / level object has a callback like userHasPoked (int x, int y), and then there is an applet call this method with a mouse click. and the Android application calls it when touched (which is oddly still called onClick).

I think it will be a long way, but much easier than rewriting it all. This probably sounds like a lot of work, but as soon as you finish wedging your code in the applet and Android app, you probably will never have to touch this code again and may just keep adding to the game,

I would not underestimate the task, but it sounds like a very funny programming exercise. Good luck

+5
source

What game are you developing? This may be the best approach to developing a Javascript game.

This can be installed from phonegap (cordova) to an Android device.

+2
source

Let me break it down for you ....

Model - Business Logic and Data

View - Display model output

Controller - the action is performed.

The advantage of using this MVC architecture is that you can keep the same model and keep changing the views .

Thus, bearing in mind this idea, you can have the same model for both a web application and an Android application, and then implement each other accordingly.

+1
source

All Articles