JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

An abstract class is a class with one or more methods declared abstract (ie the signature is declared, but there is no implementation. Becuase one or more methods are not implemented, it is not possible to create an instance of an abstract class.
An abstract class can be extended by another class. If that class does not provide implementations for all the abstract methods then that class is also abstract, and cannot be instantiated.
Eventually you get to a subclass or subclasses where every method has an implemention (inherited, or defined in that subclass). Now that subclass is not abstract, and you can create instances of it.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Create the Event class first.
The create a List<Event>. It doesn't matter what kind of List it is (ArrayList, LinkedList, Vector etc).

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You can now use aTask to do anything that's valid for a Task. Later you coiuld change the PracticeTest ofr a FinalTest or any other subclass of Task without breaking any code.
A better example:
List myList = new ArrayList();
myList has to be a List because of the logic of the program, but the code doesn't care whether it's an ArrayList or a LinkedList. Eg you can try both to see which is fastest without changing any other code.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

If you need to add events, then the obvious way to start is to create an Event class. It would have start date/time, and date/time, title, location etc as instance variables, with the usual getters and setters and a constructors. You can use GregorianCalendar instances for the start and end dates if you want (I don't agree with stultuske in this particular case).

Now you can do the rest in simple sub-tasks:

Create a simple GUI form to enter the data for a new Event.
Create a list of Events.
Define methods to search the list - eg get the Event(s) for a specified date
Use that to get the events for each day in you Calendar and display them
etc

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

That toggled loop looks to me like you are trying to go "procedural" where you should be event driven.
Normally in both client and server you would have a loop that waits for an inbound messages and handles them (updates game state and/or GIU).
In the client, GUI events (OK button etc) trigger sending an outbound message to the server.
In the server an inbound message causes a state update for the game that then sends an update to the client(s).

You enforce clients taking turns etc by enabling/disabling the appropriate GUI components based on the latest state of the game.

ps: If you have finished with your previous topic please mark it "solved"

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

startRunning creates an infinite nuber of concurrent server threads, each of which tries to open the same server socket. That's the wrong threading strategy.
To make things worse, you have that startRunning infinite loop exceuting on the Swing event dispatch thread, so it blocks all GUI activity for ever.

You need to start one thread with a ServerSocket, looping to accept connections.
As soon as it gets a connection it thens starts a new thread to handle that one Socket connection. The new thread opens the input and output streams and processes all input from that socket.

Ie you have one server socket thread plus one additional thread per socket connection. (plus Swing's EDT, of course)

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

:)

ps: Never NEVER 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

Well yes, but since you never use g2 you may as well delete that whole line. All it's doing is confusing anyone who reads it.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster
        public void paintComponent(Graphics g) {
            super.paintComponent(g);       
            g = graphic.getGraphics();
            g.drawImage(graphic,0,0,null);
        } 

You re-use the g variable on the third line here, thus losing your reference to the component's Graphics, so you draw the imge back onto iteself on the fourth line.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

What is the .exe file?
Simply re-installing the latest version usually fixes any out-of-date or incorrect registry settings.

Java 1.6 is years out of date, no longer supported, and riddled with un-fixed security problems. Unless you have some very specific requirement for some obsolete Java application, you should update to the latest 1.8 version immediately.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

No need for the Strings or the switch, classes are Classes in their own right!

Class[] carTypes = {Van.class, Cab.class ... };
for ( int i = 0; i < x; i++) {
   newArray[i] = (Car) carTypes[getRandomIndex()].newInstance();
}
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Sorry man, the first version looks right to me. Maybe it's OK but there's some other problem that makes it look like its not working?
If you post a runnable test program I can check it out on my Macs.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

There's something deeply suspicious about the data redundancy here that makes me unsurprised that your swap method has problems.

As I understand it theres a Tile[][] array that says what Tile is in what position, and each Tile has its x,y position as instance variables. Change one and you must be certain to change the other. One small code error and they will get out of step, with chaotic results.

In your swap routine it looks like there are 4 Tiles:
tiles[from.getPosX()][from.getPosY()], tiles[to.getPosX()][to.getPosY()], from, and to, but in reality there are only 2 and you are swapping around their references as well as their data. I tried to follow what was really happening in your swap, but between the redundant references and the redundant data it just made my brain hurt.

Now the only reason ever to duplicate info like that is to fix a performance problem. I know you are a fan of premature optimisation, but you are paying a high cost here. Your attampt to fix a non-existant performance issue is resulting in code that you can't write correctly or fix.

IF this was my code I would be thinking about getting rid of those instance variables, and just keeping the array. (Based on a guess as to how often you need to know which Tile is in a given position, as opposed to where a given Tile is. If I'm wrong the keep the instance variables and can the array.) IF there are cases where you just …

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Do you just want to shuffle all the Tiles?

Put them all in a List and call shuffle()
Then simply re-populate your x,y grid with the Tiles in their shuffled order.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

I can't read all that code, but it sounds like you should be using Key Bindings.
http://docs.oracle.com/javase/tutorial/uiswing/misc/keybinding.html

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

I'm baffled. That code is valid.
Is it possible that you have created your own class called Math at some point? If so you could try referencing the right class explicitly...
int randomNum = (int) (java.lang.Math.random() *5);

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

When you declare a variable its scope is from the immediately preceeding { to the immediately following }. So your excel variable is in scope from line 211 to 213 only. Outside that scope the variable cannot be used. You have to declare variables somewhere where their scope includes all the places where you want to use them (just looking at your code fragment, anywhere that's NOT in the if or else blocks would work).

ps: The approach you have taken is not certain - in particular the exists test followed by create new file is not an atomic operation.
You are on much safer grounds using the modern Files class and its createFile method https://docs.oracle.com/javase/8/docs/api/java/nio/file/Files.html#createFile-java.nio.file.Path-java.nio.file.attribute.FileAttribute...-

Edit: following Peter's note... the nio package (including Files) was always a standard part of Java SE 7, it's just that it wasn't pushed very hard until later.

peter_budo commented: Java 8, uhhhh, ohhhh.... Can't do it yet on Android ;-) +16
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

That message does not correspond to the code you posted, so that's useless.
Anyway - check your capitalisation... the method name is random not Random

ps: You will get a faster resonse by posting Java questions in the Java forum.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Wow, that's bad.
I see you are in Iran, and it seems Oracle have decided that they cannot supply Java technology to Iran under US law. Most people seem to think that they are wrong about that, but there's nothing you can do.
The tutorial problem is annoying, but the lack of Java security updates is really dangerous. To be honest if you can't get a secure version, then I would advise you to forget Java and use something that you can get maintained (C#/.NET?) in your country. This is very sad.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Yes. The tutorial on Sockets that I linked is the best place to start, but it's very clear that you do not yet have the basic knowledge to attempt such a complex application. Please start with something a lot simpler to build your skills.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

OK, if you really really want..
Here's an excellent tutorial on client/server messaging. It' part of the Oracle tutorials, which are by far the most complete, accurate and up-to-date tutorials for Java. Get started here.
Many other tutorials on the web are either out of date or downright wrong, so be careful out there.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

I agree.
You will need to create a user interface, create a IP server and an IP client, make a network connection, send data by using streams, and do all that in multiple threads. If you are new to Java this is far too much to tackle in one go. Have a look a our thread on projects for beginners (at the top of the forum listing) and try something simpler first.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You create a frame and a VectorDraw panel, but you don't add the panel to the frame!

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Have you tried redirecting the new process's output stream? There are various options for that (see the API doc). This one looks particularly interesting...

public ProcessBuilder inheritIO()
Sets the source and destination for subprocess standard I/O to be the same as those of the current Java process.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

The usual way to read a text file is to try to read the line and test for null/EOF at the same time, ie

String line;
while ((line=br.readLine()) != null) {
  // do something with line
}

anyway, I'm off to bed now. Nighty night. J

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You still need to create those lists - just declaring the variables isn't enough. (Maybe you just didnlt post that part of the code.)
Also
watch out for your readLines...
starting from the beginning of your loop...
line 2 reads the first line, and discards it
line 4 reads the second line (if there is one) and uses it
line 2 reads the third line, and discards it
line reads the fourth line (if there is one) and uses it
(etc)
ie every call to readLine() reads another line (until you reach EOF, when it reurns null - which may then cause a NullPointerException)

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

It's a class in the standard Java API that holds a list of values, like an array, but it grows automatically to fit whatever data you put in it. In this case you don't know in advance how many lines there will be in the file, so it's hard to guess how big your arrays need to be. With an ArrayList you don't need to worry about that.
https://docs.oracle.com/javase/8/docs/api/java/util/ArrayList.html

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

That code is mostly OK.
If you use i to index into the arrays to add the words (lines 8,9) then you need to increment it after processing each line (like lineCount).
Lines 2 and 3 create two variables that can refer to String arrays, but you haven't actually created any arrays. To create an array you need the new keyword, as in (eg)

String[] engList = new String[100]; // creates array with 100 elements

The problem is that you have to guess how big to make the array - which is why people tend to use classes like ArrayList rather than simple arrays.

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

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

This is the Java forum.
That's not Java code.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You have a single blank character at the start of the string.
Ie it's " 2", but it should be "2". The blank character is not valid when parsing an integer.

Maybe you are initialising out to " " instead of "" somewhere?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Java 6! Ouch. Enjoy all those unpatched vulnerabilities!

(Some employers never learn)

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

That's a nice refactoring,... for Java 7 ;)

Now for current Java you can take it a lot further and simplfy the code massively. I'm referring to the event handler(s). Just pass the action handling code to createButton, and completely get rid of the hidious 120 line universal ActionListener

private JButton createButton(String label, int size1, int loc1, int loc2, ActionListener al) {
   ...
   button.addActionListener(al);
   ...
}

then

// for one-line actions...
add(createButton("tansh", 70, 40, 100, 
    (e)->T.setText(Double.toString(Math.tanh(Double.parseDouble(out))))));
(etc)

// for more compilcated actions...
add(createButton("+", 265, 340, this::addMethod));
(etc)
...

void addMethod(ActionEvent e) {
    Double number = Double.parseDouble(out);
    double addition = 0;
    (etc)
}
(etc)
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

I'm confused.
If you want them to change together use one model.
If you wnt them to change independently use two models.
What's the problem?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

The problem is not with the tokens.
~s.o.s~ gave you the hint 21 hours ago, but you ignored it.
You create a variable called postFix, but you don't give it a value until line 44, so on line 23 it still has its default value of nulland when you try to use it, you get an NPE.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

If you want two independent spinners then why are you worrying about giving each its own model?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You misread the question.
I didn't ask what was in the DeQueue, I asked about the variable called postFix.
If youy are still confused, try printing postFix at line 33

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

No, it's not the token that's null.
What is the value of the reference variable postfix on line 23 in the code you posted?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

I think the problem here is that Doogledude is concerned that there will be a performance issue around saving and restoring his game state, and is trying to fix it in advance. Until the game is complete and tested the exact data to be stored will remain uncertain. There are also unanswered questions about whether his files will need to be compatible across Java versions, or with other languages.
In my opinion it's another case of premature optimisation. It's an irrelevant diversion away from actually getting the game complete and running. I would advise him to define an interface for saving and restoring the state, and supply the simplest implementation possible (which is, yes, to make the classes Serializable and write the whole thing to an object output stream).
As and when the requirements are complete, if and when there is a performance issue, then that may be the time to replace the initial implementation.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

"data written using DataOuputStream can only be read using DataInputStream i.e. it is portable across Java versions but not portable across languages/runtimes"

Were you thinking of ObjectOutputStreams? DataOutputStream just writes the bytes you tell it to write in the order you tell it. You just need to know that integers are big-endian. There's no reason why you cannot read or write the file from another language or runtime.

(But having said that, if you feel the need for your own binary file, then Google protocol buffers would be an obvious option)

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

int = 32 bits
short = 16 bits
byte = 8 bits
byte[n] = 8*n bits
etc

But check out the API - writeByte, writeShort, writeInt all take an int as parameter, so it's the method, not how the vars are declared that matters

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

I question the need for your own special file format ("much faster" probably means you will save a few microSeconds), but anyway...
You can use a DataOutputStream to write java primitives, byte arrays, and Strings to a binary file as a sequence of bytes in their normal internal binary format. And DataInputStream to read them in again.

DataOutputStream out = new DataOutputStream...
out.writeByte(0x4D);
out.writeByte(0x41);
...
out.writeShort(width);
...
out.writeUFT(id);

...

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

... and
3. Since you have a try-with-resources, your FileOutputStream is guaranteed to be closed when you exit the block, either normally or abnormally - which is more than your explicit close calls will do!

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Yes, and similarly for reading it back in.

ps: It's easier for us to read your code if you stick to Java naming conventions - connectionList, not Connectionlist (looks like it's a class)

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

No need to change that! A List is a Collection.

(interface List extends Collection, All Known Implementing Classes:
AbstractList, AbstractSequentialList, ArrayList, AttributeList, CopyOnWriteArrayList, LinkedList, RoleList, RoleUnresolvedList, Stack, Vector)

I was just making the point that you can read/write the whole thing as a single object, as long as it's some kind of Java Collection, eg ArrayList, as opposed to a class of your own.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Maybe just loop through the keys of one of the Maps, deleting all the entries that don't have a corresponding key in the second Map?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Yes - that's definitely a problem.
Your load will have to use a loop to read all the instances.

Alternatively (easier) is ConnectionList is an ordinary Java Collection, you cam simply write that as a single object to the OOS and read it as a single object from the OIS. That will serialise the list, and all the objects in it, in a single call.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

What do you intend with thisConnection and newConnection? They don't seem to make a lot of sense.

Anyway, you can only serialise a class that implements Serialisable (so check its API doc). Some classes (eg ones that are intrinsically tied to some operating system resource and use its state) are not able to be written to file and then restored by just reading them back in.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

I was suggesting java.util.Timer to update the model, not the GUI.
In general, the model may be CPU intensive (eg checking collisions between arbitrary shaped sprites) so I avoided javax.swing.Timer to keep that processing off the Swing EDT.
Yes, you could use firePropertyChange to trigger a GUI update. I just think repaint() is easier. In this case the OP is using GDX, so the method to invalidate the GUI will be different.

@centenoid. If you want to run on screen with different pixel sizes you need to build your model in some independent units (eg millimeters) then scale that to actual screen resolution when painting/updating the GUI.