JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Did you remember to call the method that reads the file before you try to display the table? If so, let's see all your code for the datamodel class.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

No! Don't convert rosterList to something else, what you've got is fine.Your problem is in
ArrayList rosterList
Because you don't say what the members are, all that Java knows is that they must be Objects. If you declare it fully, Java will know what they are String arrays and be able to handle them properly:
ArrayList<String[]> rosterList = new ArrayList<String[]>();

===========

Hi BJSJC - thanks for covering this while I was offline. OP has a data file with a variable number of lines, each containing a fixed number of separate values. While working on the read file part of this we ended up with an ArrayList for the lines, each consisting of an array of the String values. Hence ArrayList<String[]> and the get(line number)[data item number] notation

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Sorry - typing too fast! Yes it's get(int). Sorry. What's the error?
Your fragment shows )} at the end, which should be );}

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Your compiler should have told you that rosterList.size is an error. It should be rosterList.size();
You can delete all the data[][] stuff because your data is stored in the rosterList.
Beware of becoming dependent on step-by-step "is this OK?" posts. You won't learn so much or so well that way. Give it a try, see if it works, if it doesn't work try to see why, and only ask for help when you are stuck.
James

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Yeah, you declare it in the creatArr method, so it's limited to that method. If you move its declaration to outside the method (ie just in the class) it will be available to all the methods.
ps Don't forget to call creatArr before you try to display the data or there won't be anything to display.
pps getRowCount() needs to return the number of rows (String arrays) in rosterList

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Don't give up - you're almost there!
Suppose, when you read the data file, you store the rowfields array into rosterList instead of line. Then your getValueAt method can be

public Object getValueAt(int row, int col) {
    return rosterList.at(row)[col]
}
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

The missing step here is that you have stored your data as a 1-dimensional list, whereas it really needs to be stored in some kind of 2D structure to fit int0 a table (original lines as the rows, with the split elements as the columns). You could use an ArrayList of String arrays, or an ArrayList of ArrayLists, or various other solutions.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

ArrayList and Vector are interchangeable as far as this app is concerned; the subtle differences between them aren't relevant here.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You may want to do some more clever formatting of your output - the simple code you have now just proves that it works, even if it does overflow your console window. the print(...) method is just like the println(...) method, except that it does not put a new line character after every print. This will enable you to print multiple items on one line and thus see more clearly what's going on...

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster
br = new BufferedReader(new FileReader("mydata.txt"));
String line = br.readLine();
while (line != null ) {
    rosterList.add(line);
    String [] rowfields = line.split(" ");  
    for (String s : rowfields) {
          System.out.println(s);
    } 
    line = br.readLine();
}
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Of course it does. If it was inside the first loop it would print the split version of every line.
ps: the "enhanced for loop" syntax is easier and less error-prone:
for (String s : rowfields) {
System.out.println(s);
}

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You split the line into the String array rowFields, but then you do nothing with it. Perhaps you should loop thru the members of that array printing them, or storing them somewhere.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

1. 22/7 is a calculation using 2 integers, so it's performed in int arithmetic, giving the int result 3, which is then assigned to the long variable. Just making one of the values a floating poit number will force the calc into floating point, eg 22.0/7
2. When you calc the volume you pass in a radius & height, which are the same both times. The volume method should not need any parameters, it should use the values it already has.

AirmanTheGreat commented: Win +1
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

where do you try to print ip etc. Is it inside the loop?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

One class can only have one constructor with any given list of parameters (although it can have any number of constructors that take different parameters). So it makes no sense to copy a constructor in the same class. If you create a subclass, the superclasses' constructors are NOT inherited, so you need to create new constructors for the subclass. In that case you MAY start by copying the superclasses' constructors, although the normal practice would be to write a small constructor that just calls a superclass constructor as required.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Java's not the best choice for this kind of thing.
Here's a script that does what you want:
http://www.interclasse.com/scripts/killpopup.php

ithelp commented: Thanks. ithelp +6
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You need one more loop, to include your existing loops. This is the loop that will keep reading new sets until the file is empty. You can make it an infinite loop (while (true)...), and break or return out of it when the readline() hits E.O.F.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

... but if all you want to do is have a default button clicked when you press "enter", see getRootPane and setDefaultButton in the Swing API

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

The "official" way to perform the same action from different UI events is to use Java Actions. See
http://java.sun.com/docs/books/tutorial/uiswing/misc/action.html

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

... So I don't see why there couldn't be a list of Listeners (in the model), one per category. Or would it be better to just set it up like Ezzaral said, with only one list of Listeners, and in the GUI, the stuffChanged method would decide which windows needed to be updated?

I think there's no one right answer here. As long as the Listeners are defined in terms of what's in the model, rather than what's in the GUI, you should go for whatever gives the cleanest easiest to understand implementation for your particular case.

As for 3-layer, you can always take all the response handling code out into a separate class, and hey-presto there's your controller (!).
But... when people talk about "3 tier architecture" they more usually mean user interface / business model & logic / data storage & persistence. So in your example the third layer would be the (so far unmentioned) database or whatever the patient info is stored in. I guess you have to take the context of your course to see what applies here.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

... how would it be implemented with a Controller? Ezzaral's example only used a model and a view. I'm curious how it'd work with all three as separate parts.

I'mo going to come clean here: I don't think that separation of the controller and the view works well in a typical Swing app, and I personally rarely do it. The controller needs so much access to the fields in the view that the code is far simpler when they are in the same class.
Where a controller becomes useful IMHO is when you have a complex model consisting of a number of elements. In that case you would use a controller to organise them all - eg you may have an app for purchasing an item. The model layer may involve: items, warehouse stock, customer details, pricing and discounts, delivery methods etc, so it would make sense to have a controller that called on all those elements in turn to complete the overall process.

The answers to your other 3 questions are: Yes, Yes, Yes.

Let me know if you still want a bit more flesh on the trivial example.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You may want to glance through this article as well, which shows a simple pattern of even further separating the observers from the observed with a message queue on a separate thread:.
It's probably overkill for what you have in mind...

I agree. But it reminds me of one important point in the Swing environment. The change to the model may well happen on a thread other than the Swing EDT thread (eg some database access or network-based server thing). If the model just calls the listeners, and they go ahead and start doing UI updates (as in my previous trivial example) you have the potential for horrible concurrent access thread bugs - remember that Swing's code is not thread-safe. In my own code I sometimes have to have two ways for a listener to register itself, depending on whether or not it wants to be called back on the Swing thread.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Part 2: thoughts on push vs pull.
I think it's a false dichotomy; you have both.
The model will have various public getter methods that a UI can call to get valid current data from the model any time it wants. That's what may probably happen when the window is first opened, for example.
The problem is that the UI won't know if its data becomes out of date, and that's where the Observer pattern kicks in. The listener interface should not attempt to transmit every detail of what's changed; it should give enough info for an Observer to decide if it's interested.
Trivial example:
Model is a Customer class. Public methods getName, getAddress etc etc.
Listener interface could look like this:

interface CustomerListener {
   public void customerChanged(Customer c);
   public void customerAdded(Customer c);
}

Typical code in the UI could look like this:

public void customerChanged(Customer c) {
   if (c != theCustomerImCurrentlyDisplaying) return;
   nameField.setText(c.getName);
   ... 
}

So the fact of an update is pushed to anyone who's interested, but the details are pulled only as and when required.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Hi guys! Just saw this thread and had to join in!
For me, the key issue about separation of GUI and model is about good architecture. Sure, you can hard-code calls to the GUI in the model, and hard-code calls to the model in the GUI, but if you do both you just get one big ball of spaghetti and an inevitable decline into chaos.
IMHO GUI/model separation requires the use of Observer, no choice.
The point is that the model just implements an Observable interface, and has no knowledge of the GUI or anything else that may use it.
You can code, compile, and test, the model without the GUI, then you can safely put it in jar, and get on the the GUI as a separate task.
The project I'm currently doing enhancement work on has one model, but supports three user interfaces (local GUI, remote GUI, web browser). Because it had proper Observer architecture, adding the web browser interface required zero changes to the model or the GUI code. That's enough to convince me.
In response to the specific Q about lots of windows and selective updating: I think you should not try to split the Observable interface into sub-interfaces to meet a GUI requirement; that's just another way to entangle the two layers. Provide an Observable interface that's designed around the model and what can happen within it. Windows, or whatever, can register with the model if they want to …

Ezzaral commented: All good info. +20
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

size(), as it says in the API doc, returns an integer, which is the number of elements in the Vector. It doesn't return the element itself.
To get an element you need elementAt(int). Since elements are numbered from 0, the last one is number (size-1).
ps Having said all that - have a look at the lastElement() method for Vectors.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

To know where the last item is, your program can either keep track of the size of the Vector, or you can use the Vector class's size() method.

Definitely use size(), why do it yourself?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

GMT-5

Wow, you get up early!

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

GMT+2 (including summer time). I'm certainly up for discussions on design patterns. I've spent many years teaching and consulting on OO design with companies such as IBM and HP, so it's a real passion of mine.
For starters, let me suggest that MVC in Swing really doesn't fit. It's painful to try to separate the view from the controller in a typical Swing UI. In practice it almost always compacts down to a UI / Business Objects(s) 2-layer model. You only need full MVC where there are many business objects and you need some kind of overall "process control" to marshal them.
Or maybe we should take this to a new thread?
J

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

OK neutralfox, stick with it! (ps what time zone are you in, if you don't mind saying?)

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

So, a superscript?
http://java.sun.com/j2se/1.4.2/docs/api/java/awt/font/TextAttribute.html May be of use.

Do they work in the console? I suspect not. You could use the unicode symbols for ² or ³ (00B2 and 00B3), but that's all, I think.
In JLabels and the like you can use HTML formatting, of course.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

I can't add much to what I said in post 9. I would separate the GUI, the server, and the connection handler into 3 classes, and make sure each is started in its own thread. This really looks like the code "just grew" to the point where it's too hard to work with, you have to go back and do a bit of design!

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

(sorry man, need to go offline now, will get back tomorrow with any luck)

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Don't have time to read all code now, but it looks like you're still starting the server in the Swing thread!

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Maybe changing your class name to something other than vector will help avoid clashes with java's Vector class?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Without an up-to-date code listing there's not a lot I can do, but...
Maybe you should take a few moments to clarify your architecture in terms of its threading. You need 3+ threads, (1) The "swing" or "EDT" thread where you do all your user interface stuff. (2) The server thread where you wait for new connections and (3) the connection handler thread(s) that you create to handle each connection as it's made.
So in your main(...) method I would expect to see a call to set up the GUI (which if you want to be pedantic you should schedule on the Swing thread, but few people would bother), and a new Thread to start the server. Judging by the code you posted, I suspect you may be getting problems because you have mixed the server code in with the GUI code - they really should be separate.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You start the server on the Swing event thread, and in that you wait for the connection, thus blocking the Swing thread.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Not certain that I understand the Q, but you can only have 1 run() in a class, so if there are other things you want to start new threads for you need an additional small Runnable class to do it. You can use an anonymous inner class (Google it if unfamiliar) for this, like this:

new Thread(new Runnable() {
  public void run() {
      // call a method in your main class to do the work 
  }
}).start();
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You can get an aray of pixels to do your scanning/looking for algorithms by using the PixelGrabber class (I've attached some code I wrote earlier that will give you a head start).
To decode an RGB pixel int, this works:

int pixel = // whatever,  eg getPixel(x, y);
// int alpha = (pixel >> 24) & 0xff;
int r = (pixel >> 16) & 0xff;
int g = (pixel >> 8) & 0xff;
int b = (pixel) & 0xff;
public class PixelArray{

	// useful (?) stuff for image processing via PixelGrabber's pixel array

	private Image image;
	private int w, h;
	private int[] pixels;

	public PixelArray(Image im) {
		image = im;
		w = image.getWidth(null);
		h = image.getHeight(null);
		pixels = new int[w * h];
		PixelGrabber pxg = new PixelGrabber(image, 0, 0, w, h, pixels, 0, w);
		try {
			pxg.grabPixels();
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
	}

	public int getPixel(int x, int y) {
		return pixels[x + y * w];
	}
}
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

I just had a quick scan of your code, so I may have missed things, but...
In the actionlistener you overwrite the value of sTable that you set up in the constructor, so it seems pointless to have passed the value into the constructor in the first place. Is this what you intended?
Plus, if you want to display the new JTable that you create in the listener, shouldn't you add it to a visible frame or panel of some sort?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

java.awt.Desktop.getDesktop().browse(new URI("http://www.your.url")); (needs Java .6)

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Without seeing all the code, my best answer is "don't know". Sorry

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

What's wrong with getSelectedValue() ?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

So, if you've got two threads executing at the same time, and they both try to use the same object (such as an OutputStream) at the same time, you can get "unexpected" or "unpredictable" results (aka absolute chaos).
The synchronised (...) { ...} syntax mens that the current thread tries to get a lock on the object. Once it's got the lock it will go on to execute the code in the {} and when that's finished it releases the lock.
If a second thread tries to do the same thing while the first thread still has the lock, the second thread will be held up and will wait in the synchronised statement until the first thread releases the lock. Once the lock is released, the second thread will be able to lock the object and continue its execution.
This means that all the threads that want to use the object will have to wait in turn, and only one of them will ever bea able to access it at one time, thus making the program "thread safe"

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

If you have a single processor the two (or more) threads will share it according to some process that you don't get involved with. In particular, if one thread has to wait (eg for user input) the other will be able to continue running.

"this" represents the current instance of the class. In your example new Thread(Client) would try to use the class itself, not the current instance.
Whenever you run an ordinary (not static) method, you have to specify the object that it will run for eg myString.toUpperCase(); the toUpperCase method is running for the object myString. During the execution of toUpperCase, the code could refer to "this", which in the example would be myString. If you then called
myOtherString.toUpperCase(), "this" in the toUpperCase method would now refer to myOtherString.
In a constructor "this" refers to the object that's being constructed.
I don't know if you can use "this" in a static method - if you can it would presumably refer to the class iteself (?).

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

The OO purist solution is to create a tiny class to hold info about the term of the polynomial., as in

class Term {
  private int power, multiplier;
   public Term(int power, multiplier) { etcv};
  // getters as usual
  // other useful stuff such as calculating the term for a given x
}

then the polynomial just becomes a vector of Terms:

Vector<Term> polynomial  = new Vector<Term>();
polynomial.add(new Term(2, 4)); etc

Maybe overkill in your case, but it's a good direction to start off in!

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

this represents the object whose method is currently executing.
A Thread is a separate stream of execution (eg if you have a dual processor, you can execute two threads simultaneously).
Your class implements the Runnable interface, which consists simply of a public void run() method.
So new Thread(this) creates a new thread in which code from your current object ("this") can be run. The start() method sets the thread running by calling the run() method in your current object.
Whatever is in the run() method will start to execute in parallel with whatever follows the new Thread(this).start(); statement. You now have two threads running which can continue to execute (or wait, or whatever) independently.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Sorry man, I've given you the best advice I can, twice, but you don't want to follow it, so good luck, I'm outta here.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

It's a static method for the Char class - ie
Char.isLowerCase(characters0;
I still say you should do all the replacing in the char array, then convert back to String when it's all finished. The String replace you are doing is at best redundant, and at worst will replace all occurrences of LetterFind when you just wanted one replaced.
ps unless LetterFind is a class it should start with a lower-case letter ie letterFind.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

The selection happens in the JTable, not in the underlying model, so you need to look at JTable methods like getSelectedRow() etc.