JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Client-server automatically needs multiple threads. No matter how you do it at the very least you will be waiting for the local user to do something and simultaneouly waiting for the other user to do something.

If you want to extract maximum learning from this I'd set it up as a server that handles multiple (pairs of) clients - that's more like real life serverland. I would put the game code on the server and only ask the user for an input - the server knows both user's input but each user only knows their own until the result is published.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

The error shows your classes and manifest are ok. It looks like you failed to package your png files in the jar properly - the message implies it can't find them.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

That sounds like a homework question that you want someone to answer for you?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Static methods execute without an assocated instance of the class, so they don't have any direct access to any instance variables or instance methods. They only have direct access to static variables and static methods. It's nothing to do with get/set as such.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

BufferedReader is the simpler and more direct way to read lines from text file, but the overheads of scanner for readling lines will be tiny.
Either will be just fine on files of many megabytes.

I don't know why there is tht Linux problem, but if Scanner works for you in both environments then that's what you should use!

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Maybe your Linux Java is 1.6 and your Windows Java is 1.7 or 1.8? (The try-with-resources construct was new in Java 7. You use that in the first version, but not in the Scanner version.)
If so, time to update! 1.8 is the current version on Windows and Linux

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Second thoughts:
Previous post does too much messing around from the List too early. Here's a better suggestion:
Just use Files.readAllLines(Path p) to get all the data into a List, then use random ints to pick lines, and then split the chosen lines into word/remainder.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Separating words and hints is a forumla for update chaos.
Just read the file 1 line at a time. Get the index of the first " " and use that to substring the word and the rest of the line (the hint). Store them in 2 ArrayLists (or create a class to hold them both if you want to be clever). They won't occupy much storage.

Then use random ints to index into the arraylists to get a word and hint.

No need for REGEXs

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

^ ... provided they are declared as being in the same package. If you use (multiple) packages then you need a directory hierarchy that matches the package hierarchy.

ps: It really has to work that way, just consider two classes each of which references the other.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

That looks OK. Have you tried it?
Problem with swing timer is that it executes on the swing thread, so no GUI updating or painting can happen while the updatePosition is executing. Right now that's not a problem, but if you have lots of things moving, and you're checking for collisions that takes a lot of CPU. By using a util.Timer you have the modelling and the GUI painting on two difffferent threads, which gives far better performance and smoother painting.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

27 Btter (but not essental yet) to use a java.util.Timer because the swing timer runs on the swing thread and will interfere with smooth screen updaying as your animation gets more complex (collisions etc)

35: There's no way you should be starting a timer in a paint method - you'll create a new timer every time it's called, and you don't know how often that will be. Start the timer just once, at startup, eg in your MyPanel constructor

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Yes, you should use invokeLater, and I always would in "real" code.

But for this tiny demo it would just create more clutter and hide the real point. I should also mention that I have never (yet!) had a problem building a GUI on the main thread provided that I make it visible as the very last statement (but that's no excuse!).
J

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You can do it with threads and waits etc, but it's too easy to get that wrong. Timer is easy & safe. Here's a little demo program that shows the basic pattern for running an animation in Swing at a predictable speed using a Timer and paintComponent...

import java.awt.Dimension;
import java.awt.Graphics;
import java.util.TimerTask;
import javax.swing.*;

public class Animation0 extends JPanel {
    // absolutely minimal example of how to structure animation in Swing.
    // One method steps the simulation model through time
    // One method updates the screen with the latest data

    public static void main(String[] args) {
        // create and display the animation in a JFrame
        final JFrame frame = new JFrame("Animation 0 (close window to exit)");
        Animation0 animationPanel = new Animation0();
        animationPanel.setPreferredSize(new Dimension(400, 150));
        frame.add(animationPanel);
        frame.pack();
        frame.setLocationRelativeTo(null);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setVisible(true);
    }

    // this is the "model" - just a single object moving at constant speed
    int xPos = 0, yPos = 35;    // current position of animated object
    int xSpeed = 1, ySpeed = 0; // current speed ( - for left/up)

    Animation0() {
        // start Timer to update the model every 30 milliseconds...
        // uses a java.util Timer rather than javax.swing Timer
        // to avoid running intensive simulation code on the swing thread
        java.util.Timer timer = new java.util.Timer();
        TimerTask timerTask = new TimerTask() {
            @Override
            public void run() {
                updateSimulation();
            }
        };
        timer.scheduleAtFixedRate(timerTask, 0, 30);
    }

    public void updateSimulation() {
        // reliably called by Timer every 30 milliseconds
        xPos += xSpeed; // update position of object
        yPos += …
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Painting: see http://docs.oracle.com/javase/tutorial/uiswing/painting/

Timing: start a javax.swing.Timer, and return. Every time the timer fires you can update whatever needs updating and return. Inbetween the timer firings Swing will be free to update the screen.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

If you load it as an Image you can use getScaledInstace to re-size it before converting to ImageIcon, but the reuslts may not be great. Better to do it in some proper image editing program - in which case you can also set a transparent background and save as a GIF that supports transparent backgrounds.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Counting the number of wrong guesses is part of the game definition, so it belongs in the model. You'll need a getWrongGuesses() method to return that value so the GUI can use it.
Now the GUI. Start with a JPanel in which to build up and display the hanging man. You can use JLabels as the easiest way to display actual images (load the image, create an ImageIcon from it, set that in the JLabel). This is one rare case when you may want to use a null layout manager for the JPanel so you can position each image exactly to fit together properly.
Any time the user enters a letter incorrectly call getWrongGuesses() and use that to make the right number of JLabels visible or invisible. (Put all that into its own method, of course)

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Yes, all that sample pseudo-code is in the actionPerfomed that is called every time the user enters a letter.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

With Swing you automatically are multi-threaded. There's always the thread your main runs on, and the Swing thread where all the mouse clicks, keyboard entry,a nd all your listeners are processed. You don't use while loops because, in effect, Swing already has the while loop waiting for user input in the GUI.

There are lots of ways to do this, but, for example, you could set up your model with no UI code of any sort, but with public methods like:

public int tryLetter(String aLetterToTry) 
   // returns 0 if word is completed, 
   // 1 if letter is correct, 
   // 2 if not correct, 
   // 3 if out of tries
   // (an enum would be better, if you know about them yet)
public string String getWordSoFar();  // returns word with underscores and correct letters

Now in your GUI you instantiate a model, and in your actionPerformed you can do stuff like:

int result = model.tryLetter(inputTextField.getText());
outputTextField.setText(model.getWordSoFar());
switch (result)
   case 0:  display success message
   case 1:  display OK so far, keep trying
   case 2:  display sorry, keep trying
   case 3:  display out of tries, game over

This separates your app into a model that has complete logic, but doesn't care about the UI, and a GUI (or console UI, or web interface etc) that doesn't care about how the game works.
You've broken one big problem into two smaller ones, which is exactly how huge systems get written in real life.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Without the whole code it's very hard to see where an NPE starts from.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

MVC!
Separate the GUI from the game logic as much as possible. Store everything in the game logic, and provide accessors for any user interface (console, GUI, HTML etc) to enter moves and keep them selves up to date.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You can't just print an array by saying
System.out.println(myArray);
all you get is a coded output like
[[Ljava.lang.String;@73a175]
that says it's an array of Strings at a particular address (etc)

Either print the elements one at a time in a loop, or use a method from the Arrays class to convert the array to a printable string, eg
System.out.println(Arrays.toString(myArray));

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Yes, sure. I was just explaining a bit more why the double-loop code was so bad.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

System.out.println(" " + num + " is in index "+ j);
should do the trick.

... as long as the trick you want to do is chosing between an array index out of bounds or an infinite loop (depending on whether num == array[0] or some other element

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Yes, as in my "check your spelling". OP's previous thread was a similar typo, so he should be able to understand a "cannot find symbol" error by now.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

I doubt very much that that will help anyone. Sorry, but that code is complete nonsense compared to the original. Did you try executing it? I thought not. Just run it and see how bad the output is.

It also includes the mistake from the original code, array[i] (or array[j]) is the value, not the index he is looking for.

stultuske commented: countering imo not deserved downvote +13
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

There is already something named Interface!

Are you sure? There is a keyword "interface" but that's irrelevant. I don't see anything else called "Interface"

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

System.out.print(" " +num+ "is in index " + array[i]);

You are printing the value in array[i], not the index.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You have been posting here long enough to know that you should give the complete details of any error messages, and explain what symptoms you are seeing.
ps CHECK YOUR SPELLING (AGAIN)

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Yes.
There were all kinds of tiny improvements in Java 8 that weren'y big enough to make the press release, for example (one of my favourites)...
how many times have you done this:

Object value = myMap.get(key);
if (value == null) {
   value = some default or new value
}

Java 8 added

Object value = myMap.getOrDefault(key, defaultValue);

OK, it's not earth-shattering, but these things add up to smaller clearer code, and we need all the help we can get with that!

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Slavi: that's the Java 7 version, probably OK, but we should be referring people to the current version of Java (Java 8) unless there's a specific reason not to.

Here is the current API documentation.
It contains details of all the methods and variables for all the classes in the Java SE API. It's an absolutely essential tool for anyone writing Java. I know it's inimidating at first, you absolutely MUST get familiar with it.
I keep it permanantly open in a tab in my browser. and so should you.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

The symbol it can't find is "showMessageDiloge" (see line 4 of the error!)
It's because you spelled it wrong.
See the API doc for JOptionPane for the correct spelling

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Small correction to the above...
the increment expression is always evaluated after the body of the loop, never "as if though it were the first line of code in the for loop". See
http://docs.oracle.com/javase/tutorial/java/nutsandbolts/for.html or the Java Language Spec 14.14.1

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

NO!

length is a variable. There is NO length() method for arrays. Mahybe you are confusing it with String, which does have a length() method?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Arrays are objects, and length works just like a public final instance variable. The Language Spec says

10.7 Array Members
The members of an array type are all of the following:
• The public final field length, which contains the number of components of
the array. length may be positive or zero.
...

You don't need a loop, eg if you are expecting either one or two command line argument you could code:

public static void main(String []args){
  if (args.length < 1) ... // report an error and terminate
  ... args[0] ...  // use the first argument
  if (args.length == 2) ... args[1] ...  // use second argument
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

In that particular code the i++ or ++i is executed at the end of each iteration and its execution is complete before the next iteration starts and its value is tested, so it makes no difference whether you use i++ or ++i

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

length is like an instance variable that arrays have. It contains the length (size) of the array. In this case it's telling you how many command line arguments there are

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

I don't understand that question, sorry.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

I can't see any problems in that code. Are you certain that the nodes are being populated correctly with the names and links?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

^ well spotted, but that description not quite exactly correct - "Supplies" is a reference variable, not an object. The code creates 7 objects, and keeps changing the reference variable to refer to the most recent one, so it has no way to access the first 6. Eventually the first 6 will be garbage collected because there are no surving references to them.

ps: having a variable with exactly the same name as the class isn't a Java error, but its really really confusing. Java naming convention is that class names should start with an upper-case letter, but variables should start with a lower case letter

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

7 works because on lines 32-36 you print all its fields explicitly. For the others you use System.out.println(Supplies);

This is all about the toString() method...

Every Java class inherits a toString() method from the Object class, so methods like println use that to convert the object you want to print into a String. The inherited method prints the class name and the object's hash (normally the same as its address). If you want to display something more helpful, override the toString method in your class to return a useful string. Eg

class Person {
    private String givenName, familyName;
    ...
    @Override
    public String toString() {
        return "Person: " + givenName + " " + familyName;
    }

You should do this for every class you create so when you print an instance you get useful output.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

The loops are confusing this. Try a simpler example

int i = 1;
System.out.println(i++);
System.out.println(i);

int j = 1
System.out.println(++j);
System.out.println(j);
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You can use the java.beans.Introspector class to get the BeanInfo for your bean. Then use the BeanInfo to get the PropertyDescriptors. That gives you an array of all the properties, from which you can call getReadMethod() to get each of the bean's get methods. You can invoke those methods to get all the property values.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

ClassNotFoundException: net.ucanaccess.jdbc.UcanaccessDriver

that message is pretty explicit. After extracting fromn the zip file and adding to NetBeans librray, do you have the jar that contains net.ucanaccess.jdbc.UcanaccessDriver.class in the list of libraries?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You should incorporate Taywin's point and test for size >= 3
The problem may never happen with this application, but that kind of "defensive programming" is a good habit to develop. In real life programs get updated long after they were first written, and often by another programmer. If you use size == 3 you have an infinite loop just waiting to happen...

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

UCanAcess-2.0.6-bin.zip looks like a distribution package - you need a .jar file. Start by expanding the zip and look for the jar file

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Never do this when writing new code:

} catch (Exception e) {
}

If/when there is an error you just told Java that you didn't want to know anything about it, and please discard the detailed error message that Java just created for you.
ALWAYS put an e.printStackTrace(); in your catch blocks until/unless you have a good reason to do something else.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

OK, I just had a couple of idle minutes and read the whole code. There are no null chars (see above), but you do have references that are null, and you convert them to Strings.

Here's what seems to be happening:

You create a String[][] array, but you don't initialise it, so it's full of null references. Then you attempt
newData[i][k]+=data[i].charAt(j)
which is a short form of
newData[i][k] = newData[i][k] + data[i].charAt(j);
Java realises that the + can only be string concatenation at this point, so it converts both operands to String and concatenates them.
newData[i][k] converts to "null"
data[i].charAt(j) converts to a one-character long String (eg "a")
and concatenates them to give "nulla"

Solution: initialise your String[][] array properly.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Can you explain what you are trying to achieve, recognising that there's no such thing as a null char?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You need to look more closely... there is no such thing as a null char in Java. What exactly are you seeing?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

As a guess:

Your run method contains an infinite loop, so if you call it directly it will never return and the calling program will be frozen. So you need to execute it on a different (new) Thread.

(That's why it's called "run" - it implements the Runnable interface that a new Thread needs.)