JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Is your method being called when you resize the component? Just setting the preferred size doesn't necessarily mean that the component will be resized. Depending on what layout manager you are using you may need to set the minimum, maximum and preferred sizes to get the result you want.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

it's not a good idea to do some bussiness logic by using
try/catch block.as they are not made for it and if you are required to do it.then you should recheck your design.

I've often seen this stated, but I'd be grateful if anyone could point to an authoritative source for it.

The Java API can easily put you in that situation, for example if you are using the Scanner class to parse user input then nextInt() throws InputMismatchException if the user has mis-typed. This, by design, seems to violate the "don't do business logic by Exceptions" paradigm, but it's in the API, so it should be OK.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You can use an anonymous inner class. Something like:

new Thread(){
  public void run() {
     // some lines of code
   }
}.start();
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

is it possible to use try catch exception inside while loop?

Yes.

You often see this in cases where you want to re-try something that may fail (throw an Exception).

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

For any node the possible paths consist of the possible paths for all its children, but with the current node inserted at the front of each path. In pseudo-code it kinda looks like this:

public CollectionOfPaths getPaths() {
   CollectionOfPaths cp = new empty collection of paths
   // (where a "path" is an ordered list of nodes)
   if there are no child nodes {
      return a new path consisting of just this node
   }
   for each child node {
      CollectionOfPaths ccp = child.getPaths()
      for each path in ccp {
         add this node to start of the path
         add the path to cp
      }
   }
   return cp
}

So call this on the top node and it will recurse all the way down to every leaf and return all the paths.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You need a recursive solution

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Thanks!

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Stephen: just a quick aside - how did you get the java tags into your message without them being interpreted as java tags?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Open the file into a FileInputStream, read (say) 1024 bytes at a time, send them over the Socket connection. At the other end read the incoming bytes from the socket and write them toa FileOutputStream. Wrap the whole process in a simple protocol for requesting a file and hey presto!

bharatshivram commented: thanx.. +3
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

It's easy. Just Google for it.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

throws appears as part of the declaration of a method. It tells you that when you call that method the named Exception may be thrown by that method, and that you need to handle it in some way.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

If Pr.class is inside of C:\mylib, the classpath should be c:\ As you have it now, its looking for mylib.classwhatever inside C:\mylib - ie 1 too many mylibs.

freelancelote commented: Just what I needed. Thanks +1
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Short version: If you refer to a class in a package, the JRE will search all the directories in the current classpath for a folder or jar with the same name as the package, then search in there for the class. So your classpath must reference the folder/directory that immediately contains your "mylib" folder.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Two things: 1. Use while() rather if() because a wait() may be interrupted by other things than the notify() you intended.
2. You have two blocks of code that update the two positions, and i and the array - I would be tempted to put that code (and that code only!) in a synchronized(coll) block to be certain on no partial updates.
(personally, I would use a Vector to hold the things, add to the end, take from the start. no need for any other variables. Vector is synchronized, so no synchronization needed either).

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Treehole needs to be enhanced with Collection of some sort to hold the ints that the Squirrels put in. Squirrels add to the Collection, Magpies remove from it. The wait condition for get() needs to test that the Collection is not empty. The wait condition for put(...) needs to test that there is room in the hole (ie that the Collection has not exceeded some arbitrary maximum size).

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Hi adatapost; I'm sorry, but I don't agree this time!
This particular pattern is one where the get and put methods perform all the necessary synchronisation, in a way that can be scaled to longer sequences of operations that need to be serialised. Object locks can achieve the same result in terms of blocking concurrent access, but cannot provide the sequence control that's needed here. In this case they are neither needed nor helpful.
Although volatile is generally useful in code like this, boolean assignments are atomic in Java. Also, in this pattern the boolean assignments are within the scope of the code managed by the wait conditions, so there is no possibility of concurrent modification. Either way, it's not needed in this particular case.
J.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Your code looks 100% OK to me. If the magpie gets the right int "before the squirrel has put it", then this implies that things are working OK - otherwize the magpie would just get the previous int twice. Maybe when the magpie gets the int it should reset seq to 0, just to be sure what's happening.
Does anyone know if System.out.println is guaranteed to write lines in the correct order when called from multiple threads?

ps
available == false is redundant for !available
and
available == true is redundant for available

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Is the focus needed in your app, or some other Windows application. If it's yours you can request focus thru the Swing API. If its some other Windows app this is not easy; you could use JNI to access the Windows api directly (difficult) or use PrecessBuilder to call something like cmdow ( http://www.commandline.co.uk/cmdow/index.html ) to set the focus for you (not so difficult, but not elegant either).

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Maybe you can use the java.awt.Robot class. This was intended for automating tests of a GUI, and allows you to post mouse and keyboard events directly onto the host operating system's event queue.
http://java.sun.com/j2se/1.6.0/docs/api/java/awt/Robot.html

Majestics commented: Great Help +2
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You need to share with us the class and line number where the error is thrown

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

the reason why i used
is there a way to limit Arrays.toString() to only look through the actual size of the array?

Not that I know - if there are nulls in your array it will fail.
Maybe you would be better off with an ArrayList or Vector rather than a dumb old array, that way Java keeps track of the size for you. If you are committed to arrays, then something like this should work

String subjects = "";
for (String subject : subjectsTaught) {
   if (subject != null) subjects += subject;
}
return subjects;

ps

subjectsTaught is my array declared at the begining

declared, OK, but is it initialised? If not, you need something like the previous poster's suggestion as well, although personally I would prefer

private String [] subjectsTaught=new String[10];
private int subjectsCount = 0;
.....

public void setSubTaught(String value) {
if(subjectsCount <=9)
subjectsTaught[++subjectsCount ]=value;
}

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

In getSubTaught() you loop thru all the members of the array, regardless of how many have actually been populated. You only set element [0], so when the loop hits element [1] you get a null pointer.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Your TutorGroup class has a SortedMap that appears to contain student names as keys and Student objects as values. You can use this map to look up the Student object for any given name.
The map is private, so you can't just access it from anywhere else (quite rightly!), so you could add a new public method to TutorGroup to do the lookup public Student getStudent(String name) {...}

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Your Customer constructor requires a Name and an Address, but you have just provided the raw information (last ... zip).
You have to create a Name and Address from the raw data and pass that to Customer

Name n = new Name(last, first);
Address a = new Address(street, city, state, z);
Customer customer = new Customer(n, a, acctNum);
// or just
Customer customer = new Customer( new Name(last, first), new Address(street, city, state, z), acctNum);
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Since nobody else has the answer I had a quick Google, and found this: " How do I use JSAPI in an applet?
It is possible to use JSAPI in an applet. In order to do this, users will need the Java Plug-in (see http://java.sun.com/products/plugin). The reason for this is that JSAPI implementations require access to the AWT EventQueue, and the built-in JDK support in the browsers we've worked with denies any applet access to the AWT EventQueue. The Java Plug-in doesn't have this restriction, and users can configure the Java Plug-in to grant or deny applet access to the AWT Queue. "
(Source: http://java.sun.com/products/java-media/speech/forDevelopers/jsapifaq.html#applet-use ).
If you've already one that, please accept my apologies.

although Java seems like a great language I just find it hard to find the right functions/code to use

Too f'ing right! I reckon a few months to learn 90% of the language, 10 years to learn 50% of the API (if you're lucky).

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

My pleasure. J

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Two is not static, so it needs an instance of One to be created in. ie One.Two p=new One() . new Two(); Alternatively, declare Two as static

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

^^^^^^

I understand your impatience, but I have a life to live here. People are arriving for dinner in 15 mins (it's 18:45 here) and I have to go now. I'll check this thread again tomorrow

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

1. You got this bit right! ByteArrayInputStream is a subclass of InputStream, ie it's a "kind" of InputStream. You have created an instance of ByteArrayInputStream, and that is a suitable object to set is to.
2. Personally I'd forget the bufferedreader bit, just read directly from is. You can worry about optimising it later.
3. Yes, you got that right as well. In your code you read(), but you assign the result to b, which is a byte array, not an integer as required by the API. Your code also tests for end-of-file by looking for a null value, when it should look for -1.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

InputStream, as the Java API doc makes very clear, is an abstract class; it's definition is incomplete and you cannot instantiate it with new. It's purpose in life is to define a standard set of operations that any byte-oriented input stream should implement. As also explained in the API doc, it has a number of subclasses that you can instantiate, including one that is based on a byte[] array. So, you can declare is as an InputStream reference variable, but you have to instantiate one of its subclasses to get a real input stream to use as its value.
Finally, it's the input stream you need to close, not your integer.
oh, and ps, read the API doc for InputStream.read() to find out what it returns (hint: it's not a byte array) and what it does when it reaches end-of-file (hint: it doesn't return null).

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Hi. I'm suggesting the array/loop approach because if you have 10 of anything without them being in an array, you will end up with 10 almost identical blocks of code for everything you do.
You can just set them up in the array from scratch, then refer to them by array rather than field1, field2 etc

JTextField[] arrayOfFields = new JTextField[10];
for (int i = 0; i < 10; i++) { 
   arrayOfFields[i] = new JTextField("");
   form.add(arrayOfFields[i]);
   arrayOfFields[i]. // etc etc
}
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Since you need to set visible true or false for every field, maybe now is a good time to re-visit the array of fields solution

for (int i = 0; i < 10; i++) {
   arrayOfFields[i].setVisible(i<= ComboBox1.getSelectedIndex());
}
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

If your code is an ActionL:istener, you're probably listening for the wrong event to see if the selection has changed. You probably need an ItemListener.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Look OK to me, but like I said, you don't close the output file, so maybe your 3 lines are still sitting in a buffer somewhere waiting to be written to disk. Try an output.close(); immediately after the 3 primts

As for the accessibility of the variable, I was trying to be polite, rather than directly contradict the previous poster, but yes, the default scope is the whole package, so the two classes would be in the same scope unless declared otherwize, and there's no need to declare anything public.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Have you got an actionlistener added to the menus?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Doesn't readData have default (package) scope, and is therefore accessible from the main class? If it wasn't, you would get a compile error.
Maybe the output file needs to be closed before the contents are read?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Oh yeah. JOptionPane has a whole library of of useful standard dialog boxes just waiting to go.
That's why we're all here on Daniweb - maybe to help, but also to learn. I guess when there's nothing left to learn you may as well shoot yourself.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Or, even better for the user: JOptionPane.showConfirmDialog, which gives yes/no buttons with no risk of user error in the first place. (sorry BJSJC - parallel posted with your reply)

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

is this what you want to achieve?

String change1 = "";
while (!change1.equalsIgnoreCase("y") && !change1.equalsIgnoreCase("n")
   change1 = JOptionPane.showInputDialog("Change Silo 1 dimensions? (y/n)");
}
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

No problem. ps: got my method names a little confused - what I meant was put the increment/decrement in enterTrack & exitTrack, then call those from the appropriate places in useTrack. They're obviously there for a reason...

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

I'd go for a simple solution - create int variables in the Thread class to hold the number of threads currently using the track in each direction. Increment the appropriate variable in useTrack and decrement it in exitTrack. Now you have the info necessary to perform the tests specified in your question.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

1. Just use the selected rows, and ignore the selected columns and print all the columns regardless of which were selected.
2. To get the sorting in numeric order probably best way is to store the data as numbers in the first place - but that's going to mean quite a few code changes, maybe not worth the bother? Maybe someone with more experience of JTables can point you to a way of using a custom sort ode?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Hi, I'm back! AFIK the rule is that the numbers are padded with leading blanks to a fixed total width, so they all line up in columns, right-aligned.
1. The rule, therefore the code, is the same for all columns except the first - there's no need to replicate all those code fragments.
2. Suppose the desired width is 5 chars. You stick 5 chars on the front OK, but the you need to substring the last 5 chars. So substring(1) isn't going to work. The substring need to start 5 chars before the end of the string. You're going to need the length() method (as I said before). Try writing down a couple of examples on a piece of paper and see if you can work out the correct sunstring expression before trying to code it.
(Hi, BJSJC!)

BestJewSinceJC commented: Hi to you too! And you gave a lot of good info in this thread :) +5
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

I notice that the extra columns are padded at the front, not at the end like the name was. So you'll need a slightly different version of the padding code where you add the blanks at the beginning of the string, then substring the last "n" characters. You should be able to do that with a little thought. You'll need the length() of the string to work out where the last "n" characters start.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

If the original is aligned to fixed columns, then yes, you can pad them all to the same length just like you did for the name. If the originals have random spacing and you want to keep the original number of blanks, you'll have to store the original lines in a separate ArrayList<String>, and retrieve them from there by row number.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Have a look at this, it may help you (!)
String name = "James";
String paddedString = name + " ";
String fixedLength = paddedString.substring(0,19);

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

I'm not going to give you the code (against the rules!), but here's the plan:
You want to treat the first column differently from the rest, so in your "i" loop first do col 0 with its own special code, then start the column loop from col 1.
You want to pad out the name (column 0) to a fixed length (say 20) by adding blanks, so get the name, add a string of 19 blanks on the end, then use the substring method to get the first 20 chars from that.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Nearly there. You have the loop with i and j ( = row & column numbers). Remember the datamodel? You already have a method there that returns the data for any specified row & column. You can use the same 1 line expression if you just change the variable names a bit.
ps Open the printwriter before you go into the loops, and close it after you've come out. Otherwize you open/close it for every single value.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Start with something like:

public void actionPerformed (ActionEvent event){
  int[] selectedRows= table.getSelectedRows()
  for (int i : selectedRows) System.out.println(i);
}