Calling a Bitmap Class in Java - java

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.

Related

Creating a line on a DrawingCanvas in Java

I am trying to use the Williams objectdraw library (http://eventfuljava.cs.williams.edu/library/objectdrawJavadocV1.1.2/index.html) to make a line on my drawing canvas. I am very new to Java and am unsure whether I am setting it up correctly. Attached is a screenshot of what happens when I run the code.
You have extended WindowController,i think you are suppose to extend Applet..
http://spot.colorado.edu/~cathyb/hiapplet.html have a look at this page it will be useful.

FancyOverFlow on swipe listener

Im using this library to create a gallery,and im kinda new to android programing but i want to add a listener to when the user swipe down the image it will be deleted.
thanks for the helpers,and if you didnt understood me tell me to rephrase.
Ok, since you haven't tried anything, and thus you don't have a specific question, all I can do is trying to point you in the right direction (I hope).
I suggest that you do the following:
1) Setup the library: take a look at the examples provided by FancyOverFlow.
2) Make sure that you understand what is going on about the code that you use, don't add code "just because it works". Do this as a rule of thumb for every code that you write. If you are using a 3rd party code library, you don't have to fully understand how every method works internally, but make sure that you understand in/outputs of the methods you are calling. Understanding how things work will make it much easier to modify your own code.
3) Find out which component has the hold of your current image in displayed gallery. This will be the control on which you will set up a swipe listener do detect user swipe moves. I haven't tested this, but I suspect taht in this case the component is called FancyCoverFlow (take a look at README.md file).
4) Take a look at Swipe Views (or any tutorial that does swiping) and adapt your code.
If you are new to Android, it may take a while, but don't give up!

Using java Robot class

I want to write an address in the address bar of a browser as well as click on a link using java Robot class. How can I track the different objects in a certain window?
Just giving a look at the API http://docs.oracle.com/javase/7/docs/api/java/awt/Robot.html, anyone who do this should know that via Robot Class there is no "trackComponent(Component specificComponent)" method, you got 2 things that may help you:
1-getPixelColor (more than help, seems useless for you by now, maybe i'm wrong).
2-createScreenCapture.
the second method is maybe the answer for your problem, you could take a picture of the screen and with some image processor (javaCV could help you on this: https://code.google.com/p/javacv/) you could then track the components on the screen you took (for instance: from pixels xxx to pixels yyy is the Address bar of browser), of course you need to read some documentation about javaCV (OpenCV) for get this done, after that just use the method for move cursor and enter keys for fill the components, hope someone give a simpler way to do this, but i think this way you learn a bit of JavaCV a really powerful tool.

Java to Android conversion problems

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

Overriding AnalogClock in Android

I want to create an AnalogClock that can display a preset time, given as a parameter.
And I want to draw between the background and the hands. I want to paint the area between the minute-hand and location of the hour-hand at a preset future time. This is to let the user see how much time remains for the current activity.
I thought that I could take the AnalogClock object and extend that. However, when I create a new function that is essentially a copy of one of the old ones, I get errors on the com.android.internal.R.styleable.AnalogClock* objects: "com.android.internal.R cannot be resolved"
How can I import these objects? I've read something about declare-styleable, but I cannot figure out how to apply that to my situation. (Sorry, I'm really a Java n00b)
For instance, the internal objects refer to several graphical things, such as dials, hour_hand and minute_hands.
Here's my code: http://pastie.org/713276
Any help is very much appreciated, I am stuck after hours of Google.
Here is an tutorial for creating a custom Analog Clock. Shows some sample code, hope this is at least a start in the right direction.
Set time with custom android AnalogClock from its original class Please have a look at my solution. You can use it to display a custom analog clock in a application and set time that you want in it.

Categories

Resources