I have Java code of the algorithm that has numeric values as its input and output. The GUI is implemented as Swing in Eclipse. Now I would like to tranfer to the web environment and create the web-tool using JavaScript or sth like this. Is there any way to use the Java code of my algorithm without rewriting it?
if your logic and goi all together at the same class you need to remove all the GUI part and stay with all the logic. after you have logic class you can use what ever goi you want(swing, html, jsf....)
Another alternative is to skip the HTML part by hand and just create your HTML app in Java. No need for separate servlets serving Java validation to your HTML inputs. The open source framework Vaadin that we've been working on since 2001 and it has an almost 100% similar API to Swing could be an alternative for this for you. And it would hopefully save you a lot of time.
As a swing developer the most relevant starting point for you would be: https://vaadin.com/swing
You can look up in to servlets and if you do it in netbeans then will be much easier for you.
Related
Good evening, I'm working on a project with a team, we have to make a browser without using JEditorPane or any other class that reads HTML.
How can we do that? Do we need to make a new class that does what JEditorPane does? Can I find somewhere JEditorPane's code? Thanks!
Well, this is an answer:
If you need to display web content without using any pre-existing engine (such JEditorPanel or a ChromeBind), you need to read the HTML as a XML file and construct your native View based on it (without CSS and JS this is a fairly easy task) by constructing the screen based on a one-to-one equivalent of a HTML tag to a Java JComponent.
Modern Web Browsers are pretty complicated, so there are a lot of different pieces that come together to display a web page. In order to build a browser, you need to first understand what a browser is. For that, I recommend reading this tutorial.
Once you have an understanding of how a browser actually works you need to determine which pieces you can reuse and which pieces you have to write from scratch. Do you have to write the entire rendering engine? Good luck! Can you use an existing engine like Gecko or Webkit? Or maybe you can get a little closer to done and use the java port of Webkit?
Once you have a better understanding of the question come back and ask more direct questions when you get stuck at a specific piece. As it is, your first step is to gain an understanding of the problem you are trying to solve.
I need to access HTML elements from my Java program based on the id or className of the element (like getElementByID or getElementsByClassName). I also need to be able to click a few buttons on the page.
Main Points:
I am creating a desktop application. It is not a web app.
I need a browserless solution
My code needs to auto fill a form and submit it without opening a page.
Are there any libraries out there that could suit my needs, or could I achieve this in plain Java code? If my question isn't clear please let me know and I will try to explain it in a better way. Thank you.
Selenium is a library used for scraping html elements using java. It is often used for testing. There is another library called Vaadin. It is used for doing front-end work on the back-end using java. It is similar to Java Swing but used on the web. Hope this helps!
I would like to know the best way and what it would require(languages/libraries) to generate Java GUI code from an HTML page with embedded Javascript code. It would emulate the HTML objects(like divs/tables) and their interactions. I don't need to emulate any complicated Javascript libraries, but just get basic functionality like handling mouse clicks/movements and key presses which Java can easily support.
I was thinking of representing all of the HTML objects using absolute positioning in Java without having to generate code for layout managers.
EDIT:
Regarding seand's comment: I meant that I don't need to convert code written in JQuery or other Javascript libraries into Java GUI code. I only want to deal with simple Javascript.
I was searching as well and it appears that nothing seems really meant to do that.
However one option is to embed a browser into your app using something like:
http://djproject.sourceforge.net/ns/
http://www.eclipse.org/articles/Article-SWT-browser-widget/browser.html
And then used it to load your HTML pages.
I am trying to build a search engine using java and the lucene API as part of a project. For the last step, we plan to build a web UI (a local host would do) for the same. Are there UI softwares/plugins for eclipse which will allow me to call the functions present in the java classes?
Essentially I would want to have a search box and a search key, pressing which will throw up the search results(which is computed from the java program). javascript cannot call java code I understand. So using that is eliminated?
Any suggestions on what to use will be greatly appreciated. I have pretty poor knowledge in front end design!
Cheers!
AB
If all you have is a simple screen with a entry field and a button and you simply want to return an html table. I would go with a servlet and two jsps. Your servlet can call your search engine and then have the jsp format the data into the table. If you do not know web apis this is probably the easiest entry.
I think, If your using JAVA, that you should look into JSF.
It's a rather easy to maintain and work with library for just the uses you describe.
I recommend these tutorials to get you started: http://www.coreservlets.com/JSF-Tutorial/jsf2/#Tutorial-Intro
There are lots of options to achieve this.
you can create web-ui using jsp.
I have also created same type of project using Lucene, here i have used spring mvc.i have provided all the back-end process as REST api which any web-ui can use.
Please do not look into JSF; it is an overengineered pile for your task.
Sure you can call your java code from javascript, you can make it really simple with something like DWR.
However, for your project I would suggest GWT as then you only deal with Java and it will generate javascript, html and css for you.
For your project you dont really need an "enterprise" level framework like spring or a fullstack JavaEE, you could keep it real oldschool with only JSPs and html/javascript. However thats a bit too flaky for my taste, so go with GWT.
With GWT you basically set it up, define your module, entrance point (look at the hello world), and then you add a layout to your page like something to place the searchbox into and the resultbox to. Then you call your other Java code and classes from there like you normally would.
I would suggest you to use GWT in your application because GWT enables you to call java methods and it will also convert Javascript and css for your Java modules after GWT compile.
GWT reference :- http://code.google.com/webtoolkit/gettingstarted.html
If you're going to use GWT, you could aslo check Vaadin.
Creating a search UI is really simple, and the tutorial show a criteria /result table application taht could be adapted.
Does anybody know of a pure java (ar at least cross platform) open source component/library which displays HTML which can contain swing components inside it?
All I could find were either abandoned or incomplete.
I am asking because I'm thinking about trying out approach to do use this combination for creating desktop application.
EDIT:Seems like this question is missunderstood, so let me clarify it. I basically want to create desktop application in the similar way as web. Idealy I would like browser to serve as an UI layer. That browser should allow me to embed my own compoents, eg to be able to use JTextField instead of <input type="text">.
Since I don't know of such easily usable browser, I was asking for a html component which will let me do it. I hop the question is clearer right now.
JEditorPane already supports what you want to do. It can render HTML (pretty crappily, I'll admit) and you can embed Swing components in that HTML using the <object> tag. Here is a blog post that demonstrates this technique: http://weblogs.java.net/blog/aim/archive/2007/07/index.html
Otherwise, I don't think you have a lot of options.
I think the question is the other way around or, better, goes further than using JTextPane. As I understand the question: Marko needs a Java component that can display HTML and additionally is able to contain further Swing components. Say, there should be a new tag
<swing jclass="MySwingComponent" />
which would render that MySwingComponent class. Not sure, maybe it would also be okay to have a HTML-able Swing component that can embed further applets?
And no, I don't know of such a thing. Sorry.
JavaFX maybe?
check out xhtmlrenderer: https://xhtmlrenderer.dev.java.net/
You will have to work wit it to get it to do all you want.
I thought Google Web Toolkit allowed you to write a UI in terms of Java/Swing. It would then convert it to JavaScript. Maybe that's what you're looking for.