I have a pretty complex Java (JDK 6) code that needs to be converted so it works on Android. That Java code is intended to work with graphics: thus i have a class that extends JLabel (Swing component), "paintComponent" method reshapes that extended JLabel ("cuts" it to look like a circle) and draws it on the screen (i know, i know - i might use come "drawCircle" method but i need to extend JLabel because it has some popup menu attached to it).
Now, i have a problem - Android don't seem to have "Graphics" type, "Dimension" type, "Rectangle" type, "paintComponent" method and after all, i have no idea what control should i use to draw those customized JLabels on (in JDK 6, i have used JPanel that was container for those customized JLabels).
Please help! I need some advice on what would be the most painless method for converting given Java logic to Android logic?
Android provides Graphics and 2D Graphics, used for drawing.
Have a look at Shape Drawable which should assist you in drawing rectangles. Instead of JLabel use TextView. You will have to spend some time in getting to know Android and redrawing your GUI, but I hope I provided some good starting points.
Also note that depending on complexity of your code, you may not be able to use all your Java code, becase Android doesn't provide full Java version.
AFAIK Android doesn't support Swing, so you're going to have to use equivalent Android UI classes. The android UI classes are not a 1-to-1 match with Swing classes, so sometimes an Android port means you need to do a pretty heavy UI rewrite.
Android do not have JLabel, so you can not use this code.
Instead use TextView . You can declare TextView in xml or in java code
Related
I can change the location of a JButton, but I can not change the title. Is it possible that the java file is corrupted? How come I can't change the title while changing the location? I use Eclipse...
The width of the button is too short to display the title (15 pixels). As a fallback, the … is shown.
In addition, I highly recommend not to use the setBounds method directly. Take a look at a Java Swing tutorial on Youtube, Vimeo, Udemy, or as a book. You will learn how to create a user interface with layout managers. You won't have these kinds of problems then.
You might want to consider learning JavaFX instead because Swing is end of life.
I have a Swing custom control which serves an almost identical function to a JLabel. It's not accessible by default for people who use assistive technology, like a screen reader. I'm working on the Megamek GitHub Project, and trying to figure out how to associate the PMSimpleLabel class with other objects, as in the JLabel class's setLabelFor method.
The approach taken so far seems to be to more or less ape the JLabel's accessibility implementation. I'm not sure if this is the right way to go about it, there seem to be some elements in the latter I'm not understanding.
The problem turns out to be largely because of the custom components. The AccessibleJComponent class has a fallback mechanism to name controls which don't ohterwise have accessible names, but this is hard-coded to look for a JLabel and not a custom label class.
There are a few work-arounds for this, such as modifying the get/setAccessibleName methods, or switching to using the accessible description instead.
The solution in the long term is probably to use regular Swing components where possible
I found this post on the site:
Blackberry Clickable BitmapField
explaining a class where you can draw a clickable bitmap. This is exactly what I want to do but the issue for me is that I'm quite new to Java and I don't know how to properly call this statement. What are the commands to create this bitmap? So far all I have is:
CustomMenuButtonField buttonInstance = new CustomMenuButtonField("img1.png", "img2.png");
aside from that I don't know how to make the drawing appear. If I try:
buttonInstance.paint(graphics);
I need to declare graphics which I am not sure how to do. I've checked the API but its still a bit confusing to me. Also where should these call statements be used? In the userInterface constructor?
Once you create your custom button field, you just need to add it to your screen:
add(buttonInstance);
It will then be displayed by the framework automatically. For more info, see the Getting Started Guide for the SDK version you are using in the Development Guides.
I am developing a small desktop application in Netbeans. The application is complete and working fine. A small description of application is as follow:
The application is basically an object manager, where user add new object, remove old objects and connect object with each other. What i did is that i simply add 3 panel and change its type to titled border. One for Add object one for remove and one for connect.
Status:
Every thing is working fine as expected.
What Left:
In order to make UI more appealing i added a new panel at the end and called it "Object Viewer". I am planing to visualize the steps which user performs e.g
If user add an object then i that pannel i will daraw a little
circle and fill it with green color
Similarly if user remove some object then again i will draw another
cricle and fill that with red
And when user connects two object then i will draw two circle and
connect them with a dotted line
This is my first java application, i only want to know how do i acheive this task. Some links or experience are highly appreciated
As for custom painting in swing, have a look here: http://download.oracle.com/javase/tutorial/uiswing/painting/
However, I'd suggest using a graph visualization library like JUNG etc. Using this you'd basically only have to define your object graph.
You can either do that manually with Java 2D, which I don't recommend, or, since you are using Netbeans (and I assume the Netbeans Platform, but this is not required), I would strongly suggest looking at the Netbeans Visual Library. It can do exactly what you want.
As Nico Huysamen said you can do that with Java 2D. But because it's your first Java application I strongly recommend to do it manually with this lybrary in order to understand how higer level lybraries work.
The company I work for has an java application that runs on esmertec jbed JVM on windows mobile 6.
There is a requirement to capture a user's signature as part of some new functionality. One option is to try and implement this in java. This has been tried previously and has been found to be a bit slow.
I think the better option would be to get a native component to handle the drawing of the signature and save it to file. Does anyone know of a component that I would be able to use?
Creating our own component is an option as well but if there is one available already, I would prefer to use that.
For completeness, I'll answer my own question.
I could not find an existing component that done this. We ended up writing some c++ code that would handle this.
The code would get a handle to the Java canvas and register our own callback function with it. This callback function would record any mouse movement within the canvas and draw a line when necessary (either on mouse up or after a number of points had been drawn). Once the user leaves the screen we would save the canvas to file and re-register the original canvas callback function.