JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Your model class can have public methods like, for example:

void setArg1(double newValue)
double getArg1()
void setArg2(double newValue)
double getArg2()
double getResult()

so in one GUI you can do stuff like:

model.setArg1(Double.parseDouble(num1.getText()));

and in the other GUI stuff like

num1DIsplay.setText("" + model.getArg1())
resultDIplay.setText("" + model.getResult());

becuase both the GUIs share the same model instance. all those values are shared via the model.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

It doesn't matter! You just need to process and remove entries until there are none left. Any Collection will do. With, I dunno, maybe a dozen entries there is no issue about space or runtime efficiency. Pick one at random.. how about about ArrayList?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

The "standard" answer is to have a "model" class that contains the input data and performs the calculation. You create an instance of the and pass it as a parameter to the constructor of all your GUI classes. Now ny GUI class can use the its input fields to set the data values, or query the data and the calculated result for display.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Why not just take a copy of the list at startup and remove each program from the copy when its started? When the copy is empty you are done, and the original list is still there for next time. (Presumably the original list is a disk file, and the copy is the loaded list in the Java program)

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Iterating any Collection will visit each member once. Do you specifically need to iterate them in the order in which they were created?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

What's the requirement for keeping them ordered?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Hi Aditya

Yes, we can help you - but remember that you must make an effort and try. The more you try, the more we will help you.

If you are new to coding then videoconferencing is going to be very difficult for you. It involves media handling, client-server computing, all kinds of advanced topics. Even an experienced Java developer would find parts of it challenging. What has gone wrong here? Has your teacher set an unrealistic task, or have you missed out on some earlier stages?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Although it is theoretically possible to use Java and .net, in practice it's not feasible.
Java comes with its own API that provides a superset of .net-like capsbilities, and is compatible across Windows Linux and Mac. Most Java developers use either NetBeans or Eclipse IDE - both free and downloadable from their respective web sites.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Yes, you can use -cp in the javac command instead of setting the classpath.

So did you download spark? It's not part of the standard Java distribution.

I've never used it, so I can't offer any more advice, but there must be some kind of user group or WIKI for it.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Sounds like the jar is not in your classpath. You should have CLASSPATH environment variable, and one of the entries in it should be where the apache jar is stored.
If not, either add the relevant dir to the classpath, or move the jar to somewhere that's already in the classpath

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

It would be helpful to know exactly what the error message says.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster
  1. Is SphericalCoordinate a kind of PolarCoordinate? If not, it shouldn't be a subclass. EndOf.
  2. Are there situations where you will use or accept a PolarCoordinate without worrying about whether it's cylindrical or spherical? If so, the common superclass will be useful
  3. Is there a useful amount of implementation detail that's common to spherical and cylindrical? If so a superclass could be useful
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

I think this is an old micro-optimisation thing that is irrelevant with modern compilers. The preincrement just adds 1 but the postincrement theoretically requires you to store the initial value before incrementing. Nowdays that would be optimised out anyway.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

OK, let's think about it...
What's different between any two "buy product" processes? Only the user.
So we can code it as a method with just one parameter...
void buyProductFor(User u) { ...
in that method we can display the products, get the user's input, update the user's cart, and return.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

That will just loop forever calling itself.
You have to read that tutorial properly.

In pseudo code the equals method is going to contain some logic like`:

if (the other's name is the same as this name AND
    other's username is the same as this username AND
    other's contactNo is the same as this contactNo) THEN
        other is the same user as this

The code for that will be something like

if (getName().equals(other.getName() && 
    getUsername().equals(other.getUsername() && 
    getContactNo().equals(other.getContactNo()) 

    return true:
else 
    return false;

There's also some code for other not being a user at all, but have another look at the link I gave you. You can ignore the section on inheritance at the end, but the code immediately before that section is totally relevant.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

No no no. That was just a way of explaining how contains works.

It needs to be able to test if any user in the list is the same as the new user. That's where the equals method come in. You need to define an equals method in your User class. This tutorial explains it well.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

The loop (line 1) is totally wrong.
First time thru the loop you add the user
Second time thru the loop the user is already in users, so you take the else.

You don't need that loop at all!. Just delete it.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Best not to reinvent the wheel. List already has a contains method

boolean contains(Object o)
Returns true if this list contains the specified element. More formally, returns true if and only if this list contains at least one element e such that (o==null ? e==null : o.equals(e)).

so for clarity and safety...

if (! users.contains(user)) users.add(user);

How can I make it so that I can get display the profile of the newly added user instead of the pre-existing user?

Whether you need to add the user or not, the variable user still refers to the new/current user, so you can use that to display the profile.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

There are more than one ways to do this, but here's one:
Start with an ArrayList containing the numbers of the columns with no queen. Initially it will contain the numbers 1..8.
For each row, pick a column number from the ArrayList at random, place a queen at that row/col, remove that entry from the ArrayList (thus ensuring that you never place another queen in that column)

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Are you sure the .fxml file is in the correct directory structure inside your jar?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You will need two nested loops
One to generate the lines like I split them up above, and an inner loop to to generate the 2x4x6... sequences

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

2 +
2x4 +
2x4x6 +
2x4x6x8 +
(etc)

see the pattern? Exactly what help do you need?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You have TWO login dialogs - one created in main (line 24), the other created in showLoginDialog() (line 72).
The line 24 one gets the action listener, but the line 72 one is the one that is displayed, and that has no action listener.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Debugging is not an answer. The behaviour of that code is undefined in the standards, so any compiler.now or in the future, can implement any order of evaulation it wants. Confirming that it works with one particular compiler is just setting yourself up for a disaster later. The code is bad code, downright wrong code, and should never be allowed to live.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Yes, something like that. You will need to deal with moving in the other 3 quadrants, of course, but you could set up a test that's up/right to confirm before doing the other 3 cases.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

If your speed is a constant then you can only make 0, 45, 90 degree movements. To get any other angles you will need to vary the speed.
Eg:

if
deltaX = distance to be moved in the x direction
deltaY = distance to be moved in the y direction

if deltaX > deltaY
go full speed in x direction
but speed in y direction must be slower, ie speed*(deltaY/deltaX)

( and v.v if deltaY > deltaX)

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Have you tried calling getText() for your two JTextFields after the dialog has finished?

The simple pre-packaged dialogs in JOptionPane are just that - simple. The assumption for inputDialog is that there is one entry field and one value returned. For your two-value case you should create your own simple dialog and query the field contants via their getText() methods afer the user has pressed OK.

Start4me commented: Thank you very much, I appreciate your help +2
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

There are two ways to approach this:

Create a new "empty" object using a default constructor, then call its set methods to populate all its data (no need to call the get methods)

Have a constructor that takes all the data values and creates a fully-populated object

OR any combination of these - eg pass all madatory data to the constructor, then use set methods for optional data

There's no absolute right or wrong here, it depends on the details of the particular case.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

divinity02 has started 38 threads in the Java forum over the last seven months and is still unwilling to ask sensible questions or post proper error messages. None of those threads has ever achieved "solved" status. Maybe we are all wasting our time here.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Exactly waht command are you using?
Does your source file start with a package statement?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

... that sounds like you are doing the right thing already.

Maybe this is just an example of "premature optimisation" - trying to fix a performance problem before you know that there is one?

Unless you're in some kind of expert corporate-scale development, the best advice is to get it working with sensible simple implementations first. Then, and only then, if there's a performance issue, identify exactly what/where it is before spending time making the code more complicated.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Looking at that I wonder if you can/should split updateAndRender into two methods so you can call update for all the entities, but only call the expensive redering for the visible ones?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

I'm confused about the client updating entities.
Yes, the client will render all the entities that are in its current viewport. But the clients do not have enough information to update all the entities.
Normally the server will hold the complete state of all the entities. Clients will get mouse clicks, keys presses etc, and send requests to the server to update the state. The server will send the latest state info to the clients, who render what they need to render.

It sounds like you may be mixing updating and rendering together in some way? (it's important to keep them completely separate)

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

If you don't keep them all updated, how will you know what their correct state is when they come on-screen? If you don't keep their position updated, how will you know when they come on-screen??

Keep the state separate from the GUI, so updating the state is a quick as possible. Run that in a non-GUI thread. Only worry about how they are painted etc when they are visible.

How many entities are we talking about?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

code III has invalid syntax = it uses the method names without their ()

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

It's worth a try BUT...
== and != test for Objects being/not being exactly the same object (same address in memory).
You want to know if two different InetAddress objects represent the same IP address, for which you have to use their equals method

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Your "just a typo" has probably wasted all kinds of time for people who have read your code trying to help you. An apology would be more appropriate than just laughing it off.

Anyway what exactly happens when you try to send to multiple clients?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

What's the relationship between the address and addressList Lists?
Are you sure that addressList contains all the entries you expect? Is the size() of address as large as you expect?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You could try combining all those arcs into a single shape that will then fill properly. A Path2D.Double may be the best option.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You cannot mix Data streams and Readers/Writers - they use completely different data formats. Data sttreams send (binary) data, readers/writers send text.
Either use a DataOutputStream to send data to a DataInputStream, or use a PrintWriter to send text to a BufferedReader

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

If this seems a bit vague and ambiguous, then that's because it is. The technical differences between abstract and interface have been blurred even more in Java 8.
The best way to think about it is to look at the intent behind it.
If you want to define a contract that some classes can meet, then look at defining an interface. If there are multiple overlapping contracts then definitely use interfaces. eg Runnable, ActionListener, Serializable.
If you want to create a master template that other classes can use as a common standard base then define a abstract class. Eg Vehicle, RectangularShape

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Yes

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Looking at the next line in the stack dump, the parseInt was called from line 111, so it is the "Year" tag that has a null value

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

aTask is defined as being of type Task, so you can use it to refer to any methods defined in the Task class. If, and any particular time, it happens to refer to a PracticeTask, then it will use the method definition from the PracticeTask class - which may be defined in that class or inherited from Task.
What you can't do is refer to any methods that are declared in PracticeTask but not in Task

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

No. If you have any abstract methods then the class MUST be abstract.

There's no need for subclasses to use any of the parent's methods if they don't want to. But the compiler doesn't know all the contexts in which the subclass may be used, so it has to ensure that you could legally use any of those methods.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Why re-invent the wheel?
Why not use ObjectOutputStream and ObjectInputStream to write your meeting data as Java objects and read them in the same way? If there's a top-level object that holds the whole list of meetings then you can just write/read that as a single object.
Alternatively, if your own classes conform to normal JavaBean protocols (getters setters etc) you can use XMLEmcode/XMLDecode to convert the whole shebang to/from XML and write that to a text file

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

stultuske: yes - you are right. The JLS says
"A class type should be declared abstract only if the intent is that subclasses can be created to complete the implementation...", but it does not prohibit such a declaration.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Why do you have that test? Why not just listen for packets and process them whenever they arrive?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

No, the problem is here:

void whileChatting()  { // 
        do {            
            if (this.packet == null || !this.send) { // null means receive first packet
                this.packet = receivePacket();
            }
            if (this.send) {
                sendPacket();
            }
            ...

A loop like that just should not exist.
You should have a thread that connects to the server then loops waiting for and processing input from the conection. In general it does not send. It doesn't depend on whose move it is. It must NOT be the Swing EDT.
You send when the user clicks the OK button or equivalent.

Ihave no idea what the intent of your run method is. If you call that on the EDT you will just hang the GUI, in any other case it will just hang around doing nothing. Why?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Back up one step...
You declare a reference variable of type Task. That variable can refer to any instance of Task, or any instance of any subclass of Task. (Because any subclass of Task has all the methods that a Task has). You can use that variable to access any method defined in the Task class. If the variable refers to a subclass of Task then those accesses will still be valid, regardless of whether the method's implementation is inherited from Task or overridden in the subclass.