?
Solved

Swing GUI - Image contain id# of database element

Posted on 2003-03-26
4
Medium Priority
?
181 Views
Last Modified: 2010-08-05
Okay, I wasn't sure how to title my question but I think that one fits.  What I am trying to do is query a database (Oracle) and select the id#, first name and last name of users.  I can do this with a simple SQL statement.  I then want to display all the current contacts in the list but first and last name (alphabetically by last name) and beside those names there are icons which say View, Edit, Delete.

IE/

Bill Adams    VIEW  EDIT  DELETE
John Doe      VIEW  EDIT  DELETE
Bob Zee       VIEW  EDIT  DELETE
etc

I understand how to access the names and know how to print the data off into a normal terminal screen by using a very basic while loop.

while(resultSet.next()) {
     System.out.println(resultSet.getString(1) + " " +
          resultSet.getString(2));
}
and that prints the names just fine.  I believe I have an idea on how to do that with the GUI as well but haven't fully tested it out.  What I need to know is how do I set it up so that the same 3 images appear for all the names but so that each image is uniquely identified to the name it appears beside.  I was thinking of doing this with the id# but I know that images cannot hold this other information.  Another idea I had was to store the images in the database along with the names but this would be an extreme waste of space because all rows in the database would contain the same image.
I need it so that if I click on VIEW for instance for the name John Doe I would get all of the information from the database that is listed under John Doe.

Any help would be great.  Thanks.

Let me know if I didn't make any sense I'll try to explain better.
0
Comment
Question by:Cujo_34
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 2

Accepted Solution

by:
glottis earned 225 total points
ID: 8215492
You did make sense :P

In GUI if you want to display the results there are many options.

1.
You could try printing the data in a JTable. SO basically a JTable would contain 6 columns like:
|id|fName|lName|edit|delete|view
in the first 3 columns you can get the results from the query, and for the last 3 you can display the images. Then you can add a mouse listener to the JTable and see on which row the mouse was cliked. then from that row get the value from column 1 that is the, then you can simple query the database again like select * from table where id=value;
To accomplish this you would be using you own tableModels, and cellRenderers/

2.
You could display the result in a JList. After you query the database you can create a local record of the results return, for eg
class Users {
  private int id;
  private firsName, lastName;
  public Users(int id, String fn, String ln) {
    this.id = id;
    firstName = fn;
    lastName = ln;
  }

  // create setters and getters;

  public String toString() {
    return lastName + ", " + firstName;
  }
}

then you you can add these Users to the JList and can have only three JButtons with the respective buttons and their own listeners. On their actionListeners you can see which record is currently selected in the JList, get that User and getID() of that user and do you sql statements again.

I hope you get the picture.
0
 

Expert Comment

by:bhayzone
ID: 8216316
just a small suggestion ... you'll have to figure out the implementation urself ... i think its possible

What you can do is use JButtons and set the images as the background of the JButton. You mite have to extend the JButton class and tweak around a bit. If you manage to get the JButtons working ... your problem is solved.

One advantage of this JButtong approach is that you will be using fewer objects ... if you can have the background image as a static Image object .... there will always be just one Image object irrespective of the number of JButtons.

See if that can be implemented.
0
 

Author Comment

by:Cujo_34
ID: 8232323
Hey Glottis,

Thanks for the answer.  I've been coding on and off and have it functioning okay I guess.  Having troubles with getting the images to be displayed in columns but that's secondary now.  I'm just going to finish the rest of the codin and if time permits add the pictures (currently just using words).

I used the JTable method in case you were wondering.  It was the first one I saw so I thought I'd try it first.
0
 
LVL 2

Expert Comment

by:glottis
ID: 8234931
After you have used JTables, you would find using JList easy too, because their functionality in customizing works sort of the same.

and your welcome :)
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
Suggested Courses
Course of the Month9 days, 1 hour left to enroll

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question