JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Yes. Exactly the same as for HashMap except that it's already sorted.
Have a look at the methods for TreeMap in the API documentation. You will find all kinds of methods for getting the keys, the values, iterators for looping through them etc. You can use those methods to access your data any way you want so you can send it to a file any way you want.
We all start by learning arrays, but in real life its much more common to use Lists and Maps etc because these are more powerful and easier to work with. You'll learn all about them sooner or later...

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Easiest solution is probably just to change your HashMap to a TreeMap - it has all the same keys/values/methods etc, but it keeps the data sorted into order according to the keys (bigrams) automatically

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Almost... the temp reference is for you to create a new ArrayList, add a word to it, and add the ArrayList to the HashMap. After that the temp reference goes out of scope and dies - it's not needed any more.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

@mKorbel - OP needs to add ALL words that match, so the break is INCORRECT

@drogba123 - do NOT put in the break suggested in the previous post.
I did say it's not the same syntax to create a new ArrayList with just one String in it. You have to do something like:

ArrayList<String> temp = new ArrayList<String>(); // new arraylist...
temp.add(word_); // .. containing just the current word ...
test.put(bigram1, temp); // ... is added to the HashMap
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Line 15 you add a new arraylist containing the whole word list (a1), this should just be the single word that you just found (words) (NB: not the same syntax).

ps Variable words is a confusing name, change it to word because it only contains one word at a time!

pps: This is a perfect example of how good/bad variables names can help/hinder you. Your word list is called "a1", which means nothing. If you gave it a good name, eg "allTheWords" then your mistake would have been obvious... test.put(bigram1, new ArrayList<String>(allTheWords)); // obviously that's not right!

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

When you do a set method you must pass in the value that you want to set. So the test code says

cmis141Student1.setStudentName("Andy");

but you don't have a parameter corresponding to the new name "Andy"

public void setStudentName() { // no parameter
  studentName = studentName;  // this just sets studentName to whatever it was anyway (ie does nothing)
}

Have another look at the set method in example I gave you - it shows you how to use a parameter for the new value - you just have to adapt that idea to work with your code.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You can use the format method in the String class to convert stuff to String using printf-style formatting codes.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

4: if (test.containsKey(element)) { // this is all yu need

5: test.get(element).add(element1) // key is bigram, value is word

8: test.put(element, ... // value here needs to be a new ArrayList containing word]

Note: variable names make this hard or easy - element/element1 doesn't help, bigram/word would make it much clearer

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Should line 13 be for (Object element1 : a1) ???
Line 14 should use the loop variables
line 15..
Sorry man, your code really doesn't follow the pseudocode at all

ps code would be better with the ArrayLists declared as <String> -

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Like I said the hashmap is for storing the matches. In pseudocode it goes something like this:

for every bigram
   for every word
      if word contains bigram
         if there is already a key in the hashmap for this bigram
            get the corresponding ArrayList of words and add this word
         else
            add a new entry in the hashmap, bigram as key, new ArrayList(word) as value
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

The other thing that comes in here is the Java package structure - so if one of your desktop .java files imports (for example) jcode.SomeClass, then the compiler will search for a jcode directory in the classpath and look inside there for SomeClass.class or SomeClass.java. If it only finds the .java it will compile it.
See http://download.oracle.com/javase/1.4.2/docs/tooldocs/windows/javac.html - in particular the section headed "SEARCHING FOR TYPES".

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Sorry, don't understand your question. It would look like:

KEY (String)    VALUE (ArrayList)
"ev"            ["every"]
"ve"            ["every"]
"er"            ["every", "errant"]
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Compiles all the .java files in the current directory (*.java) - is that the desktop?
Is the JCODE folder in the classpath?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

OK, that's a lot clearer, thank you. HashMap<String, Arraylist<String>> still looks like the best choice to me.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Here's some examples that are relevant, when you understand them you will be able to do yours:

public class Demo {
   int data;

   public void setData(int value) {
      data = value;
   }

   public int getData() {
      return data;
   }

   public int calculateDoubledData() {
      return data*2;
   }
}
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You said "How do i store matching substring and string ..." so I assumed you had already compared the substring and string, and were looking for a way to store the ones that match. In the HashMap you use the substring (eg "er") as a key through which you can get the ArrayList of all the matching words (eg "every", "errant") .
If that's not helpful, then maybe you can provide a clearer /more complete description of what you need to achieve?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

/t isn't going to do anything for you, you'll have to use HTML codes for formatting & layout. JLabels support many ordinary HTML tags, but not all. You just have to try a few things and see what works to give the result you need.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

I don't have time right now to check all your code, but it looks to me like your main should call drawSnowflake (passing N ans S as parameters), and drawSnowflake should call snowflakePart ( AKA snowflake ), but not vice-versa.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

When Java needs to load a class it gets the variable "CLASSPATH", which should contain a list of directories and/or jar files, and searches all those locations to find the .class file(s).
Line 4 appends %AGLET_HOME%\lib\myJarFile.jar to the CLASSPATH variable.
AGLET_HOME was set to C:\Users\MARIA\Desktop\aglets, so line 4 appends the jar file
C:\Users\MARIA\Desktop\aglets\lib\myJarFile.jar
to the CLASSPATH, so java will be able to find whatever classes are stored in that jar.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

The only way I know is HTML, but that's really easy - eg
myJLabel.setText("<HTML><This is a test<BR>on two lines</HTML>");

HelloMe commented: straight to point with example +2
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

When you get a Java error it comes with a complete description and a stack of line numbers. Please post the full details of your error(s). Also post the full source code - you post identifies the error as being on lines 161/166, but the code you posted only goes to line 39!
However, I did notice that your Java snowflake method calls drawSnowflake at the end, which is not in the pseudocode.
You also renamed snowflakePart to snowflake - makes no difference to the compiler, but may reveal something about how you are thinking of it, eg you call snowflake from main, but maybe that should be drawSnowflake?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

OK, post what you've done so far (don't forget the code tags!) and someone here will have a look and give you some feedback and advice.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Not exactly a clear statement of requirements, but if you want to link that list of words to the substring you could use a HashSet with the substring as the Key and the ArrayList of words as its Value.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Just get a text editor and start typing! But seriously, you have a detailed blow-by-blow description of what you have to do. It's detailed enough that you don't have any room for cleverness, so just do what it says.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Missing } at end of previous method

ps NEVER leave empty catch blocks like 187-191

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You'll find some strong clues in the JavaDoc for Thread and ThreadState, but I can't find anything from Sun/Oracle that documents this properly. It must be somewhere?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

A thread will continue executing until its run() method terminates, at which point it dies and cannot be restarted. I think the GC issue is a red herring - although you may have freed all your explicit references to it, the JVM scheduler surely has one.
This http://www.janeg.ca/scjp/threads/state.html useful summary isn't from Sun/Oracle, but it does reference them.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

OK, we don't have the full picture here.
You declare goodWords as a raw type - which gives a warning when compiled. Ditto your iterator.
Line 5 has a case error, and doesn't compile.
You then assign the return value of iterGoodWords.next(), which is type Object, to a String, which generates a compile error.
So exactly which "javac" compiles it?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Just setVisible(false) /* temporary */ or dispose() /* permanent */ the first window in the button's ActionListener

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Main,java draws the current component. UDPClient sends the data to Main.java through UDP protocol. I have to finally update my data using UDP protocl

Does the program have to perform the UDP data transfer for every paint? If so, is this what is limiting your re-draw rate?
What Thread is the UDP activity happening on - is it called directly or indirectly from paint or paintComponent? If so, you may be blocking Swing's event dispatch thread which will cause jerky screen refreshes.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Move as much code as possible out of paint(...) - eg read the image file or create the new Font just once at startup, not on every call to paint(...).
How and how often are you updating? You should be using a javax.swing.Timer to call update the heading then repaint() pretty frequently, eg 50 mSec

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Glad to help. Mark this thread "solved" now?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

If you have 4 subclasses you can use 4 variables, or one variable with the base class reference. It depends on the code and what it is doing.
Another (real life) example:
The base class InetAddress holds IP addresses, and has two subclasses Inet4Address and Inet6Address for IPv4 and IPv6 addresses respectively. Once you have got the IP address of some server you don't care whether it was an IPv4 or IPv6, you just want to use the methods that work for either kind, so you just have one variable and declare it as InetAddress.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You may have multiple subclasses, but in this particular piece of code you don't care which one it is.
Animal a = new Cat(); (or) new Dog(); (or) new Horse(); // etc

a.makeNoise(); // don't care what kind of animal it is

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

> class ButtonFrame is public, should be declared in a file named ButtonFrame.java
means what it says
> cannot find symbol : class Jlabel
> cannot find symbol : variable plainJbutton
check your capitalisation - all Java names are case sensitive

After that it doesn't help that the code you posted is NOT the code that the error messages refer to.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Going back to the original MVC question, which seems to have got submerged in all these issues about waits and repaints...
A simple way to do this as MVC goes as follows:
1. Model class - has 8x8 array modelling the logic of the chessboard and populating it with the possible queen moves etc
2. View class - a Swing window that gets an instance of Model passed into its constructor, and displays the contents of the model on request
2. Controller class - creates a new instance of Model, creates a new instance of View, instructs the Model to populate with Queen moves, instructs the View to display, repeats last two steps in loop (with delays if you want) to find solutions.

An better, but optional, enhancement is to link the View to its Model via an Observable pattern (AKA change Listener) so that the View will update automatically every time the Model is changed.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You can iterate through all the children of the JPanel removing them one at a time... but it's probably easier to remove the old JPanel from your window and replace it with a new empty one.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Hint:
If a subclass constructor does not have a call to its superclass constructor as its very first line, the compiler will automatically insert a call the the superclass's default (no args) constructor.
What did the compiler give you in this case? Will that work? If not, what can you do to make it work?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Maybe this is the default constructor problem? You don't have a constructor for the subclass, so the compiler tries to supply a default one. The default constructor calls the superclass no-args constructor, but here isn't one so you don't get a default constructor after all, and hence the error message.
Do the subclasses have any constructors defined?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

so far I have three errors ...

What errors exactly, on which lines? Please post full error messages and the source code lines where the error happens

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

nevermind

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You can use a boolean variable to tell you whether this is the first pass of the loop, eg

boolean isFirstPass = true;
while (... ) {
  ..
  if (isFirstPass) {
     // do stuff that you only want to do on first pass
     isFirstPass = false;
  }
}
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Hello Hertze. I deliberately didn't give the OP the exact fix to his code so that he would work it out for himself and learn. So you give him the exact fix to copy/paste and what does he learn? Please remember that we are trying to help people to learn Java, not to help them cheat their homework

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

1. Your print expression has one correct + operator, but it needs two!
2. You define and create your arrays inside the loop, so each iteration of the loop creates and destroys a new set of arrays. You need to define and create them before starting the loop so that each iteration of the loop is working with the same arrays.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

That's great. Time to mark this thread as "solved"?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Is your problem in printing the array [Ljava.lang.String;@8814e9 ?
That's how println prints an array of Strings.
If you want to see the contents either loop thru the elements printing them one at at time or use Arrays.toString(..)

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

"has errors when it runs" is not enough info for anybody to conclude anything. You must be specific. What errors? If an Exception give whole message and line number(s). If incorrect output give expected and actual results.
ps mKorbel - I'm assuming that this is a training exercise so SimpleDateFormat wouldn't be acceptable, despite the fact that that is what you would use in real life.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

The problem here is that the code for initialising various parts of your app is distributed around various classes & methods in a confusing way. Based on what you have said so far it would be better to group it together like this:
Login class:
Constructor does everything to set up and display Login dialog. When login is completed successfully it creates a new MainWindow passing the name as parameter.
MainWindow class (better name than just Main!):
Constructor takes user name as parameter and does everything to set up and display the main window in its initial state.
ActionListener calls method to add menus (etc) as required.

public static void main(String[] Args)
In a real app there will be other application initialisation (eg opening databases, loading preferences) and it makes sense to have an app startup class that does all this via main. But in your case you can put this method in almost any public class - eg Logon. The important thing is that all it does is call new Logon() - nothing else. All the other code for setting up windows etc belongs in the appropriate constructor - this is why you are having problems with the code in your latest post.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

That doesn't look like the exception is thrown until after the System.println on line 6, so maybe it's not the split that is the prolem.
What is the exact complete exception message (including the line number)?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

So why does main want to call Main()??? From your description main should be calling the Logon class - that's where execution starts.