Marc Kryzhan

Greenhorn
+ Follow
since Mar 17, 2004
Merit badge: grant badges
For More
http://geocities.com/kryzhan/
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Marc Kryzhan

Thanks for your help. I am now able to get one ImageIcon to display in the correct container.

I get the ImageIcon, that is represented by "ZO6", to appear in the correct container.
[B]My Problem is I'm not able to cast in ,[/B] in place of "Z06" because this method will not take a type Object.

My method in AutoInventoryModel (grabbed as new instance represented by autoInventoryModel) that I'm calling to grab the row and column of the JTable is:


Thanks for any help.
Marc
[ April 08, 2004: Message edited by: Marc Kryzhan ]
[ April 08, 2004: Message edited by: Marc Kryzhan ]
[ April 08, 2004: Message edited by: Marc Kryzhan ]
[ April 08, 2004: Message edited by: Marc Kryzhan ]
[ April 08, 2004: Message edited by: Marc Kryzhan ]
[ April 08, 2004: Message edited by: Marc Kryzhan ]
[ April 08, 2004: Message edited by: Marc Kryzhan ]
[ April 08, 2004: Message edited by: Marc Kryzhan ]
[ April 08, 2004: Message edited by: Marc Kryzhan ]
[ April 08, 2004: Message edited by: Marc Kryzhan ]
19 years ago
I am puzzled about getting an ImageIcon to appear in one container when a row is selected in a scrollable Jtable from another container (I easily get text to appear in the container):
My setup:
- I have a new JLabel called pix inside a JPanel called PixContainer.
- I also have JTable called AutoScrollTable which is defined as a JScrollPane inside a JPanel called AutoContainer. The table has 4 columns of information taken from an xml document. Important from the xml document is a model type which is the key to 7 pieces of information. One of the seven is the name of a .jpg for a vehicle.
- I have some images (10 of them) of different sports cars and I already created ImageIcons out of them.
My two methods in a class called AutoImageUtils, one to set up and one to hopefully grab the imageicons:
// To get image icon with a key I provide from my Event Handler
public static ImageIcon getImage (String key) {
ImageIcon ii;
ii = (ImageIcon) autoImages.get(key);
int siz = autoImages.size();
System.out.println("8 888888888 AutoImagesUtils::getImage key/ii/size= " + key + " " + ii + " " + siz );
return ii;
}
//* Returns an ImageIcon, or null if the path was invalid. Name is resolved to a URL.*//
private static ImageIcon createImageIcon(String path, String description) {
String fullPath = "../images/" + path;
java.net.URL imgURL = AutoImageUtils.class.getResource(fullPath);
if (imgURL != null) {
System.out.println("createImageIcon:URL " + imgURL);
return new ImageIcon(imgURL, description);
} else {
System.out.println("Couldn't find file " + fullPath + " with URL " + imgURL);
return null;
}

My event handler which is where I'm having trouble is in a separate class which also contains the containers, my Jlabel pix, and my Jtable:
class ListSelectionHandler implements ListSelectionListener {
public void valueChanged(ListSelectionEvent e) {
// column "1" of the JTable is the model (or type).
final int TYPE_COL = 1;
// get the index (row number) that is selected in the JTable
ListSelectionModel lsm = (ListSelectionModel)e.getSource();
int selectedRow = lsm.getMinSelectionIndex(); //the current selection

System.out.println("ListSelectionHandler() Index/row= " + selectedRow);


// Problem One: using this row number, I want to get the key that is used to find the image.
// Like I said the key is the model(type) because it's unique.
//* Below I forced in a key by using the model type of one auto, the Z8. My return from getImage was expected [8 888888888 AutoImagesUtils::getImage key/ii/size= Z8 z8.jpg 10] *//
AutoImageUtils.getImage("Z8");

//* Problem Two: I want to get the image that has been pre-loaded in AutoImageUtils. Hopefully I can return an ImageIcon *//
[I believe all I need at this point is to give a visual attribute to Jlabel but I�m having no success].
//*I believe I must also update the JLabel component to render this image (JLabel setIcon())*//

pix.setIcon(images[AutoImageUtils.getImage("Z8")];
pix.setIcon("hello");
My code for the Jlabel (which is bring back simple text currently):
pix = new JLabel("my name is marc");
JPanel pixContainer = new JPanel(new GridLayout(1,1));
pixContainer.setBorder(BorderFactory.createTitledBorder("Image of the Sports Car"));
pixContainer.add(pix); // add the image to the container
Thanks for any suggestions or pointers (not C pointers).
Marc

[ April 07, 2004: Message edited by: Marc Kryzhan ]
19 years ago
Thanks to the suggestions and examples. I got the following to work.

import java.io.*;
public class ReadFileBuffer {
public static void main(String[] args) throws IOException {
BufferedReader in = new BufferedReader(new FileReader("myText.txt"));
int count = 0;
while (in.ready()) {

System.out.println("Read line " + count + ": " + in.readLine());
count++;
}
in.close();
}
}
19 years ago
Thank you very much for the prompt response. I'll be back in the office tomorrow to play around with my code. I'm basically trying to read a file and print it out as a display. I'd like to go line by line and run my output through a loop and number each line just to verify I can count out a certain amount of lines in any given file.
Marc
19 years ago
I ended up getting the gist of types and iterators through this forum.
My end code:
public InventoryItemInterface getInventoryItem(String itemName) {
InventoryItem inv = null;
int invSize = inventory.size();
System.out.println("Store::getInventoryItem() Size Of Inventory Is: " + invSize);
if (inventory.isEmpty()) {
allocator = "empty";
return inv;
}
else {
Iterator i = inventory.iterator();

while (i.hasNext()) {
inv = (InventoryItem) i.next();
if (itemName.equals( inv.getName() )) {
System.out.println("Found Information For Item: " + inv.getName());
allocator = "found";
return inv;
}
}
allocator = "Not Found";
return inv;
}
}
Thanks for your help. Marc
[ March 29, 2004: Message edited by: Marc Kryzhan ]
19 years ago
I've successfully read from a file; proven because I wrote to a text file by copying from a file. How do I do a System.out.println of the contents of a file? Here's my code that I used to write a file and inwhich I've also attempted to output the encoded contents of my file with println. The file I read from is called farrago.txt (from sun's site). I modified it to contain two lines of text.
import java.io.*;
public class Copy {
public static void main(String[] args) throws IOException {
File inputFile = new File("farrago.txt");
File outputFile = new File("outagain.txt");
FileReader in = new FileReader(inputFile);
FileWriter out = new FileWriter(outputFile);
int c;
while ((c = in.read()) != -1)
{out.write(c);
System.out.println("ToString " + out.toString());
System.out.println("Read " + in.read());
System.out.println("Encoding " + in.getEncoding());
System.out.println("Can Read? " + inputFile.canRead());
System.out.println("Path " + inputFile.getPath());
System.out.println("Length " + inputFile.length());

//System.out.println("..." + getEncoding();
}
in.close();
out.close();
}
}
19 years ago
I've successfully read from a file; proven because I wrote to a text file by copying from a file. How do I do a System.out.println of the contents of a file? Here's my code that I used to write a file and inwhich I've also attempted to output the encoded contents of my file with println. The file I read from is called farrago.txt (from sun's site). I modified it to contain two lines of text.
import java.io.*;
public class Copy {
public static void main(String[] args) throws IOException {
File inputFile = new File("farrago.txt");
File outputFile = new File("outagain.txt");
FileReader in = new FileReader(inputFile);
FileWriter out = new FileWriter(outputFile);
int c;
while ((c = in.read()) != -1)
{out.write(c);
System.out.println("ToString " + out.toString());
System.out.println("Read " + in.read());
System.out.println("Encoding " + in.getEncoding());
System.out.println("Can Read? " + inputFile.canRead());
System.out.println("Path " + inputFile.getPath());
System.out.println("Length " + inputFile.length());

//System.out.println("..." + getEncoding();
}
in.close();
out.close();
}
}
19 years ago
public class Store implements hw9.interfaces.StoreInterface {
private Collection inventory = new ArrayList();
public hw9.interfaces.InventoryItemInterface getInventoryItem(String itemName) {
// inventory.indexOf(itemName);
InventoryItem name = new InventoryItem();
name.setName(itemName);
String gotName = name.getName();
inventory.toArray();
inventory.
}
I have a Collection that is created called inventory. I believe I've created an okay method to add to the collection. To test I need to fix my above method. Problem is Collection methods do not have a get function. I'd like to access the methods in ArrayList but don't know how. Please suggest how?
p.s. Here's my method to add input into a collection as an object;
public void addInventory(String name, String type, double cost, double
price) {
System.out.println("Store::addInventory()");
InventoryItem i = new InventoryItem(name, type, cost, price);
inventory.add(i);

}
InventoryItem () is a constructor in InventoryItem class which has the setName() and getName() methods. This is just there to teach me how to think in terms of protecting code I think. To really put into and get out of the collection all I would need I believe is the Store class.
Marc
19 years ago
You are right the declared method exists in an interface file. I've been struggling with this one for a few hours now. Ugh!
I've commented out all the methods in StoreInterface except for three, two of which I have working. I'm implementing the methods in Store.
In this particular instance
public hw9.interfaces.InventoryItemInterface getInventoryItem(String itemName) {
// inventory.indexOf(itemName);
InventoryItem name = new InventoryItem();
name.setName(itemName);
return name.getName();
//inventory.indexOf(itemName);
}
I'm using NetBeans to compile and am currently bombing on the return statement. The methods setName and getName are simple methods found in ItemInventoryInterface.
I could use some help with some coding examples. Pleeease! The above setName and getName methods aren't what I really need but I'm first trying to take baby steps with the app and get something to return. I'm supposed to prompt a user for an itemName and then display details about the item. I have a collection that is storing objects (name, type, price, cost).
Anyhow to get to C I first need to understand B.
Thanks ahead of time.
19 years ago
public InventoryItemInterface getInventoryItem(String itemName);
I have the above script in an assignment.
Firstly, What does InventoryItemInterface represent here? My guess, An Object? Is getInventoryItem an instance of this Object?
The other methods I have are in this following format (which I understand):
public void deleteInventory(String itemName);
I do have an interface called InventoryItemInterface but no methods in it called getInventoryItem().
My second part of this query is what capabilities does getInventoryItem() have if it is an object of InventoryItemInterface? Does it have the capability of using the methods in InventoryItemInterface?

[ March 19, 2004: Message edited by: Marc Kryzhan ]
19 years ago
I understand. Thank you for your very clear example and answer. As I work my way through this problem I may have a question or two, but I will keep them clear and brief also. It's like playing windwalker and needing a hint here or there.
20 years ago
My primary question is does a method definition for an interface need to specify 'return' and some return, even if it's just return null;?
20 years ago
I have six java source files that together make up a simple store and inventory system I'm working on. It's supposedly to teach me about collections.
I have two interfaces provided for me, StoreInterface and InventoryItemInterface.
I have a class StoreUI (partially created) which is the main arg and main file the user interacts with to do several functions, like add/delete an item to the store inventory, display the entire inventory, etc. I have a SimpleInput class that contains code that helps StoreUI take keyboard input from the user.
I have two classes I'm designing from scratch. One, Store, defines the methods from StoreInterface. The second, InventoryItem, defines the methods from InventoryItemInterface.
My dilemma: I have this code I've created so far for Store.java and I'm getting confused with the returns from the methods. How do I implement a return with several things going on in a method. In particular for now

This file is to define methods found in this interface StoreInterface.java

This file is the main user interface file StoreIU.java

[ edited to preserve formatting using the [code] and [/code] UBB tags -ds ]
[ March 17, 2004: Message edited by: Dirk Schreckmann ]
20 years ago