Hi,

I am quite a competent c++ console programmer but I need to do some work with loading images and clicking on the images.

I want to load a screen full of images, click on an image and be able to retrieve the code, index or some value which uniquely identifies the image which I clicked on.

Is java the right tool? i need some direction to get started. Sample code would be a good jumpstart. i am prepared to read an experiment

Hi,

I am quite a competent c++ console programmer but I need to do some work with loading images and clicking on the images.

I want to load a screen full of images, click on an image and be able to retrieve the code, index or some value which uniquely identifies the image which I clicked on.

Is java the right tool? i need some direction to get started. Sample code would be a good jumpstart. i am prepared to read an experiment

well you can implement it in any language you wish. implementing in Consol C is a bit lenghty, since first you have to make function to load images bla bla.

I'd prefer to go for any High level language of your choice (C#, VC, VB, Java etc)

The logic behind this work is quite simple. you can either use a database or simple file (XML preferable). There will eb unique name for each image say "image1", "image2" ... if i talk XML then you'll have some tags like that

<image>
    <name="image1">
        <value>
        "any value you wish to have for that image to be loaded in your program"
        </value>
    </name>

    <name="image2">
        <value>
        "any value you wish to have for that image to be loaded in your program"
        </value>
    </name>

</image>

Now on image click you read the xml, match the TAG and read it's value. The same thing can be done using Simple File. Just make a structure like

class ImageDate{
    String name="image1";
    String value="data";
}

and write this data into file, you can then read those files and match the name to get value.

You can implement in Database as well. For this you have to do Database connectivity.
There can be a table

name: varchar(50) PK
value: varchar(50) NOT NULL

on selecting the image you can use the following query to search from the Db

select * from image where name = [apend it from the program]

Ok, let me see if I grasp this.

1. I have a directory that has for example 9 jpg images (img1, img2,..etc.).
2. I load these images on the screen from Java
3. Each image has a name and value record
4. When I click on the image, I trigger statements which writes this record to a file

My questions then are:

Does Java have some methods that would load an image to the screen? Do you know which package this function is in?

This "on-click", actually recognizes which of the images on the screen get clicked? Do I have find a way to determine the mouse pointer position on the screen when the click is made?

My questions are naive, I am sure. It is just that my programming experience is restricted to reading text files, processing them etc. I have no gui experience

Member Avatar for DaSogo

I know that you can load images into a JLabel. You can find tutorials online no problem. I used swing once to load an image into a JLabel for my background. It wasn't that hard to implement. As far as being able to click the images. You should be able to use java event handling and use an IF-else statement for control. From the control structure you should be able to retrieve the info you stored about that particular image.

yeah you can use JLabel and set it's icon. Then on ActionPerformed you can get the label of the image and can manipulate according to your choice. you have to go through the documentation of JLabel and EventHandling.

Thanks for all of your help!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.