JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

That's really sad. I would worry that if the course materials have not been updated this century then they will also miss the massive language updates of version 1.5 etc.
Still, you have no choice if you want a passing grade!

I don't know why you have that message. Is there a stack trace or a "cause" Exception on the console? (java.lang.reflect.invocationtargetexception is a wrapper for some other exception = the "cause").

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

^ excellent advice. You can, and should, test code as early and as often as possible. Waiting until all the code is "finished" makes it really hard to tell where things are going wrong - it could be anywhere. If you test code as you go then any problems are most likely to be in the most recent additions.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

The awt GUI classes were superceeded in 1998 by Swing. Yes, 1998 - more that 15 years ago. You are seriously wasting your time learning or using it.
Update your code to use Swing (JApplet etc).

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Exactly what errors? - post the complete text of all your error message, don't expect people to guess.
[edit] Thank you. You should expect some answers now.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Is that a hex 52 or a decimal 52?
LDAP error 52 (hex) is the totally unhelpful "Local error occurred", but if that's 52 decimal (34 hex) it's the self-explanatory "The server is unavailable"
http://support.microsoft.com/kb/218185

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

That code is so nearly right!. It's just that for the length of an array you use myArray.length not myArray.length()
(yes, I know that's confusing - for a String it's length(), but for an array its just length)

Alternatively, make your code simpler by using an enhanced for/each loop, eg

String[] names = line.split(" "); 
for (String w : words) {
   initials += w.charAt(0);
   ...
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You have a load of JPanels that you don't need. You add the lables and fields to these panels, but that doesn't get them into the main mwindow. Forget the JPanels and just add your labels and text fields directly to the main window. (In real life there are reasons why you may use a JPanel or two, but this exercise isn't one of those)

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Hello Susanna
Thank you for sharing that with us, but is there any particular point you wanted to make, or question you wanted to ask?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Your earlier version was almost there

    while ((line = reader.readLine()) != null) {
      String[] name = line.split(" ");
      //Fullname = name[0];
      for(int i = 0; i < name.length(); ++i){
        Initials += Fullname.charAt(0);
      }

It just needs you to use name[i] to refer to each name inside the inner loop, and you will be heading in hthe right direction...

       Initials += name[i].charAt(0);

ps Java 8 uses :: to refer to methods, eg this::doIt means "run the method doIt() for the current object", someObject::print means "run someObject's print() method". Used a lot to replace anonymous inner classes, eg for Runnables or Swing event listeners, eg

saveButton.addActionListener(this::save); 
// calls this object's save(ActionEvent e) when button clicked
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You try to define method1 but you are still inside the main method. You ca't define a method inside another method.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

(A small digression for anyone who has noticed that Java 8 is now released, so we have Lambdas and Streams to use for this problem. Here's a solution using current Java. Not useful for this OP I know, but a heads-up for everybody about the magnitude of the changes in Java 8. It takes a file path/name and returns the first letter of every word separated by commas)

    String firstLetters(String fileName) throws IOException {
        // get a reader for the file...
        BufferedReader br = Files.newBufferedReader(
                Paths.get(fileName), StandardCharsets.UTF_8);
        return  br.lines().  
                flatMap(line -> Stream.of(line.split("\\s+"))).
                map(word -> word.substring(0, 1)).
                collect(Collectors.joining(", "));
    }
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

"\n" is the new line character. YOu read the file line-by-line, so that process strips the new line characters and gives you each line without a \n. So splitting on \n is pointless. Youwant to split each line into words, where words are separated by blanks, not newlines.
Look at line 20 - you are looping through all the characters in the first word. What you need is to loop through all the words, just looking at the first char of each.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Your code is almost right - you have the right pieces but the order is a bit messed up.
Read each line of the file,
split each line into words (ie use split with the default separator of a space),
then use chatAt to get the first letter of each word.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Check out the very first post in the Java forum "Starting Java [Java tutorials / resources / faq]"

http://www.daniweb.com/software-development/java/threads/99132/starting-java-java-tutorials-resources-faq

There are excellent book recommendations in there

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Try
TimeUnit.SECONDS
or chnage the import to
import static java.util.concurrent.TimeUnit.*;

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Sharing the exact complete error message always helps...

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You just copy/pasted your assignment without even a moment taken to explain what help you need. That's highly disrepestectful to the many people who give their time to help others here.

DaniWeb Member Rules (which you agreed to when you signed up) include:
"Do provide evidence of having done some work yourself if posting questions from school or work assignments"
http://www.daniweb.com/community/rules

Post what you have done so far and someone will help you from there.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Rather than using println with tabs, you will get better results using printf (like line 91) so you can specify the width and alignment of each field. I see you tried that, but I don't know what problems you had - maybe it was because CurrentMonth[i] is an enum value but you have a string format - in which case you probably want the string CurrentMonth[i].name(). There is definitely NO problem using printf with arrays etc, so just keep trying, or come back here for help.

As mentioned before, you can use Enum.valueOf to allow the user to enter month names rather than numbers.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster
  1. To prevent the application for terminating when yuo close the window, use WindowConstants.DISPOSE_ON_CLOSE (releases all the window's resources, leaves the program running) or WindowConstants.HIDE_ON_CLOSE (just makes the window invisible).

  2. For your Thread exercise I suggest you forget SwingWorker for the moment. SwingWorker does all the thread-related stuff for you, so it's not helpful for learning.
    All you need to do is to call invokeLater (ie what you do now) to run the method that will create the window on the Swing EDT thread - no other threads should be involved in that. Then create and start an ordinary thread that prints to the console in a loop. You may want to think about how to terminate that loop...

If after that you want to have some kind of interaction between the console loop and the window, that gets a bit more tedious, and you start to see why SwingWorker was invented.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You coded
54. setDefaultCloseOperation(EXIT_ON_CLOSE);
and Java is doing what you told it! That option instructs Java to exit the whole program when the JFrame is closed.

I realise that you are practicing with Threads here, but t4 just executes an addActionListener, which isn't enough for you to be able to observe any multi-threaded behaviour.
Also t1 and t2 are missing the whole point of SwingWorker, because Swing runs the doInBackground and process methods in suitable Threads anyway. Indeed by using your own thread for the process method you are breaking the program - process is where you updade the GUI so it MUST be executed on the Swing EDT thread (which is where SwingWorker calls it)

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Honestly? I think you may be over ambitious. Any one of those topics includes a huge base of data and practice - just take them one at a time and don't expect rapid results.
Personally I have no knowledge of Unbuntu phone development, but maybe someone else here will be able to help.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Yes, Eclipse is trhe other. I can't comment on the quality of either sources because I haven't read them myself. I would expect them both to be of very high quality.
I suggested NetBeans because that's closer in its roots to Sun/Oracle Java. More seriously, Eclipse uses IBM's SWT GUI library rather than Java's Swing or JavaFX. Although SWT is used a lot by IBM, Swing is far more common in general Java usage.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

ckide seems to work in C++ and Java, so either forum would be a reasonable place to ask. It's certainly NOT an error that would justify any moderator action.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

The usual GUI lib for Java is its javax.swing - part of the standard Java API. However, starting with Java 8 this month Oracle are pushing JavaFX as a superior replacement for Swing with lots of animations and clever effects.

I'm hoping to get time to post some simple "why are lambdas a good thing" tutorials here when they are released. I'm a big fan.

As for projects - have a look at NetBeans - it's one of the two all-singing all-dancing IDEs for Java, so it's a vast GUI project with massive technical content under the hood. It's written in Java, and you can join the project at https://netbeans.org/community/index.html

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

^ +1 to all those, plus they are more likely to be up-to-date

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Look at the Enum.valueOf method - it gives you the enum value from a String. Eg you pass it the String "May" and it it returns the enum value Average.May

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

I didn't say "read the API", I suggested you read the source code of the Java classes that implement the API. That satisfies everything in your first post except the use of build tools.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

The source code of the entire Java API can be downloaded form Oracle. That's as high-quality as anything gets.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

This one of those "which is best, football or cricket?" kind of questions. People are going to disagree strongly, mopstly based on personal preference and bias.
To get things started: my personal preference and bias is Java because you will need a lot of complex data structures and complex processing - I'd use Google's libraries to augment the standard Java API as well.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

To close a JFrame and release all its resources you can call its dispose() method.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Like I said before, Average.values() is an array of enum values, it's a loop along this pattern (pseudo code):

for i = 0 ... 11 {
   print actual[i]
   print Average.values[i].getAverage()
}
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Sockets give you raw InputStream and OutputStream on which you can then layer any other higher-level stream eg PrintWriter. However, Object streams work perfectly well over sockets, and have the easiest code. I have used them countless times without problem.
This is very puzzling. Can you try splitting the line into two and see which part is hanging? Also catch any Excecption, including uncheckedEg

try {
    System.out.println ("Start " + id);
    InputStream is = socket.getInputStream();
    System.out.println (is);
    objectinputstream= new ObjectInputStream(is);
    System.out.println ("End " + id);
} catch (Exception e) {
    e.printStackTrace();
} 
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

That doesn't fix the error - you have 12 data elements so the array should be [12]. What you did just "hid" the error.

Your problem comes down to this: you have some data in an array, but you are using an enhanced for loop on a different array (ie Average.values()), so it's hard to reference both afrrays in the loop.
The solution is to use a for (i=0... type of loop, in which you can access both actual[i] and Average.values()[i]

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

:)

But seriously.. what was the cause of the problem?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

After the for loop (Lines 34-38) i will be >= CurrentMonth.length, so that's why you have the error - array index out of bounds on line 45

stultuske commented: indeed +13
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Nobody here is going to be stupid enough to waste any time trying to debug a program that discards and ignores relevant Exceptions.
Given the problem you have described, your commenting out line 75 is a candidate for the DaniWeb all-time greatest mistakes hall of fame.

I know there is a second version of the code later in your post that is different - but how is anyone suposed to deal with two versions of the code like that?

Anyway - the error happens in the Thread that deals with individual conections, so there's no a-priori reason why that should stop the main thread from accepting further connections. The answer may be somewhere in the missing stack traces.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Can I suggest a little sensitivity on this topic? We know nothing of the OP's circumstances, and we do not want to cause offense or upset.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

It's a dual core Pentium (!)

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

<Order extends Queue<Order>> looks wrong (?)
How can Order be a subclass of Queue<Order> ?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

miles_per_gallon = miles / gallons;

Because miles and gallons are both ints this division is done in int arithmetic. After that, the result is converted to double to match the target variable miles_per_gallon, but by then it's too late.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

OK yes :)

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Yes, I'm sure there are problems with sharing a listener when you want to do stuff like finding the text area or updating its state.
What I am asking is: what's the problem when the whole code for the listener is just like

@Override
public void insertUpdate(DocumentEvent e) {
  mySaveButton.setEnabled(true);
}

... it doesn't need to get the source, or the DocumentEvent, or reference the document or the text area(s) in any way.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

mKorbel - do you have any links or refernces I can follow up re problems in sharing a DocumentListener?
For this specific case, where the document is completely ignored in the listener (and the callback is always single-threaded on the EDT), I can't see any potential for freeezes, but I'm always ready to learn...

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

So I tried a small demo program. With a bit of tuning it looked like this:
First the universal listener...

   class Saver implements DocumentListener, ActionListener {

        private int count = 0;

        @Override
        public void insertUpdate(DocumentEvent e) {
            System.out.println("Event " + count++);
        }

        @Override
        public void removeUpdate(DocumentEvent e) {
            System.out.println("Event " + count++);
        }

        @Override
        public void changedUpdate(DocumentEvent e) {
            System.out.println("Event " + count++);
        }

        @Override
        public void actionPerformed(ActionEvent e) {
            System.out.println("Event " + count++);
        }

    }

    private final Saver listener = new Saver();

(that uses prints to confirm what's happening. The real thing would replace all those with a setEnabled(true); for the save button).

Then I did a simple test window with a checkbox and a couple of text fields, which I hooked up with

        cb.addActionListener(listener);
        tf1.getDocument().addDocumentListener(listener);
        tf2.getDocument().addDocumentListener(listener);

and hey presto - any change to the text fields or check box trigger the event / Save button enabling.
Isn't that what the OP was looking for?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Sorry - my mistake, it should have been DocumentListener, not TextListener. (Old habits maybe?)

Because the listener is just going to enable the save button, I can't see any reason why all the text fields cannot call the same one-line listener? It's not in any way dependent on, nor does it change, the state of the text field.

What's the problem with ChangeListener for JRadioButton?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You can add a TextListener to each text field (and ChangeListeners to radio buttons etc etc). You can use the same listener code for all of them - all it has to do is enable the Save button.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

When you print an object, the print or println method calls that object's toString() method to get a printable representation of that object.
toString() is defined in the Object class, so it is inherited by every other Java class. The version in Object just returns a code representing the type of object, and its hash code - technically correct info, but mostly useless. That's why you should override the inherited version, and supply your own toString() method in any new class that you create. You can ensure that your toString() returns something useful.

The @Override annotation on a method tells the compiler (and anyone reading the code) that the following method definition overrides an inherited one. Thus the compiler can check that you have overridden it correctly, and everyone else can understand what you intended.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Using a null layout manager is a really bad idea unless you are coding for some very specific hardware configuration and the code will never run run on (eg) a Mac retina display. Pixel sizes are very different from one machine ot the next, so they are a near-usless way of specifying layout that has any text anywhere in it.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Hi Lius.

The purpose of your project is for you to learn and practice Java programming, not Googling.

The only way to understand how to code this is to start at the beginning and solve each problem as you encounter it. We will help with that.

You have a short step-by-step approach described in the post you quoted. Use that as a template and start at the beginning.
If/when you get stuck post what you have done so far and explain what's blocking you.

ps: DaniWeb Member Rules (which you agreed to when you signed up) include:
"Do provide evidence of having done some work yourself if posting questions from school or work assignments"
http://www.daniweb.com/community/rules

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Ideally you should enums for Suit and Rank - but maybe you have not covered enums yet in your course.