Use JFrame (or external equivelant) on Android - java

I'm working on a small 2D tile-based game prototype for Android in Java. Unfortunately, I don't understand Android nearly as well as straight Java, and JFrame-based methods are perfect for what I'm trying to do. I've already done some research, and the general consensus is that it's impossible... But JFrame is exactly what I need. Is there any way at all to use it, or at least an external library that recreates it's functionality?

In a word -- no, you can't use any Swing component related classes whatsoever with your Android application as they are structured and rendered completely differently. You can only use your model classes if they are well behaved, and you'll of course have to learn the Android library/platform.

Related

reusing android code (native Java) in a frame inside web app or desktop app

as per this answer it is possible to reuse android java code inside web app or desktop app frame.
so how its done step by step?
I wonder if there is a special tool to do so.
I don't think there is a complete tutorial, as it's tedious work. The example you linked shows
Android -> Swing conversion. So I will illustrate this with some examples:
If you have a View in your android app, you replace it with JPanel for swing.
If you have a Button, you replace it with JButton
Sometimes elements may look similar, but they do different things, like CardView and CardPane. This complicates things.
There might be android Views that has no matching pair in swing, so you will have to improvise there
But it's not this simple of course. Setting the properties of the views is going to be completely different. Moreover, Android uses XML, while in Swing you have to set everything programmatically.
The only thing common is basically they are both built on Java. So my best advice is that you shouldn't try to "convert" your code. Maybe you can reuse some pure Java parts, but other than that, I suggest you re write the application using the other platforms tools.
you can't use android code in web app or desktop,
first you have to separate the business code from the ui code
the business code can be in a pure java module (completely reusable)
when i speak about business code i mean network calls (using retrofit for example) and any code that is pure java ..
the ui and android specific code (like Views ...) should be rewritten entirely because will not have access to android packages containing views (recycler, layouts...)

How to implement basic 2d graphics/use them in java

So as you can probably tell from my question I am very new at all of this. I am creating a small "particle simulator" (really just gravity thing). I am modeling both X and Y positions. My question is how do I incorporate graphics. I don't really care about re-working my existing code (in java application format). In my prevois research I came along Jquery and Css but I am not sure on how to implement either or them. Also in researcher I found java graphics but I am not sure on what or if library's are involved in making that would I only found commands. I have used them before but that was in a fake environment(codeacdemy). I have created a small GUI in netbeans using a Jframe. That leads into a somewhat second question of what would I use in a GUI to have something graphically involved.
here's a tutorial on how to use graphics in java:
http://docs.oracle.com/javase/tutorial/uiswing/painting/index.html

Possible ways to create console like screen in java

I am trying to create a screen like this one
Initially I was trying to port a console program to java. I have found things like jcurses and charva but there is almost no documentation on them and I really cant understand how to use them.
So I figured that I could create a console like screen that resembled the one above.
what library / framwork would I be best using. Should I use swing as it if fully portable?
what would be the best approach being that I need to be able to navigate and alter the 00 in the picture above?
Easily usable would be great but as long as it has good documentation that I can learn it from that would be fine.
(Answering as if you're looking for a hex editor.)
http://jhecomponent.sourceforge.net/
http://www.fifesoft.com/hexeditor/
http://hexedit-lib.sourceforge.net/
Played a bit with the fifesoft.com offering, kinda cool.
If you're not looking for a hex editor, can you be more specific? If you just want a cursor-addressable window you'll probably have to suck it up and figure out something like jcurses or libjcsi :)
If you prefer to create a full fledged GUI with Java you could certainly use Swing. I would prefer SWT as a matter of personal taste, the widget library of Eclipse. You will find a lot of snippets and tutorials (same for Swing). Here is the Widget Library.
Here is a discussion about SWT versus Swing.
You could use the table layout manager to create the layout shown in your screenshot. If you rewrite the application from scretch, you should be able to handle the GUI events and update the widgets according to your application needs. You will easily find articles when you search for swt and table. If you would like to keep the code base and just exchange the GUI, I 'm not sure about the best approach. Maybe, the libs jcurses and charva are the way to go.
Unless you are looking to run the app on a headless VM (where a console/tty is all you've got), I'd use Swing. Create a JTable with a custom TableModel (to provide the data) and custom renderers (to provide the hex formatting) and everything should just work. Consider deriving from the various DefaultXXX implementations to save a lot of work.

Genome browser built in java: Swing and awt or Swing and Processing?

I'm writing a genome browser designed primarily to view the history of chromosomal rearrangements. Right now the project is a series of proof-of-concept demos written using Processing. At this point if I don't make any radical changes the final application will be a web applet with a gui built of swing components that open PApplets to actually show the rearrangements happening.
My question is: Should I give up on processing and switch over to pure Swing/AWT? This is my first big java project. I'm building in eclipse, but I can use netbeans as well. If I could embed PApplet objects inside a JFrame, for example, that would make my day.
processing.core.PApplet extends java.applet.Applet, so it should be possible to embed
a PApplet in a java.awt.Frame, as discussed in the article Applet ⇒ application: Hybrid Switch Hitters. See also, Mixing heavy and light components.
Addendum: From the API, "Processing runs in a Frame and not a JFrame. However, there's nothing to prevent you from embedding a PApplet into a JFrame," except for the limitations mentioned above.
Keep in mind that I know almost nothing about either Processing or your project, so I can only give you general advice.
The question that you should ask yourself before every major design change: what problem am I trying to solve by making this change? If the current architecture works, then you should keep it. If it's not working, then you should start by defining the specific things that are wrong with it (which I notice you didn't do).

Converting equations to java for android?

I am a cameraman and I want to make an app for my Moto Droid that will
calculate my depth of field given four inputs.
I am literally brand
new to javascript and this programming stuff, so I was wondering if
anyone could help me out.
I have a very basic GUI set up using Droiddraw which allows me to
input my 4 variables, which are:
Focus (#+id/focust)
Focal Length (#+id/flt)
Aperture (#+id/apt)
Circle of Confusion (#+id/coct)
Equations for this calculation are located here
for example...
to get hyperfocal distance I need to get: ((f^2)/(N*c))+f
all of these variables will be drawn from inputs in the GUI, but I don't know how to call them, how to write the actual math, and how to address the results so I can make them appear in the "results area" on the bottom of the screen.
I've never done java before and I only want to make this app because the existing ones don't fit my needs.
Can someone help?
Thanks!
If I'm not mistaken, DroidDraw is a tool for building the XML user interface description used by the Java API. If you want to program for Android in JavaScript, something like PhoneGap might be a better choice. It lets you build real Android application using HTML and JavaScript.
On the other hand, if you want to use the XML and Java APIs, then you should probably run through the Android tutorials. The first one is Hello, World.
Since you're just getting started with programming, I can't stress tutorials enough. It's true that your idea shouldn't be too hard to implement, but you need to understand the basics first.
I don't mean to give the impression that one style (PhoneGap vs. Java and XML) is better. For your purposes, either should be fine. It's more a question of what you prefer. Java/XML is the paradigm supported by Google, and provides access to more functionality. On the other hand, if you already know HTML or JavaScript (or are interested in learning them), PhoneGap will certainly provide everything you need. I think PhoneGap is also intended to make it easier for beginners, though I haven't used it, so I don't know how successful they have been.
The XML file that is generated by DroidDraw can't be used within PhoneGap. If you do choose to use PhoneGap, then you will need to build the interface in HTML. You might be able to use something like DreamWeaver or FrontPage or one of any number of HTML editors to help you with this step.
The XML file is just a description of an interface. When you start your application, the Android platform uses this description to build the user interface that you see. Once that has happened, you can move data from the interface to Java, or from Java to the interface, without any hassle. You certainly won't be limited by the XML interface description - it's pretty flexible.
If you've been going through the Android tutorials, then it might be best to forget that I even mentioned PhoneGap. It's a wildly different alternative that is the right choice for some people and some applications. But the Android tutorials won't help you to understand it. I only brought it up because you mentioned JavaScript in your original post.

Categories

Resources