Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 19 of 19

Thread: Best way to port a Swing Application to Android

  1. #1
    Senior Member
    Join Date
    Jul 2013
    Location
    Europe
    Posts
    666
    Thanks
    0
    Thanked 121 Times in 105 Posts

    Default Best way to port a Swing Application to Android

    I have a finished Swing Application and I am thinking about porting it to android. The thing is, I dont know much about android, but I know that it does not support Swing. What a bummer.

    What would you recommend I do?


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Best way to port a Swing Application to Android

    Android GUI is very different from Swing.

    What would you recommend I do?
    Study the tutorials. Here are some links:

    http://developer.android.com/index.html

    http://developer.android.com/guide/c...damentals.html

    I ported a couple of very simple desktop applications to Android as a start to learning Android. I'd recommend starting simple and advance as you learn.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Senior Member
    Join Date
    Jul 2013
    Location
    Europe
    Posts
    666
    Thanks
    0
    Thanked 121 Times in 105 Posts

    Default Re: Best way to port a Swing Application to Android

    So you say I should port everything by hand.
    Is there no alternative which is less error prone and more handy?

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Best way to port a Swing Application to Android

    Not sure what you mean by "by hand". I don't know that there is a "converter" program to do it.
    Most of the GUI design and interfaces need to be completely redone.
    A desktop window has mouse and keyboard events. Android has that plus many different "touch" and other sense events. I'm working on an app now that needs to be sensitive to the device's orientation and to know whether the screen is on or off.
    Many different ways for the user to interace with the app. It's a Whole new world for me.
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Senior Member
    Join Date
    Jul 2013
    Location
    Europe
    Posts
    666
    Thanks
    0
    Thanked 121 Times in 105 Posts

    Default Re: Best way to port a Swing Application to Android

    Quote Originally Posted by Norm View Post
    Not sure what you mean by "by hand". I don't know that there is a "converter" program to do it.
    I mean I will have to learn the android API and start all over from scratch to create the entire GUI-code all over again.
    I already have a finished and working version, it would be really nice if I could just keep using that in some way, but when its not possible then its not possible.

    Its a real bummer though. I hoped java would be a little bit "more" cross platform if you know what I mean.

  6. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Best way to port a Swing Application to Android

    I mean I will have to learn the android API and start all over from scratch to create the entire GUI-code all over again.
    Yes, that is pretty much true.
    It's mostly the GUI that's new. For the apps I ported over, most of the non-GUI code copied and pasted into the Android project without any problems.
    If you don't understand my answer, don't ignore it, ask a question.

  7. #7
    Senior Member
    Join Date
    Jul 2013
    Location
    Europe
    Posts
    666
    Thanks
    0
    Thanked 121 Times in 105 Posts

    Default Re: Best way to port a Swing Application to Android

    Well, that sucks, I really hoped there woud be another way.

  8. #8
    Forum VIP
    Join Date
    Jul 2010
    Posts
    1,676
    Thanks
    25
    Thanked 329 Times in 305 Posts

    Default Re: Best way to port a Swing Application to Android

    The GUI needs to be created from scratch, but you can port the operational code by refactoring your Swing Application.
    To do this refactoring:
    1. Create a new project (let's call it: "Core")
    2. Move all operational code from your Swing project to your Core project and refactor the code so the Core project is NOT dependent on the Swing project (Core should have no reference to Swing whatsoever)
    3. Add the Core project to your Swing project's dependencies and connect the loose ends back up (your Swing Application should now work exactly like it did before refactoring)
    4. Create the Android GUI in your Android project
    5. Add the Core project to your Android project's dependencies and connect up the loose ends (your Android project should now be functional)

    This approach allows you to maintain a single code base (Core) for the operational code for both your Android and Swing applications. A huge benefit to this comes when debugging. If you have a bug in your Android app, and you cannot reproduce it in your Swing application, this would mean that the bug is located in your Android project, not your operation code (Core). If you have a bug in your Android app and you can reproduce it in your Swing application, this most likely means that the bug is located in your Core project. You can fix the bug once in your Core project, and you can then immediately release the fix for both the Android and Swing applications. A shared codebase means you only have to fix the bug in one place.
    NOTE TO NEW PEOPLE LOOKING FOR HELP ON FORUM:

    When asking for help, please follow these guidelines to receive better and more prompt help:
    1. Put your code in Java Tags. To do this, put [highlight=java] before your code and [/highlight] after your code.
    2. Give full details of errors and provide us with as much information about the situation as possible.
    3. Give us an example of what the output should look like when done correctly.

    Join the Airline Management Simulation Game to manage your own airline against other users in a virtual recreation of the United States Airline Industry. For more details, visit: http://airlinegame.orgfree.com/

  9. The Following User Says Thank You to aussiemcgr For This Useful Post:

    ChristopherLowe (July 16th, 2014)

  10. #9
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: Best way to port a Swing Application to Android

    Everything Norm said is true. If you're looking for an automagic way to convert Swing code to Android code, you're out of luck- as you should be, since Android is a completely different environment with different inputs.

    That being said, JavaFX supposedly deploys to both desktop and Android. I've never tried it myself though.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  11. #10
    Senior Member
    Join Date
    Jul 2013
    Location
    Europe
    Posts
    666
    Thanks
    0
    Thanked 121 Times in 105 Posts

    Default Re: Best way to port a Swing Application to Android

    Well, thank you all for the responses.
    The real problem is just, that the GUI was about 75% (or more) of all the work put into the project. The core functionality is incredibly simple. The thing is that the visualization is key as well as giving the user an easy and comfortable way of manipulating the underlying data.

    The Swing part is quite complicated with all kinds of custom Renderers and Models and about every kind of Swing component you can think of.

    I really was hoping there was some kind of standard way of doing it. After all, java is supposed to be cross platform and since Swing is part of the Standard Edition I just hoped this principle would apply to swing as well.

  12. #11
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: Best way to port a Swing Application to Android

    Quote Originally Posted by Cornix View Post
    I really was hoping there was some kind of standard way of doing it. After all, java is supposed to be cross platform and since Swing is part of the Standard Edition I just hoped this principle would apply to swing as well.
    Exactly: Swing is part of Java SE. Android isn't Java SE, it just "borrows" a lot of stuff from it (hence the lawsuits between Java and Google). It does not borrow Swing, since the graphics are very different on Android.

    More info here: http://en.wikipedia.org/wiki/Compari...nd_Android_API
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  13. #12
    Senior Member
    Join Date
    Jul 2013
    Location
    Europe
    Posts
    666
    Thanks
    0
    Thanked 121 Times in 105 Posts

    Default Re: Best way to port a Swing Application to Android

    Yeah, I read that already, thats why I asked here. Its a real bummer, I was very disappointed when I found out they did not include the complete SE.

  14. #13
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: Best way to port a Swing Application to Android

    Quote Originally Posted by Cornix View Post
    Yeah, I read that already, thats why I asked here. Its a real bummer, I was very disappointed when I found out they did not include the complete SE.
    In the long run, it makes a lot of sense. Swing is on its way out, and Android needs to keep up with the latest technological innovations. Swing probably isn't the way to do that.

    I've seen JavaFX working on Android, so it's at least possible. But really, if you want to be a good Android programmer, you should learn "the Android way" of doing things. It's really not that bad once you get used to it.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  15. #14
    Senior Member
    Join Date
    Jul 2013
    Location
    Europe
    Posts
    666
    Thanks
    0
    Thanked 121 Times in 105 Posts

    Default Re: Best way to port a Swing Application to Android

    I dont want to be a good android developer. I dont have an android device, I would not even be able to test it, but some of my users asked if the port would be possible so I wanted to do some research.

  16. #15
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: Best way to port a Swing Application to Android

    Quote Originally Posted by Cornix View Post
    I dont want to be a good android developer. I dont have an android device, I would not even be able to test it, but some of my users asked if the port would be possible so I wanted to do some research.
    Ah, gotcha. That sucks then. You could also use Android's virtual device feature which lets you deploy programs to a phone that displays on your desktop.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  17. #16
    Senior Member
    Join Date
    Jul 2013
    Location
    Europe
    Posts
    666
    Thanks
    0
    Thanked 121 Times in 105 Posts

    Default Re: Best way to port a Swing Application to Android

    I've heard thats not very accurate, people told me that the simulation is not quite the same as an actual phone and some programs run on one but not the on the other.
    But yes, eventually I think I will have to get used to it. Probably have to buy an Android just for work.

  18. #17
    Forum VIP
    Join Date
    Jul 2010
    Posts
    1,676
    Thanks
    25
    Thanked 329 Times in 305 Posts

    Default Re: Best way to port a Swing Application to Android

    The emulators are accurate enough. They are slower (normally), but functionally okay. You can configure the emulators to emulate specific devices to test with, so there is a lot to work with there without getting actual hardware devices. A program may run on some devices, and won't run on others. It depends on the Android version the phone uses and the Android version the program was built with.
    NOTE TO NEW PEOPLE LOOKING FOR HELP ON FORUM:

    When asking for help, please follow these guidelines to receive better and more prompt help:
    1. Put your code in Java Tags. To do this, put [highlight=java] before your code and [/highlight] after your code.
    2. Give full details of errors and provide us with as much information about the situation as possible.
    3. Give us an example of what the output should look like when done correctly.

    Join the Airline Management Simulation Game to manage your own airline against other users in a virtual recreation of the United States Airline Industry. For more details, visit: http://airlinegame.orgfree.com/

  19. #18
    Senior Member
    Join Date
    Jul 2013
    Location
    Europe
    Posts
    666
    Thanks
    0
    Thanked 121 Times in 105 Posts

    Default Re: Best way to port a Swing Application to Android

    Thank you for clarification.

  20. #19
    Forum VIP
    Join Date
    Jul 2010
    Posts
    1,676
    Thanks
    25
    Thanked 329 Times in 305 Posts

    Default Re: Best way to port a Swing Application to Android

    If you have a specific phone you are making the program for (or a specific group of phones), find out what version of Android they run, and build your program with it. If you do that, there should be no reason (apart from bugs) that the program should not run properly on the phone.
    NOTE TO NEW PEOPLE LOOKING FOR HELP ON FORUM:

    When asking for help, please follow these guidelines to receive better and more prompt help:
    1. Put your code in Java Tags. To do this, put [highlight=java] before your code and [/highlight] after your code.
    2. Give full details of errors and provide us with as much information about the situation as possible.
    3. Give us an example of what the output should look like when done correctly.

    Join the Airline Management Simulation Game to manage your own airline against other users in a virtual recreation of the United States Airline Industry. For more details, visit: http://airlinegame.orgfree.com/

Similar Threads

  1. Seeking Developer To Port Our Program To Android!
    By cdenczek in forum Android Development
    Replies: 0
    Last Post: August 28th, 2013, 01:48 AM
  2. Starting Android Application Development
    By MikeSki3 in forum Android Development
    Replies: 8
    Last Post: May 3rd, 2013, 07:54 AM
  3. Replies: 0
    Last Post: June 13th, 2012, 06:44 PM
  4. Relay data from remote port to local port
    By chegers in forum Java Networking
    Replies: 0
    Last Post: November 7th, 2010, 12:46 PM