Ali
Ali

Reputation: 267187

Developing a Java app that runs both on the web and as an Android app?

I'm working on a game which would work both on the web, as an applet, and on the Android phone, as an app.

Is that possible to do, and if so, what do I need to be aware of to make that work (i.e if there are any settings that I shouldn't hard code and instead determine them based on the user's device when the game is run, or any java libraries that I shouldn't use?).

Also, the game needs to accept touchscreen as input for the Android app. Is that possible to build into the same game which will also be run as an applet? May be so at run time, the applet decides whether to use Mouse or Touchscreen for the input when it is run?

Upvotes: 4

Views: 169

Answers (3)

Kumar Vivek Mitra
Kumar Vivek Mitra

Reputation: 33544

Let me break this for you....

Model - The Business Logic and Data

View - The Display of the Output of the Model

Controller - On which the action is done.

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

So keeping this idea in mind, you can have the same model for both the Web App and the Android App, and then implement each others Views to it respectively.

Upvotes: 1

Christian Kuetbach
Christian Kuetbach

Reputation: 16060

What kind of game do you develop? It may be the better approach to develop an Javascript game.

That can be installed with phonegap (cordova) onto an android device.

Upvotes: 2

xbakesx
xbakesx

Reputation: 13520

Although Android apps are written in Java, the framework around the app is extremely different of the framework wrapped around an applet. You won't be able to have one .jar file that you can include as an applet and throw at an Android device because that's just not how it works.

You will however probably be able to create all the game logic and objects and have them in be shared with the applet code and android app. You can probably even get away with having them in one repository and project (although it's probably going to have to be an Android project that you then wedge in your app build scripts).

In order to tackle the different controls for your game you are probably going to have to abstract away the input, and have your game/level object have a call back like userHasPoked(int x, int y) and then have the applet call that method on click of the mouse and the android app calls it on touch (which is oddly still called onClick).

I think it'll be a long road, but much easier than rewriting the whole thing. It'll probably seem like a lot more work up front, but once you are done wedging your code into an applet and an Android app, you'll probably "never" have to touch that code again and can just keep adding to the game.

I wouldn't underestimate the task, but that sounds like a very fun programming exercise. Good luck!

Upvotes: 5

Related Questions