JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You use a variable for the switch, but you need the constants for the cases, as in

switch (dir) {
  case Direction.RIGHT: ...
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You just need public methods in your existing java file that the GUI can call to access the data it needs. The existing code shields the GUI from all the complexity of the SQL and separates your application into layers that make it much simpler to understand and support.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

I think that question needs to be clarified. Does the existing java file handle data from mysql that you now want to use in your GUI?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

If your tabs are all different then there's no point doing anything other than simple JPanels.
If they all conform to certain style or content standards (eg a background image, or certain controls always in the same place) then its worth creating a subclass of JPanel with all the common elements, and instantiating that for each tab as a starting point.
I can't see any circumstances in which you would benefit from creating different subclasses for each tab.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

^ like Norm said.
J

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

If the field is an Object then yes (unless null is a valid value for it). But if it's a primitive then no, because they all have default values (0 or false).

Looking at all the info you have provided so far I would suspect that ip is null for some value of i

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

DataOutputStream and writeInt(...)

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

BMP picture or machine instructions? Am I the only one who is confused?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

The problem is your original post said "How do I do this in Java giving the same output as the C++ program?".
Without that constraint, writing Java ints to a bin file is trivial.
This being a Java forum you can't assume that we know how C++ writes binary files.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

So, your first 4 values are 11111111 11112111 11234111 22222222 ...
and the file begins (in hex bytes) 14,00,00,00,28,00,00,00,D8,8A,01,00 ...

Sorry, but I can't see any connection between those two. I have no idea how those integers are encoded into that hex.
Maybe we can go to something simpler, like writing the values 1,2,3 to a new file from the C++ program and dumping the resulting file?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

No I don't. Maybe it's just me. My wife's always telling me I can't see things in front of my nose. Can anyone else out there see it???

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

? attached?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

... usually it complicates things when you start changing other peoples code (maybe there is some requirement), if the code is correct.

Yes, I agree. I only jumped in here because things seemed to be getting more and more complex without ever getting correct. Anyway, I'll leave you in peace now.
J

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

line 142 reads: if(ft.id==ip.t.id)
so print every one of those values (including intermediates like ip.t) immediately before that line to see which is (are) null.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

I don't mean to butt in here, so please feel free to ignore this post.

This method seems to be spiralling into more and more complexity, but I didn't see anything in the requirements that needs it to be so hard.
What's wrong with something simple like:

public void removeObject(T anObject) throws CannotRemoveException {
   boolean removedOK =  theList.remove(anObject);
   if (removedOK) return;
   else throw new CannotRemoveException ();
}

(that was the long version for clarity) you can code it as

public void removeObject(T anObject) throws CannotRemoveException {
   if (! theList.remove(anObject)) throw new CannotRemoveException ();
}
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

In terms of Java language, Java requires that when you construct a new instance the constructors for the class and all its superclasses get run, superclasses first.
To achieve that either
1. You start your constructor with a call to a superclass constructor
or
2. The compiler inserts one for you at the start of your constructor. The call that the compiler inserts is a call to the default (no arguments) constructor of the superclass, ie super();

In your code you don't call a superclass constructor, so Java inserts a super();
But the superclass doesn't have a default (no args) constructor. so that's the error message you get.

In terms of design your problem is that in your subclass you think about initialising the extra fields for the subclass, but you forgot that you inherit from the Room class a bunch of variables that still need to be initialised.

Think on that for a while. If you still can't see a way to solve it come back here for some more hints.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

In my opinion, that shouldn't be a problem because I haven't specified values for indexes 2 and 3. However, I changed the number of elements in my array to two elements and I'm still getting the same error. Anyway, thanks for your comment.

Unfortunately for you, in Java's opinion any attempt to reference an element bigger than the array is an error. If you have an array of 3 elements you can only refer to nums[0], nums[1], nums[2]. Any kind of reference to nums[3] is an error, whether you've specified values or not.

You still have exactly the same problem in your for loop. The way you coded it gives values for i of 0,1,2, and 3. When you use i=3 as an index for your array that's the error. Look again at your for loop, and especially it's termination condition.

stultuske commented: well explained for those who actually read it. +12
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Please tell exactly what the correct contents of the file should be, in hex.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

The ListIterator interface exists specifically to solve this problem (illegal modification of the List while it is being iterated over with a normal Iterator).
Use theList.getListIterator() to get the list iterator and use that to loop thru the ArrayList - you'll be able to remove the appropriate element without generating an Exception. See the API doc for details.

ps There's a subtle problem with hiddepolen's solution, which is that the code to identify the object to remove tests for the class name being the same before it tests equals(...). However, the remove(...) method just tests for equals(...), so it's possible that there is an element before the right one that is of a different class (presumably a super or sub class) that also equals(...) and that will be removed instead. I admit that this is a bit obscure, however.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

I don't have time now to understand the whole structure of your code, but at a guess you have two methods there, a paintComponent that should finish around line 62 and an initialisation method that includes all the following code.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

With the code you posted it looks like you lost a } when you commented out all that code from line 40 in logo. It now looks like you have all your GUI creation code inside the paintComponent method, so every time it repaints it creates new stuff.

David321 commented: Really helpful +2
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Your loop tries to access these array elements:
nums[0], nums[1], nums[2], nums[3]
but there is no nums[3]

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Instead of all those text-style menus in dialogs, you could pop up a small window or dialog with buttons for each of the functions - that would be a more Windows-like approach. You could also decorate that window with a bank logo in the background.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

i <= nums.length is the problem

array is length 3, so valid indexes are 0,1,2, Your code executes with indexes 0,1,2,3

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

OK, sorry about the confusion. writeInt in a for loop sounds right. Can you post the exact code? Remember that Java ints are 4 bytes, not 2. For a 2-byte int you need a "short".
Maybe you can post the original int array values, and a hex dump of what you expected and what you actually got in the file. That would allow us to home in on the correct solution.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

I'd be very interested to hear how you did the "snapshot", but yes, there's no way around displaying the incremental stages of the "flipping" graphics in a loop. (But not a loop as such - that's going to mess up Swing's event thread - use a javax.swing.Timer to control the update/repaints).

If you don't need to compute the views on the fly you could maybe use an animated GIF created in Photoshop or whatever to simplify your Java code.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

OK, looking at Norm's post I may have answered the wrong question.
Do you want to write objects to a (binary) file in a Java way, or do you want to mimic exactly the same sequence of bits that your C++ code would have written?
I previously answered the first of those.
For the second answer you can use a DataOutputStream and its methods like writeInt, writeBytes etc to write individual primitive values in their normal binary formats, but you will have to do as Norm says to confirm whether that's exactly what the desired format is.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Starting with a Serializable object, you can write it to an ObjectOutputStream with a single write, and read it back from a corresponding ObjectInputStream ditto.

NB: The JavaDoc for many classes warns that the serialisation format may change from one release of Java to another, so its not suitable for writing files for long-term storage of data, but it's OK for short-term storage or sending Objects over TCP/IP sockets etc.
For a safer and more comprehensible approach, have a look at XMLEncoder and XMLDecoder. These utility classes convert Objects with standard getter/setter methods into a simple XML format that you can safely write/read/send just like any other pure text file.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You have an arraylist of Objects, that happen to be Integers, which you try to use to create an array of Strings. You can't store Integers in an array of Strings.
Here's what the API doc says:

public class ArrayStoreException
extends RuntimeException

Thrown to indicate that an attempt has been made to store the wrong type of object into an array of objects. For example, the following code generates an ArrayStoreException:

Object x[] = new String[3];
x[0] = new Integer(0);

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

k is defined as a String. There is no insert method in the String class.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

I don't want to start an argument here, but I must point out that not everybody will agree with stultuske's post on exceptions for user errors. It's a genuine controversy in the Java world. I'm not going to argue for one side or the other, but I will point out that the designers of the Java API do sometimes use exceptions to signal bad user input - eg input mismatch exceptions from Scanner's nextInt().

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Simple rule of thumb:
Make all your variables private.
More complex real-world version of this rule:
Make all your variables private.

If, later on, you discover that other classes need some kind of access to something, create a public method.

In this particular case Scanner is a part of your user interface. That kind of console-based UI should all be in one class; if you have a Scanner used in multiple classes you lose control over the state of the Scanner - eg if you call nextInt() should you do something to move the Scanner to next line or not before some other class tries to read the next token?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

OK. maybe next time a quick look at the forum guidelines before posting?
http://www.daniweb.com/forums/faq.php?faq=daniweb_policies
You'll find we're quite friendly here, but a bit impatient with people who don't want to do any work themselves.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

That's not how these forums work.
Ask for help after you've done some work yourself.
Two minutes with Google will give you all the information you could possibly want on bubble sorts in Java.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

OK. Mark this "solved" please.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

reverser.toString();
This line creates a String and returns it, but you do nothing with the returned value. It doesn't change reverser in any way.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

cannot find symbol
symbol : variable getSelectedItem

It's a method call, needs a ()

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

I wonder whether I did my convertToLatin correct or not?

Well, did you test it? What was the result?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You're getting into a tangle with inner classes and whether they are static or not. Rather than get into all that obscure theory, I would not make them inner classes at all. You can keep them all in the same package if you need to group them together for access control or whatever.

abstract class Person{}
abstract class Employee extends Person implements myInterface{}
class Agent extends Employee { ... }

ArrayList<Employee> employeeList = new ArrayList<Employee>();
employeeList.add(new Agent(myStringArray));
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

de rien.
J

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

When you define a variable you can initialise it with a single expression that returns a suitable value. You already know about int a = 99; or maybe int secondsPerYear = 365*24*60*60; so this is just a slightly more complex example int b = readF.getNumberOfLinesInMyFile(); What you cannot have is an initialisation expression outside a variable declaration.

(To be exact - there are also things called instance initialisers, but you don't need to worry about those now.)

ps: You don't need your lignesDeMonFichier variable because ArrayLists have a size() method that gives you the number you need. By calculating it yourself you just do more work, and create the possibility of getting it wrong sometime.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

loop through the times array to find the lowest time, then do it again for the lowest excluding that one.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

times=i;

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Your { and } are messed up. Format your code properly, with correct indenting of all the {} and it should be clearer.
The line numbers in the error messages don't match the code you posted, so it's hard to understand, but

do
}

is probably a mistake

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Yes.
I was just thinking about the first part - explaining the problem of lost updates, and exactly how the actual output may vary from the expected output.
I agree that the rest of the article, no matter how relevant it may be to real life, isn't exactly what the OP's homework is calling for.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Here's an article that explains simply and briefly what this exercise is all about:
http://www.informit.com/guides/content.aspx?g=java&seqNum=248

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Three letters: M V C

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

So how many server computers are you talking about? If you want to hand the connection off to a different computer in a server farm, then sorry, I don't know how to do that. If it's two threads on the same machine then there's no advantage in changing ports.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You can have one ServerSocket that sits waiting in a loop accepting connections and passing each one to a new Thread that handles ongoing communication with that client. There's no need to change to a new port to do that.. Ie you can have one ServerSocket and multiple Sockets on a single port.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

My guess is that you cannot transfer an open connection from one IP/port to another while keeping it open.
Why do you want to do this? Maybe there's another way...