JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Since print can be called any number of times for any page you can't just do the increment in the print method. I would decide the page numbers when creating the pages, as per my previous post.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

The API doc for Printable includes this:

For correct printing behaviour, the following points should be observed:
The printing system may request a page index more than once...
... the Printable should expect multiple calls for a page index and that page indexes may be skipped, when page ranges are specified by the client, or by a user through a print dialog.

So the fact that it's called twice may be just how it works.

This all means that the approach of incrementing the page number when print is called is definitely wrong.
You could possibly pass the page number to the constructor of IntroPage and keep that as an attribute of the page, so the page number is created when the page is created and then doesn't change.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

@sirlink99:
I think the check logic was OK as it was (loop while !check, set check to true when good data has been received to exit loop). Your break on line 15 will ensure the loop is only executed once, regardless of data correct/incorrect.
However, I think you HAVE got a good point about re-initialising check. After it's set true for the first player it never gets set back to false, so subsequent players never execute the while loop. It should be initialsied INSIDE the players loop, ie swap lines 45/46 in the original code

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

If your indentation is right the continue on line 59 is the last statement in the while loop 47-60. If that's the case then it has no effect. What did you expect it to do?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

^ like Stultuske says.
As I understand your assignment (ie not very well!) the array of Student objects belongs in the Enrollment.

Programming languages are very precise things; you can't mis-use terminology or expect the compiler to "understand what I really meant". The same applies when you talk about programming in these posts, which is why S. rightly picked you up on your sending an array of students to the student constructor. Be very careful that what you write is exactly what you mean.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

OK, that's not quite how I would do an enrolment system, but hey-ho.
I think point 4 should really say
4
printEnrolment()
It calls the printDetails() method for each Studentto return and print the details on the command prompt.

Anyway, I think you have enough to keep going with for a while now...

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster
Student.printDetails();

printDetails is an instance method that prints the details of a single Student. It only makes sense when you call it for a single Student. You are trying to call it using the class Student, so Java doesn't know which Student you want to print the details of.

I somehow need to create an instance of the printDetails() method s

No. you can't create an instance of a method, you can only create an instance of a class. In this case printDetails is an instance method so you MUST have an instance of a Student object on which to call it. Your Enrolment class currently has 6 Students - so which one did you want to print?

ps: The Enrolment class needs some more work anyway - it has no variables! The Student array you create in addStudent is just local to that method and will disappear when the method finishes. And why does a method called addStudent add six Students? How many Students does one Enrolment involve? You need to go back to the specifications, and re-think this class.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You will create 1000 objects, but the only references to them are in the 1000 local variables myObject. Those variables each go out of scope as soon as the method finishes, leaving the object having no references. That makes it eligible for garbage collection, and the garbage collector will destroy the object and free up its memory at a time of its own choosing. If you are short of memory that may be very soon. If you have lots of memory and your code continues to process heavily, then the garbage collection may be deferred for some time, but sooner or later they will all be destroyed.
The question of whether to use a static reference to your object(s) is answered by the functional requirement, not performance. (Objects themselves are not static or instance, they just exist.) Static and instance variables behave differently, and only one will be right for any given task.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Bit of a puzzle this one.
We don't have enough info; the important code hasn't been posted, but it looks like the OP's code does actually throw that exception (?). If that's the case it will be immediately preceded by some kind of if test that checks for the condition that causes the exception OR it will be the body of a method (a constructor in this case) that has not been written yet. Either way, someone has to look at that code.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

So, given a category you want to take each of the words in that category and see if they appear in a given text?

If so, NormR1's idea is a good way to go.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

The exception message includes the exact line where it was thrown, ie
Home1.<init>(Home1.java:32)
what is the code at that line?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster
if(word[x].equals(null))

This code is broken. if word[x] is null then word[x].equals(anything) will throw a null pointer exception. Either the code isn't being executed, or array is initialised to something other than nulls, or you are ignoring the exception.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

I doubt that anyone will try to understand those hundreds of lines of incorrectly indented uncommented code, so you'll have to debug this yourself. Just use lots of print statements to confirm the values of all the variables in and around where things are going wrong. And don't forget to catch and printStackTrace every exception.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

It's no good trying to draw things to the Graphics like that - Swing is in charge of drawing and will ignore/over-paint your drawing.
The correct way is to override the paintComponent(Graphics g) method to include your own drawing code. Swing will call this whenever it is necessary - eg because the window has been resized, or you have requested it by calling repaint();
Look at the second (Swing) part of this:
http://java.sun.com/products/jfc/tsc/articles/painting/

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Is this connected with the META-INF in every executable jar file?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Why not use writeObject/readObject via an ObjectOutputSream/ObjectInputStream to send/receive your image in a single call?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

We're going round in circles here, just like you did with Norm. I can't help you if you don't respond to my questions or say anything I can understand. Sorry. Good luck anyway.
J

Majestics commented: thanx +3
mKorbel commented: good +8
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Check this

Yes, of course. So what? Why would you enable the OK button when the user selection is incomplete? How does this relate to the previous questions?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

I'm really sorry. Maybe this is just a language thing. I honestly do not understand what you are saying.
In your example col B should allow the user to pick office or sqlserver or windows; right? How is that possible if you only populate row 1?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

I really want to help here. It's just that I still don't understand exactly how the user interaction is supposed to go, so I can't suggest any coding techniques.

It sounds like a pretty standard thing you are trying to do here, and the usual solution goes like this:
Initially A shows "Apple/Oracle/MS..."; B and C are blank
User selects MS, B is populated with list of MS products; C is still blank.
User selects "Office" from B, C is populated with "Word/Excel/..."
... uses selects from C, selection process is complete OR
... user selects another product from B, C is re-populated appropriately OR
... user selects another manufacturer, B is re-populated appropriately; C is cleared

Instead of clearing/populating entries you can instead have them all present but disable/enable them.

But none of your descriptions seem to match this standard model - how exactly does your desired solution differ from that?

NormR1 commented: Glad you've grabbed this one. +12
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

If i select a value in column a at that time i will record it row number , when i will select value from column b i will match the row number if row number matches then values are listed else an empty column b

how does the user select a row from column b if the values are only listed (or empty column) after the user ]makes the selection? What do you mean by "row number matches"?

it isnt friendly gui practice in which user can mess up the whole database

There's nothing user-friendly about a program that can mess up an entire database, that's just poor programming.
What you are saying is that if the user accidently selects "Apple" instead of "MS" he has to go on and select an Apple product in col b, the an Apple sub-product in col C before he can go back and correct his selection in col a. Well, OK, it's your program.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Sorry, I don't understand the exact process either in that case. It certainly doesn't make sense in the light of the Apple/MS example you gave earlier, not does it sound like friendly GUI practice.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

This sounds to me like you want to disable all the cells in cols B and C until the user selects a cell in col A. At that point you want to enable just those cells in col B that are valid for the chosen value in Col A (ditto for B -> C).
Here's a link to how to use a custom cell renderer to achieve the disabling/enabling
http://www.coderanch.com/t/337047/GUI/java/JComboBox-Disabled-Items
(I assume you can work out your own logic for deciding which cells should be enabled)

Depending on the lengths of the lists it may be better GUI practice to hide/remove all invalid choices from cols B and C rather than having long drop-downs with mostly unavailable choices. This simply requires you to re-populate each list when the user makes a choice from the previous list.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Hi BJSJC
The square root answer is the correct one. If "half the possible prime" is a factor, then so will 2 be - which has already been checked. Ditto 1/3 the possible prime, which is only a factor is 3 is (ditto). Once you go bigger than the square root then the other factor must be less than the square root, all of which values have been checked.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

@IIM
Please be aware that we do not do people's homework for them. By supplying the OP with a "corrected and optimised" solution you are simply inviting him to copy/paste the whole thing and learn nothing (except maybe that cheating is easier than learning).
On the other hand, this is a pretty poor example of a Java program*, so maybe the OP will be smart enough not to embarrass himself by submitting it and getting a low grade.

* using an undocumented int (f) for a boolean value, no error checking, redundant else clause, zero comments, random indentation

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Please don't misunderstand - I was just trying to help, not criticising, and certainly not expecting an apology!
You will see a number of us repeatedly posting advice to use more print statements for debugging because so many beginners don't use this technique enough, and thus have great difficulty debugging. I'm not just picking on you here!
As for the nextLine() - I suggest that you define a standard behaviour for all your code that uses the scanner, eg "all methods that use the scanner will leave it at the start of the next line". Thus methods that end with a nextLine() are OK, but methods that end with a nextInt() or whatever are responsible for adding an extra nextLine() in order to leave the scanner in the standard state. That way it's clear who has to do what.

ps: we parallel posted there! Yes, instead of the way I suggested above you can alternatively have a standard of not using nextLine() and consistently ignoring carriage-returns. The imnportant thing is to have a standard and stick to it.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Probably this:
nextInt() takes the "2" from the console input, leaving the following carriage-return in the input buffer. So next time round your nextLine(); takes everything up to the CR - ie nothing. After taking an int or whatever you need to use an extra nextLine(), or some other call, to clear the rest of that line from the input buffer.
If you had use print statements like I suggested you would have seen this for yourself.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

I can't see the problem after a quick look. Put lots of print statements into your code so you can see the exact sequence of execution and variable updates that lead to the problem.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

public static void sortNumbers( int oddNumbers[], int evenNumbers[] )
sortNumbers( randomNumbers );

So here we have a method declaration that requires two int arrays as parameters
And we have a method call that passes only one int array as parameter.
That's not legal Java.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You may still be creating problems by trying to read binary data as if it is character. That will read 1 byte per character from the input stream, but convert to Unicode 2-byte chars to store in a char array, with results that may be unexpected for random binary input.
To read a binary file you can read it verbatim from the input stream (not a Reader) in nice chunks with
read(byte[] b) - Reads some number of bytes from the input stream and stores them into the buffer array b. The number of bytes actually read is returned as an integer.

By way of illustration, here a little bit of code that does the opposite of your case - ie copies an arbitrary binary file from a local file to a remote client - but it illustrates the ideas well

public void send(InputStream file, String mimeType, Socket clientSocket) {
		// send a file that has an input stream already opened
		try {
			// Acquire an output stream
			DataOutputStream outbound = new DataOutputStream(clientSocket
					.getOutputStream());
			// Send the response header and content
			outbound.writeBytes("HTTP/1.0 200 OK\r\n");
			outbound.writeBytes("Content-type: " + mimeType + "\r\n");
			outbound.writeBytes("Content-Length: " + file.available() + "\r\n");
			outbound.writeBytes("\r\n");

			byte[] data = new byte[4096];
			int count;
			while ((count = file.read(data)) != -1) {
				outbound.write(data, 0, count);
			}
			file.close();
			outbound.close();
		} catch (IOException ex) {
			System.out.println(ex);
		}
	}
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Is the correct answer 142917828921?
If so, you may want to compare this with the largest value an int (eg int Total=0; ) can hold...

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

It does start from 99, it's just that your output window is of limited size and has dropped the earliest part of your output.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

That kinda works, text is a bit untidy, but that's all. What EXACTLY is the problem you are trying to fix?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

I don't know your experience level, but many people would advise staying with a simple text editor to build real Java skills before getting dependent on the assistance of a full IDE. Personally I'm not convinced, but hey, each man his own opinion.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

I don't know either, but the line number in the message does not correspond to the line numbers in the code you posted. Nevermind.
Read Ezzaral's post again, he is wize. My guess is that the error message actually refers to line 59 in the code as posted.
Watch var while running.. if you are using a Java IDE like Eclipse or NEtBeans that var monitoring and breakpoints are all there for you to use (although its a bit of a learning curve). Otherwize simply add some print statements to see what's happening,, eg

System.out.println("SalesField text = " + salesField.getText());
double order = Double.parseDouble(salesField.getText()); 
System.out.println("order value = " + order);
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

at CandleLineApplet.itemStateChanged(CandleLineApplet.java:67)

Line 67 is part of public double getOrderAmount() in your code, so the code you posted doesn't match the error message. This is not helpful!

Null pointer means uninitialised variable OR a method returned null and you tried to use the returned value. Check the actual line in the code version corresponding to the error message to see which it is.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Have you seen these?
http://download.oracle.com/javase/tutorial/deployment/applet/security.html
http://download.oracle.com/javase/tutorial/deployment/applet/deployingApplet.html

JNLP lets you get around many of the unsigned jar problems by automatically seeking permission from the user

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Stultuske has explained this to you twice. I'll give it one more try.

line 7 A b=new A(); // creates a new instance of A
line 2 A a=new A(); // instance variable a is initialised as part of creating the new instance
line 2 A a=new A(); // new A() is executed to initialise variable a. It creates a new intance of A
line 2 A a=new A(); // instance variable a is initialised as part of creating the new instance
line 2 A a=new A(); // new A() is executed to initialise variable a It creates a new intance of A
line 2 A a=new A(); // instance variable a is initialised as part of creating the new instance
line 2 A a=new A(); // new A() is executed to initialise variable a It creates a new intance of A
etc etc until the JVM runs out of memory

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

The code+messages you posted earlier point definitively to multiple versions of your files, regardless of what you may believe.
Java requires that public classes are defined in a .java file with the same name as the class, but there is no such requirement for non-public classes as in your code. (It's not required for your main method to be in a public class, but it is normal practice.) However, the compiled .class files always have the same name as the (single) class they contain.
By naming your .java file differently from the class in it you are creating an opportunity for confusion, ie you compile chartest.java but you get myClass.class as output, this making it hard to match source and compiled files.
It would be a good idea
(1) to make the source code file name match the class name
(2) delete all the other .java files
(3) delete every .class file
(4) compile & run again.

Asking someone else to read the JavaDoc for you is a really bad idea (plus nobody's going to do that anyway). Searching the API doc is a fundamental essential skill for Java developers. Go to the JavaDoc for the Scanner class. You will find
A description of the class with examples
A list of all the constructors for the class
A list of all the methods for the class
A list of all the other methods that this class inherits.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

A class with exactly one instance is called a "singleton" class. It is a common pattern in Java applications. Here's a typical implementation:
http://www.javabeginner.com/learn-java/java-singleton-design-pattern

I don't understand what you mean by "user stops the function of this package and when he starts it again then the initialization of A,B and C and all fields inside it happens again". Is there another way you can explain that? Maybe you can post your static methods that return the singletons (one will do, presumambly they are all the same).

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Hi hhfx642, We have an awful lot of absolute beginners here, and leaving catch clauses blank is one of the mistakes they often make (with obvious consequences). I wasn't having a go at you, I was just worried about newbies taking that template as a starting point without realising the importance of diagnosing exceptions. :-)
J

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Absolutely do NOT start with any code that has

catch (IOException IOE)
{ }

If it doesn't work because of an Exception you'll never be able to debug it.
At the very least replace all those with

catch (IOException e) { 
  e.printStackTrace(); 
}
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Eclipse has its own environment, and you can't get at the ordinary console.
You can get the same capabilities using a BufferedReader with System.in

import java.io.BufferedReader;
  import java.io.IOException;
  import java.io.InputStreamReader;

...

          try {
             BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
             System.out.print("Type name: ");
             String name = reader.readLine();
             System.out.println("Hello " + name);
          } catch (IOException e) {
             e.printStackTrace();
          }
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

What about status like: available()

For BufferedReader that would be the ready() call he used incorrectly before - it tells you if there are bytes sitting in a buffer waiting for you to read, but not if the source has finished sending any down the stream.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

That's just an ordinary HTTP GET for the (site default) index.html file. No hint of anything being uploaded. It's waiting for you to send it index.html.
I think this is the wrong test case, or at least the wrong part of it.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Hey guys - sorry to butt in, but I really think I know what's wrong here. The read loop is terminating when the input buffer contains less than 1 line, guaranteed to before EOF if the file is > 1 TCP/IP block. Terminate the read loop only when readLine returns null or throws an Exception.
If I'm wrong please say so.
J

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

ready()

Returns: True if the next read() is guaranteed not to block for input, false otherwise. Note that returning false does not guarantee that the next read will block.

As far as I can see that means that it will return false when you have read zero or more lines but the next line is not yet in the buffer - which is quite likely over a web link. So you will exit your read loop as soon as you catch up with the input, not when the input is complete. You need a better way to detect when the whole file has been read - I don't know what to suggest, other than some trial and error.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

A. is a static context. Whatever follows that has to be static. It's not about then enclosing method, it's just the way you use the class name rather than an instance in that statement.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

A.method() is a static reference - A is a class not an instance. method() is an instance method - hence the error.
Contrast that with the following valid code

class B{
  void myMethod(){
    A a = new A();
    a.method();
  }
}
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Doesn't a standard NAT router map each LAN IP/port to a different arbitrary port on the WAN IP - so each unique LAN client will appear as a different port number on the external IP? I'm no expert on this, so I'd be grateful for a correction if I have this wrong. Thanks.