JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You need to makedirs on C:/d1/d2 to set up the directory structure, then write your C:/d1/d2/sample.txt file to the directory.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Perhaps you Google is broken. I Googled "java button actionlistener" and this was the very first hit:
http://download.oracle.com/javase/tutorial/uiswing/events/actionlistener.html
That tells you all you need, as do any of the next "n" Google hits.

Seriously, being able to find reference material and samples on the web is an essential skill for any software developer - maybe you need to try a bit harder.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

That's how a standard ActionListener works anyway. Just Google it.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

There's no problem having a few JPanels. It's a perfectly normal thing to do. Maybe hundreds would slow you down, but two or three (or ten) is absolutely fine.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

5 on one side 2 on the other says "two JPanels" to me.
Having said that, I have yet to find a layout (based on rectangles) that couldn't be done with GridBagLayout. You have total control over every position, size, gap, and inset, which with 7 components to place gives you over 100 settings to fiddle with. Not easy, but very powerful.
Do you intend that the display will ever be resized or executed on a screen with very different resolution? If so, GridBagLayout will keep it looking good (if you set all the options right... :) ). If you are absolutely certain you don't need that, then consider going with a null layout manager and positioning everything by pixel address.
But me, I'd use 2 JPanels.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You could add a layer instance variable to the cube class, then in the paintComponent (not paintComponents, not paint!) method sort the cubes on the layer variable before painting.
Or
Keep another list of cubes, this one in layer order. Shuffle the list when you want to change a cube's layer.
Or
Combine both for maximum efficiency

paycity commented: You solved my problem with your great ideas. Rock. Thank you! +1
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Also you can create a subclass of Button with a property that contains the text that you want to appear on the TextField.

JButtons have valuable "client property" attribute that you can use to store/retrieve anything you like for that particular button
putClientProperty(Object key, Object value) / getClientProperty(Object key)
this is a better way to associate some text with a button, rather than sub-classing.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You can get the source of the event from the ActionEvent itself eg e.getSource() - this will be the particular button that was pressed.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

That's just the default way of printing for a Map<String, List>
If you want to format it differently you can write your own little nested loop thing that prints Map<String, List> however you like. Or (bit of a fudge this) embed a \n in the String returned by your CD toString method.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

This is the standard way to do it. It's universal throughout the API.
Every object in Java inherits toString from Object, and if you look at the code for PrintStream's print and println methods you see that
print(Object o)
is implemented by sending the result of o.toString(); to the PrintStream.

It's not obligatory to override toString, but it's always done.

Once you have done it you can print any CD by just
System.out.println(myCD);

ps toString is also used to display things when you add them to list boxes and other GUI components

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

CD@21e605 is what you get from the inherited toString() method - ie object type + pointer. Add a
public String toString()
method in your CD class and what it returns is what will automatically be used when the system wants to print a CD.
You don't really need printString once you've done that, because you can simply print the CD.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Kindof... you need to run one constructor to get the object to pass to the other constructor, so the simple version only works for passing one way. You can pass both ways by doing something like

game = new GamePanel();
ButtonPanel buttons = new ButtonPanel(game);
buttons.setGamePanel(game); // need to define this method in ButtonPanel class

ps. This is pushing the boundary of doing things in a single layer - if you had a third panel you would definitely be better off by going to an MVC architecture (or at least VC) where your Panels are the views, and a new Controller class has responsibility for creating all the views and handling all the logic between them. In that case each view class just needs a reference to the controller, not to any of the other views.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

So... it looks like the 2 parts to your system need to know about each other - or at least ButtonPanel needs to have access to the instance of GamePanel so it can call its methods.
One way is to pass the instance of GamePanel to ButtonPanel in ButtonPanel's constructor. ButtonPanel can then keep a copy of that and use it to call GamePanel's methods

game = new GamePanel();
ButtonPanel buttons = new ButtonPanel(game);
...
public class ButtonPanel...
  private GamePanel game;
  public ButtonPanel(GamePanel game) { 
    this.game = game;
    ...
  }
  ...
  game.initalizeNewGame()
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You have 2 arrays to fill up, but you only have one variable i to keep track of both - so if you have 4x econ they go into EconArray[0-3] then if there's a 1st it goes into FirstArray[4] not FirstArray[0]. You need two variables corresponding to the 2 arrays to keep track of how many places you have filled in each.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Yup. System.in is the console input stream.
It's common practice to use this with the Scanner class to handle some basic parsing of the input...

Scanner sc = new Scanner(System.in);
String s = sc.nextLine();
or...
int i = sc.nextInt(); // etc etc - see API doc for details of all options
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Convert the Strings to numbers, add them up, divide by the number of entries.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

In your method you have access to the size of the current CyberPet, and you also have access to the size of the other CyberPet that is passed as a parameter, so you can write a couple of if tests comparing those two things to decide what String to return. You may be looking for something difficult, but this is more simple than you realise.
Here's a starting point:
you method signature is invalid. It should be something like
public String encounter( CyberPet other )

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

This isn't very clear - but do you mean that those details are fields of a class you defined (eg Album) and when you print it you get some hex?
If so, that's the default toString() method that your class has inherited from Object, and what you need to do is to define your own public String toString() method in your class - return a String that describes the contents. That's what will be printed when you print an instance of this class.
If not, please be more specific!

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

ME is the Micro Edition - specialised version for smartphones etc
SE is the Standard Edition. It's all you need for ordinary desktop apps and applets and is (roughly) a superset of ME.
EE is the Enterprise Edition - for large-scale corporate client/server/database apps - it's a superset of SE


Most people start with SE, unless they have a good reason to do something different.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

if(value !=null)

value is an int, and can never be null. Only Object references can be null.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Your load code looks OK to me at a quick scan, but there's a big problem with what you do next. You create a new local variable FirstYears (NB should be firstYears), read the file into it, then end the method - at which point FirstYears goes out of scope and the object is garbage collected.
You need to either assign the newly-read object to a field of the class or (probably better) return it as a return value from your method.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You can download the source code for Java SE from the Oracle web site under the JRL (Java Research Licence*) - although there are restrictions if you live in country that's not on the approved list.
http://download.java.net/jdk6/source/

* The JRL is a license that was created specifically for universities and researchers who want to use Java technologies as subject matter for learning and research. This license is designed for the research community. This includes schools and universities as well as companies and individuals, who want to examine the technology source code for personal interest or research & development purposes. This license allows a licensee to work alone or with other licensees.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

In a fraction of the time it took to post that you could have Googled resultset swing table and got any amount of sample code and discussions.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

OK. Mark this "solved" so anyone else with the same problem will know.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

What version of Java are you using? It's OK with current versions of 1.6.

tunlinaung commented: Useful post +0
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

That looks like its trying to create a new array of Objects - that's OK
But then it tries to cast that to an array of typos's - which is not OK because Objects are not typos's.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

As long as typos is a Class and plithos is some kind of integer, that's good Java.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Java error messages are very precise and contain a lot of info. By not posting the full exact error message you make this a lot harder than it has to be.
Anyway - you obviously have some kind of unmatched bracket problem, so you need to fix that. Its completely pointless to try to run or debug code that didn't compile properly.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

How about something like...

public void mitosis()        // duplicates all the cells in this Organism...
  ArrayList<Cell> temp = new ArrayList<Cell>(cells);
  // need temp copy of cells because cells will be modified in the loop
  cells.clear();   
  // We could just add 1 copy, but removing the originals and
  // adding 2 copies is better when we get into mutations etc
  for (Cell c : temp) {      // for every cell in this Organism...
    cells.add(new Cell(c));  
    cells.add(new Cell(c));  
  }
}
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

No sure I understand the question, but...

// define a reference variable a that points to a new array of typos objects (size = plithos )
typos[] a = new typos[plithos];

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Unresolved compilation problem

So what was the compile error (the compiler will have given you an error message)?
(maybe something to do with the stray brackets/parens on line 139?)

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Rather than Google, you first point of reference should be the JComboBox API documentation, where you will find the following...

public int getSelectedIndex() ... Returns an integer specifying the currently selected list item, where 0 specifies the first item in the list; or -1 if no item is selected or if the currently selected item is not in the list

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

The principle is easy - on each "tick" of your clock add a small downwards increment to the Y velocity. This simulates the effect of gravity accelerating things downwards. Eg if you start with an upwards velocity it will slowly reduce to zero and then go negative.
You may also want to simulate a bit of air resistance by multiplying the velocity by a float just a bit smaller than 1 on each tick, and simulate lossy bouncing by losing a few percent of the velocity when reversing direction on the bounce.

ps When you start to do this kind of thing you will run into integer arithmetic limitations - you'll probably have to have the position & velocity variables as floats and only convert to int when actually painting pixels

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

The error message (Exception) tells you exactly what kind of error it is, and exactly which line it happens on. Without that info its very hard to debug.
Please post the full text of the error message

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

No, AFAIK there's no way (and quite right too!). There are no default params either, although you can overload the fn to have versions with and without the defaultable params (having come to Java from Smalltalk I do miss that one)

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

No, it's not.
What is it that you want to achieve? - there may be other ways to get the desired result.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Nobody else has answered so, despite the fact that I've never actually done this myself, there's nothing to lose by having a go!
The doc says that JavaFX can use Java classes, so in theory you should just be able to call the Java System.getProperty(p); // where p is "os.name", "os.version" etc. Even if you can't. for some reason access System directly like that you should be able to create a tiny Java class of your own that just wraps those calls, and use that from JavaFX
If this is rubbish, please just ignore it.

ps Just looked a bit further and it looks like you just have to import java.lang.System; and you're good to go.

pps: public class javafx.lang.FX also seems to support public static java.lang.String getProperty(java.lang.String key)

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Hello again.
I don't know what this is about - where does this code come from?
TextFileIndexer and searchIndex are not classes, they are methods. They will be defined inside a (or two) classes, but that info is not in your post.
INDEX_COLLECTION is not a variable, it's a parameter that has to be passed into the TextFileIndexer method. You can't "get it". You have to look for where that method is being called and see what value is being passed in.
Sorry, but without a lot more info on what this is all about I don't know what other help I can give.

ps: This seems like a completely different problem from the ArrayList / TreeMap thing we were discussing before. Maybe you should mark this thread as "solved" and start a new one for this new problem.

kekkaishi commented: such patience. kudos. :D +2
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Paint paints the component, any children in that component, and any frames, borders, decorations etc - everything related to the component. If you override it you can suffer from vanishing borders etc.
paintComponent just paints the internal direct content of the component, so you override that and all the borders/children etc still get handled properly.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You can use getWidth() and getHeight() on the component where you are painting to see how high/wide it is, then have two nested loops: one for x, one for y, painting and incrementing until x>=width and y>=height respectively (or stop at 5 if that happens first).
ps Recommended practice is to override paintComponent, not paint.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

One thing jumps out at me:
You get the lower & upper bounds in num1 and num2, but then you keep changing the value of num1 in your loops. This seems very dangerous to me. I suggest you add another variable or two for use as temporary values in your loops and NEVER change the value of num1 or num2. Even if that doesn't fix your immediate problem it will help avoid new ones later.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

one more question regarding the hashmap

So this is this morning's quota answer:
re-read previous posts. I told you repeatedly what to do with your HashMaps, and asked repeatedly for clarification as to where the duplicates were happening (which you never answered properly). There's really nothing I can add regarding your duplicates at this point.
Either use your IDE's step execution / variables tracing, or add lots and lots of print statements to your code so you can see for yourself what's happening.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Hang on, this is going wrong, and it's my fault.
It's essential that you develop your own skills in analysing problems, researching, reading the API, and trying& debugging solutions. What's happening here is that you are asking me before exhausting those processes, and I'm encouraging that by answering too quickly.
For you own benefit I'm going to limit this to one question/answer per morning or afternoon (excluding follow-ups for clarification only). Sorry if that sounds harsh or unkind, but it's time for you to fly on your own wings.
J

jon.kiparsky commented: Your patience is admirable. +2
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Yes, they are different Strings with different hash values. If the capitalisation doesn't matter you should convert them all to upper (or lower) case right at the start.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Yes, the enhanced for/each loop is great. I still can't see why your Iterator seems to be empty. If you can cut this down to a small stand-alone class that demonstrates the problem I'll try to run and diagnose it. Please, when you do find out, please post the answer here so we call all learn something.

If you have HashSet<String> then the iterator will be similarly be Iterator<String>, which makes your code simpler and/or safer.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Where exactly are words being duplicated? Can you provide an example?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

I said this more than once. Re-read my previous posts.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

A Map does not allow duplicate keys. If you want multiple values for one key you have to wrap them in (eg) a List - which is exactly what we have done here. Ie: each key (bigram ) is unique and points to a single value that is an ArrayList containing all the words with that bigram in them.
Where exactly are your duplicates? I think your current code given a word like "winning" with a bigram on "in" would add "winning" twice to the ArrayList - but that's a piece of logic you can fix for yourself.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

its toString() method gives you a beautiful text version (its what you get when you print the TreeMap). Now you have a String its easy to write that to a file.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Yes. Everywhere you have "HashMap" replace that with "TreeMap".