JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

What exactly are the error messages?

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

i have no idea what the program would even look

To be realistic - copy/pasting stuff and hoping for the best is not goiung to work for you... you need to learn properly about Java and programming starting from the very beginning. There are people here who will help you do that, but there are so many courses and tutorials on the web that nobody will write a new one just for you.
Searh the web for a beginners "starting java" that seems confortable to you and work at that. Don't expect to get far in less that 10-20 hours real study, but after that you should be able to complete this exercise.

Good luck
JC

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Do not ask for help to pursue any illegal activity including, but not limited to, hacking and spamming

Thread closed.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

It looks like you are wasting a lot of time. That code still has all the errors that you said you had fixed earlier, and the main method makes no sense at all.
Re-post your code after you have compiled it and fixed as many errors as you can.

Slavi commented: LOL! :D +2
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Just for all you folks out there who are still on an old version of Java, here's yet another reason to update to the current 1.8...

void addButton(String label, ActionListener action) {
    // simple method adds a button with an actionPerformed
    JButton b = new JButton(label);
    b.addActionListener(action);
    numberKeysPanel.add(b);
}

// then use that with lambdas for the actionPerformed...

addButton("7", (e) -> input = input*10 + 7);
addButton("8", (e) -> input = input*10 + 8);
...
addButton("+", (e) -> {result += input; input = 0;});
...
etc

OK, you could further shorten that by automating the numeric buttons a bit further (peronally not convinced for only 10 buttons, but hey...)

void addNumberButton(int value) {
    // simple method adds a button with an actionPerformed
    JButton b = new JButton("" + value);
    b.addActionListener( (e) -> input = input*10 + value);
    numberKeysPanel.add(b);
}

// then just

addNumberButton(7);
addNumberButton(8); etc
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

No, it just looks like string concatenation, butthat's being done arithmetically by multiplying the previous value by 10 before adding. So if numberEnterd starts at 0 and you press 1 then 2 then 3 the corresponding values of numberEntered are
0
0x10 + 1 = 1
1x10 + 2 = 12
12x10 + 3 = 123

Which is what calculators usually do when you press those buttons.

The problem you have is that the indexes of the buttons in the array do not correspond directly to the numeric values the buttons represent. You can easily fix that with an array of its that maps the actual numeric values to the indexes.

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
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

The idea is that you have a class of ButtonHandlers, but you create a new instance for each button. The ButtonHandler has an instance variable for the number that its button represents. So, for example,
new ButtonHandler(9)
creates an instance that knows its button represents the number 9.
Have another look at my sample code - you;ll see that each button has its own instance of ButtonHandler.

The big advantage is that the actionPerformed becomes a lot easier. Instead of messing about trying to see which button was pressed and doing a big switch or nested ifs, you already have an instance var with the answer. Eg for number buttons you just want to build up the whole number entered, ie

public void actionPerformed( ActionEvent event){
   numberEntered = numberEntered*10 + buttonNumber;
}

Personally I would put the number buttons in a little JPanel and all the others in a seprate "functions" JPanel, whiuch would make the rest of the code easier, both for layout hanges and to separate the logic for number buttons from the very diffferent logic of the function buttons.

If you get the feeling I'm going too fast here, just ignore it all for now.

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

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

There's a good trick to use here, which is to create a handler that knows which button was pressed - it looks like this:

class MyListener implements ActionListener {
   int buttonNumber;
   public MyListener(int b) { // constructor takes button number
      buttonNumber = b;
   }
   public void ActionPerformed(....
       System.out.println("Handling event for button " + buttonNumber);
   }

then in your loop, add instances like:

for( int counter = 0; counter < labels.length; counter++ ) {
   numberKey = new JButton( labels[ counter ] );
   numberKeysPanel.add( numberKey );
   numberKey.addActionListener(new MyListener(counter));
}
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

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

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

There are lots of people here who will freely give their time to help you become the best Java programmer you can be. There's nobody here who is interested in helping you cheat or doing your homework for you.

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

I wonder if I didn't explain my original proposal very well because it imposes zero overhead on changing cell values. At the risk of boring everybody (stop reading here if you like!) I'll go through it with greater care:
The game requires us to store 81 numbers, grouped in 27 overlappinng subsets (rows/cols/3x3 blocks) of 9 numbers each. We have to check that each subset contains no duplicated values. Proposed implementation (slightly pseudo-java):

int[81] cells;  // contains the numbers. 1D array because that halves the number of loops and indexes we will need
int[27][9] rcbs;  // contains indexes into the cells array to define which cells are in which row/col/block subgroup - this array is fixed by the rules

adding/deleting/changing a number:

cells[i] = new value; // can't be any easier than that!

now a simple method to see if an r/c/b subgroup (defined by 9 indexes into the cells array) has duplicates

 boolean hasAllUniqueValues(int[] cellIndexes) {
    boolean[] found = new boolean[9];
    for (int i = 0 to 8) {
       int value = cells[cellIndexes[i]];
       if (found[value]) return false; // duplicated value
          found[value] = true;
       }
       return true; // no duplicates
    }
 }

now all we need to check the entire game is

   boolean isComplete() {
        // is the current game a valid complete configuration?
        for (int i = 0 to 26) {  // check each rcb subgroup
            if (! hasAllUniqueValues(rcbs[i]))
                return false;
        }
        return true;
    }

So that's the …

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Just because Soduku is displayed in a 2D grid that doesn't mean you have to store it internally like that. And there are very good reasons why you shoudn't.

You have 81 cells. You want to look at groups of cells like {1,2,3,4,5,6,7,8,9} - a "horizontal row", or {1,10,19...} - a "vertical row" or {1,2,3,10,11,12,19,20,21) - a "3x3 block".
You're going to spend a lot of time iterating through the members of those groups, and doing it all with x,y coordinates is going to be very tedious.

Why not just have int[81] cells to hold the "9x9" grid of numbers, and arrays to hold the rows/cols/blocks. There are 27 rows/cols/blocks, amd each is defined by a list of 9 cell numbers, ie int[27][9] allRCBs containing cell numbers (like the examples above). Just look at how quick and easy processing those groups will be now....

(It's a classic example of why you should start by understanding the model before worryng about the user interface)

The next step is to start to define some useful methods to encapsulate access to that data structure - eg

getCell(row, col) - convenience method for user interface - makes it easy to print or build a GUI as a 9x9 grid

isValid(int[] rcb) - checks a row/col/block for validity (numbers 1-9 exactly once) rcb is a list of the 9 cells that make up the row/col/block, as in

for (int[] rcb : allRCBs) {
   if (isValid(rcb)) ...
peter_budo commented: Well put +15
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

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

The message is pretty self-explanatory. It probably refers to the degree symbols on lines 63 and 75 (there may be others as well) because there is no degree symbol in your default US-ASCII character set.
The simplest/safest fix is to remove those symbols - they are just part of the display and have no effect on the program logic.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You get the name before you enter the loop, so that's only executed once, at the start of the program. Your main two options are:
1. repeat lines 21/22 just before the end of the loop, so you ask for "name or stop" before starting the next pass of the loop
2. use a different loop structure, eg

while (true) {
   prompt for "name or stop"
   if (input is "stop") break;
   ask for pay etc...

ps: You ask the user to input "Stop", but test for "stop". There's a version of equals that ignores case - see the String API doc for details.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Of course there's no absolute universal definition of Object Oriented, so there's no definitive answer ot this question either.

Personally I worked with SmallTalk before getting into Java, and SmallTalk is definitely the most OO language of all. Everything is an object (including the code itself), and the only syntax is sending a message to an object (ie method call). No other statements ("if", "while" etc) needed or present in the language (they are just methods in the Boolean class). Similarly, the language has an assignment operator, but no others (+ - etc are methods in the Integer class etc).

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Primitives like int, char, float, boolean are not Objects, so the language is not 100% OO. The reason was for efficiency and speed - primitives have much lower overheads than objects.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Exactly the same reason, exactly the same fix. If you want a \ in your Regex then you have to code two \ chars in the Java String literal, because \ is used in Java String Literals for special characters like \n (newline)

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Nice contribution Slavi. The one you referred to uses a GUI with ten number buttons, and is a very good choice for an early Swing project. (There's not much point doing it as a console text-only project!)

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster
PrintStream ob=new PrintStream(System.out);
ob.print("Hello World");

Good point stultuske

System.out is a PrintStream, so new PrintStream(System.out) just creates another PrintStream object which is just the same oas the original. SO there's no point doing that.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

No need for the counter - it's just another thing that could go wrong. You can use the length of the bld String and see if that is 3. Don't forget to reset it back to "" after a wrong entry

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Like mKorbel says:
You can't do this with a 1..3 loop. Each time a button is pressed append it to the combination String. When that results in a String of length 3, check to see if it's right or wrong.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

That looks 100% better - you're really on the right track now.
It's especially good that you stopped there and added a line to allow you to test what you did so far. Real programmers test early and test often.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Everything to do with Swing (eg painting the screen, running actionPerformed methods) happens on a single thread - the "Event Dispatch Thread", or "EDT", or "Swing thread". Your actionPerformed is run on the EDT, which means that once your actionPerformed method starts NOTHING else will happen in Swing - no button clicks will be processed, no screen updates, nothing. You just sit in your loop burning 100% of the CPU time waiting for a count of 3 that will never happen because no button can be selected.
In your actionPerformed you just update a variable to record which buttons were pressed, and if there are now 3 buttons then unlock or error. No loops!

Your idea ofappending into a String is OK. In your actionPerformed you can query the ActionEvent to see which button was clicked, then get the text of that button to append. No need for all those horrible repeated if tests.

Your code would be shorted and simpler if you follow the Hint and use an array of 10 buttons rather than 10 separate variables.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Even after you fix that...
When your method reaches the return statement it will immediatley return to the caller, and any remaining statements will not be executed. That's what your error message means - lines 43-49 can never be reached because line 41 will exit the method.

stultuske commented: ah, missed that :) +13
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

A good start would be to separate the GUI code from the newtworking code. Refactor it into two classes so you can create and swap a new instance of the network class without creating a new GUI class instance.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You didn't post the declaration of testgui, but apparently it's not a subclass of Component. The ".this" is even more mysterious.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

OK, cool it down folks.
stultuske is well known for saying what he thinks. If anyone doesn't like his posts then just ignore them.

Please don't get into a place where I have to infract anyone for violating the "Keep it Pleasant" rule.
Now, back to the original subject please.
JC

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You can break out of the loop as soon as you have found a match, ie:

for (int i ...) {
  if (prog....) {
     display token
     break;
}
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Unless there's some reason why to has to be an ArrayList, by declaring the variable as a List you allow the possibility of (eg) changing the implementation to a LinkedList sometime later, secure in the knowledge that you will not break any existing code.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

An nested class has access to the variables and methods of its enclosing class, and it can be private to the enclosing class. That's a completely different kind of sharing and encapsulation compared to a separate class. Which you chose depends on what you need.
Consider a Listener class in Swing. You want it to have access to the components of the GUI, but you don't want anyone lese messing with it.

Oracle has a good tutorial on this subject right here

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.

There are lots of people here who will freely give their time to help you become the best Java programmer you can be. There's nobody here who is interested in helping you cheat or doing your homework for you.

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

Maybe wallSwitch needs to be an attribute (instance variable) of the Enemy class, so each Enemy has it's own value for that variable?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Forget rmic and stubs. They have been obsolete for years. For current tutorial info and a working sample this is a good source of info.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

That's a pathetic post. If you want some help you'll have to provide a LOT more info than that. Do you think we are all mind readers?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

In rollConsec() you can change thewhile (true) to a do loop with a limited (eg 20) number of iterations

Doogledude123 commented: First time I had to use a do loop :) +3
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You read the first line (17) then use its tokens to add columns (20). You then read the rest of the lines (22) and use those to add rows (25). That's why the first line of the file goes to the column names.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Those 2 code fragments don't quite add up, but...
you have a 2D array 4x3, so the array's length is 4
in your loops you use the length to control the loop for both indexes, so you will have a problem with the second index.

In Java it's misleading to think of 2D arrays at all. All Java arrays are one-dimensional, but each element may also be an array. Sub-arrays do not have to be the same size. It's perfectly valid to have a triangular array like {{1},{2,3},{4,5,6}}. So in general, the safe way to loop through an array of arrays looks like

int[][] array = ...
for (int i = 0; i < array.length; i++) {
   for (int j = 0; j < array[i].length; j++) {
      array[i][j] = ...
ntaraaki commented: Thanks JamesCherrill +0
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

There are lots of people here who will freely give their time to help you become the best Java programmer you can be. There's nobody here who is interested in helping you cheat or doing your homework for you.

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

You want to run an app in another jar when a button is clicked?

The easiest way is to use the Desktop class which can open a file in its default application - if you open the other jar file then the default will be to run it using javaw. It's as easy as:

desktop = Desktop.getDesktop();
File JarFile = new File(thePathAndNameOfTheJarFile);
desktop.open(JarFile);

It doesn't make the slightest difference whether you use NetBeans, Eclipse, or any other development tools. A jar is a jar.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

There are lots of people here who will freely give their time to help you become the best Java programmer you can be. There's nobody here who is interested in helping you cheat or doing your homework for you.

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.

stultuske commented: only ups to be expected here +13