Help coderanch get a
new server
by contributing to the fundraiser

Phil Lesh

Greenhorn
+ Follow
since Oct 16, 2002
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
In last 30 days
0
Forums and Threads

Recent posts by Phil Lesh

Hi,
When you are calling super(Fn, Ln, DoB), essentially what you are doing is saying Person(Fn, Ln, DoB) so it creates a Person object. What you should do is in your Person class, create/define common methods for Person which could be inherited by the JavaStudent class and any others you may wish to add (e.g. JavaTeacher class extending Person). I hope this helps!
Phil
20 years ago
Hi again,
The exception that the above code throws is the InstantiationException. How would I instantiate the class within the above code? Thanks again!
Phil
21 years ago
Hi,
I'm trying to dynamically create classes. I have an interface called Algorithm in package "App.algorithms". There are algorithms in the same package implementing the interface. From a different package called "App.gui" I want to create a new object/instance of the algorithm with the name className. Here is part of the code:

I've tried setting the className to "App.algorithms.DijkstraShortestPath" and "DijkstraShortestPath" explicitly (where DijkstraShortestPath.java is a class in "App.algorithms") but it still fails on the second line. Am I missing something? Maybe I need to do something with ClassLoader? Please can you provide a bit of code. Thanks in advance.
Phil
21 years ago
Peter,
This is the exact equality that I was looking for, thank you very much for your help! I worked great!
Phil
21 years ago
Hi,
Can anyone please tell me whether it's possible to find the intersection point between Line2D.Double & Ellipse2D.Double. If so, some code would be very much appreciated! Thanks in advance!
Phil
21 years ago
Peter den Haan or anyone else, can you tell me how the equals() method would look like becuase I tried this and it didn't work:
public boolean equals(NodePair np)
{
if(this.hashCode() == np.hashCode())
{
return true;
}
else
{
return false;
}
}
AND THIS:
public boolean equals(NodePair np)
{
return (this == np);
}
I also realised that when I put print statements in this function they are not printed, meaning that the method doesn't get invoked anyway. Thanks in advance!
Phil
21 years ago
.. i also tried making the hashCode the same for both the lookup and the insertion and still i get null from "myMap.get(new NodePair(start, end))".
Phil
21 years ago
For some reason the hash code generated by "new NodePair(start, end)" is slightly different to the one present in the HashMap but since the values stored in the HashMap contain start & end strings they must have also been placed there using the key above - I have checked and they are placed in the HashMap using "NodePair nodePairKey = new NodePair(startNodeName, endNodeName);" key.
Thanks
Phil
21 years ago
I wrote this in a make.bat file for windows and it works fine for the following structure:
App
|_data
|_gui
|_helper
TheApp.java - main file
Type make in the directory above App. Hope this helped.
Phil
--- code ---
@ECHO OFF
ECHO compiling...
javac App/data/*.java
javac App/gui/*.java
javac App/helper/*.java
javac App/*.java
ECHO done!
21 years ago
Hi!
A program I am working on now uses HashMaps. The key is a NodePair structure shown below. When I put things into the HashMap, I can see that the information has been entered (using JBuilder's watch tool) but when I extract information using the command:
(<cast to object> myMap.get(new NodePair(start, end)) where start & end are Strings
I simply get a null value. Maybe the problem has something to do with the fact that if the equals method was used to check the information in the HashMap and the new NodePair, they would be different. Can anyone shed some light on this? Thank you in advance!
Phil
------------- code ------------------
public class NodePair
{
private String startNodeName;
private String endNodeName;
/**
* Class constructor setting the start & end node names.
*/
public NodePair(String startNodeName, String endNodeName)
{
this.startNodeName = startNodeName;
this.endNodeName = endNodeName;
}
/**
* Calculates the combined hash code of the node pair
*/
public int hashCode()
{
// multiply by 3 so that you can distinguish between
// directed and undirected edge
int hashKey = (3 * startNodeName.hashCode()) ^ (endNodeName.hashCode());
return hashKey;
}
public String getStartNodeName()
{
return startNodeName;
}
public String getEndNodeName()
{
return endNodeName;
}
}
21 years ago
Thanks a lot for the example! I really appreciate it!
Phil
21 years ago
Hi, I'm trying to implement a JScrollPane into a JPanel. The JPanel in question handles creation of various shapes on the screen which can be dragged. I want the JScrollPane to adjust it's ScrollBars so the components dragged out of view could be seen by moving the scroll bars. I have tried this:
drawPanel = ... some JPanel
JScrollPane scrollablePanel = new JScrollPane();
scrollablePanel.getViewport().add(drawPanel);
// Make the scrollbars always appear scrollablePanel.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
scrollablePanel.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
This simply creates the scroll bars which i cannot move. Maybe i need some kind of listeners which determine the size of the scrollable client. Can anyone please help? Thanks in advance!
Phil
21 years ago
As seen in java api [documentation] about ArrayList: "Resizable-array implementation of the List interface. Implements all optional list operations, and permits all
elements, including null. In addition to implementing the List interface, this class provides methods to
manipulate the size of the array that is used internally to store the list. (This class is roughly equivalent to
Vector, except that it is unsynchronized.)"
To find out more, go here http://java.sun.com/j2se/1.3/docs/api/ and in the left hand column select the class you want to find more about, i.e. ArrayList.
Hope this helps.
Phil
21 years ago
Can anyone please give me an example of a makefile for java. i.e. a makefile which compiles a couple of .java files. Thanks a lot!
Phil
21 years ago
P.S. the main class sits in the "App" dir and is called "TheApp.java"
21 years ago