BestJewSinceJC 700 Posting Maven

So let me see if I understand. You have five "areas", each of which you want to be connected to the other areas, and you want to be able to adjust the size of each of them?

Sun tutorial on JSplitPane, some paragraphs in:

"You can divide screen space among three or more components by putting split panes inside of split panes, as described in Nesting Split Panes"

BestJewSinceJC 700 Posting Maven

Whoops. Good point. I'd give you more rep for that but apparently I can't since I gave you rep today.

BestJewSinceJC 700 Posting Maven

The problem is that timeRepaintIn - Calendar.getInstance().getTimeInMillis() is a negative value. Which means that Calendar.getInstance().getTimeInMillis() is greater than timeRepaintIn. So you might want to rethink your logic on deciding how long to sleep for.

BestJewSinceJC 700 Posting Maven

Yep, no problem. Somebody else on this forum told me that solution a while back as well. Also, mark this thread as solved

BestJewSinceJC 700 Posting Maven

At the start of the paint method, call super.paintComponent. This should have the effect of clearing the screen. If it doesn't, draw a new rectangle on the screen that is the color you want (white or gray probably) that fills the whole screen.

BestJewSinceJC 700 Posting Maven

What the poster above posted might look confusing, but what he is saying is a good way of doing this: Each String in the array will be the "name" of the index it is at. So index 0 of the array is named zero, and so on. This means in order to find the name of "20", you would use array[20] and it would return "twenty" since that is what you stored there.

The implementation is a little different - for example in C, I think an array of Strings is actually a 2D array of chars, but you get the point, I hope.

BestJewSinceJC 700 Posting Maven

http://www.daniweb.com/forums/thread199998.html

Look at post number 3 in that thread. If you create a Pattern based on the word the user enters, you can loop through your input, counting the number of times you encounter that Pattern.

BestJewSinceJC 700 Posting Maven

No, it is not a "reserved method". He means for you to create the method, so that after your Object is created, you can use that method to pass it to the other class. A small example:

public class ExampleClass{
     String myString;
     public void setString(String otherString){
          myString = otherString;
     }
}
BestJewSinceJC 700 Posting Maven

Also, consider the fact that you can jump to the next word by reading in the next chars after each word until you find the space. You know the next word is after that space.

BestJewSinceJC 700 Posting Maven

I don't know what line 12 is because you didn't use the code tags correctly. If you had, it would have put line numbers there. Anyway:

Check out the String class's toCharArray() method. Once you get your char array, iterate backwards over it, printing out each character. If you want to store the backwards String, then do the same, except put each character in a second array, or continuously add it to a String like this: String whatever = whatever + theChar;

BestJewSinceJC 700 Posting Maven

Probably because your data is stored on servers, possibly multiple different servers, and you need some way of accessing it.

BestJewSinceJC 700 Posting Maven

Try opening it with this constructor:

public FileInputStream(File file);

First, create the File Object. See if creating the File object also throws an Exception; if so, print the Exception's contents and getMessage() message in here. Also use the File class's file.canRead() method and tell me if it returns true or false. These are just some thoughts - there's no harm in using a different class to try to find out information about the problem, although this may not yield any answers.

BestJewSinceJC 700 Posting Maven

Which is exactly what Masijade seems to be addressing, except he did not go into much detail. At the very least, you'd need your PDF data in a separate class, and a simple "controller" that provided access to the data.

BestJewSinceJC 700 Posting Maven

You can use regular expressions. I'm not good with them since I hardly use them, but they aren't that bad, just a set of rules to specify which characters to match basically. Look up regex or regular expressions java on google.

BestJewSinceJC 700 Posting Maven

edit lol I realized I was wrong.

BestJewSinceJC 700 Posting Maven

You can draw the Rectangle from within paintComponent just by using g.drawRect or g.draw3DRect or whatever the methods are. You are over complicating things by using the coordinates and whatnot.

BestJewSinceJC 700 Posting Maven

The + operator only works with certain types. If you aren't using it with those types, then it isn't going to work. If you want more detailed reasoning on this, masijade is probably your man. But you should try using the floatValue method of the Number class, then adding the floats you get. But for example, Number could be a BigDecimal, BigInteger, etc (look at the doc) - which can't be added as simply as an int.

BestJewSinceJC 700 Posting Maven

i looked up the api ....and there is no method that let's u output the element of a stack ....and for the Queue where can i find a ready class for it ....thnx for help

Oh, there isn't? Because by typing in "Stack java" to google I found this link. Hm

BestJewSinceJC 700 Posting Maven

And to clarify the '&' issue, if it wasn't already, the scanf function needs to know what the address of something is, and the '&' is the address of operator. Since the pointer already contains the address, it doesn't make sense to use '&' in that case.

BestJewSinceJC 700 Posting Maven

You could use the Java class Timer. Or you could do something inane like

int i = 0;
while(i < whatever) i++;

And this while loop would take a certain amount of time to complete, so there would be your pause.

BestJewSinceJC 700 Posting Maven

You have to create a new Object of type Random before you can use it to generate the random numbers. If you go to the link Vernon gave you, you will notice that the class is called Random. So to use a method of this class, you need to create a new Object of this class using the 'new' operator, then you need to use whateverYouCalledThatObject.nextInt(100).... In Vernon's example, he called his Object 'random', hence his code says random.nextInt(100)...

BestJewSinceJC 700 Posting Maven

Probably, do a google search for them. If you're talking about simple differentiation and integration (i.e. power rule) then it is trivial anyway, and so is chain rule for differentiation. Why don't you mention the specific formula you're trying to code and then show some progress or ideas etc on it.

BestJewSinceJC 700 Posting Maven

it was only the comment i'd not changed, it should return an int as the map is set up to have.....thanks for spotting that though! the file contains int,string,int so i shouldn't be using a double anyway.

so how do i put the values into the map knowing they are of the correct type?

As long as you change the variable that I mentioned previously to type "int", the line that you thought wasn't working should work. So declare "pitchTarget" as int, not as double, then tell me if you're getting an error.

BestJewSinceJC 700 Posting Maven

pitchTarget = lineScanner.nextInt(); // return the next token as a double
targetMap.put(taskNumber, pitchTarget); //this is the line that doesn't work

Your first line I posted doesn't make sense. The nextInt() method does not return a double, it returns an int. And your treeMap is declared as taking a K, V pair of Integer, Integer. So you won't be able to use TreeMap.put(integer, double)...

BestJewSinceJC 700 Posting Maven

You're creating a new Student Object, when what you want to be doing is getting the data from an existing Student Object. What exactly is students.keySet()? I don't know what "students" is, nor do I know what the keySet method does, so I can't help you until you post the relevant code.

BestJewSinceJC 700 Posting Maven
for (String name: this.students.keySet())      // line 1
  {
    System.out.println("Student " + name + ":"); // line 2
    //this line should call the displayMarks() method from the class student, but whatever i try doesnt work
    System.out.println();
  }

In order to call a method of the class Student, you must use an Object of type Student. You are iterating through a Collection of Strings ("name" is a String) so you can't use it to call the Student class. Change your for loop to iterate over Students...

BestJewSinceJC 700 Posting Maven

Yeah, it seems like your add method is trying to add a Node in sorted order... instead of just adding it at the end of the list.

BestJewSinceJC 700 Posting Maven

IntNode cur = head;
IntNode prev = cur;

Doesn't make any sense. You're essentially assigning cur = head, then prev = head. Do you mean to say:

IntNode prev = cur;
IntNode cur = head;


?????

BestJewSinceJC 700 Posting Maven

by clicking the "mark as solved" blue link thats at the bottom of the last post

BestJewSinceJC 700 Posting Maven

Yeah, no problem. Mark the thread as solved

BestJewSinceJC 700 Posting Maven

I edited my post, re-read it. There is no way your file is just named "name". It would be named "name.txt" at the very least. And if it was not in the same directory as your .java file, you would need to specify the directory such as "C:/name.txt" or wherever it is.

BestJewSinceJC 700 Posting Maven

You probably aren't creating the FileReader Object correctly, due to having an incorrect pathname for the file. For example, if your file's name was name.txt, but it was located on the Desktop, you would have to use "C:/Users/yourUsername/Desktop/name.txt" where you have "name".

BestJewSinceJC 700 Posting Maven

You should also create another thread and explain your problem in there.

Mark this thread as solved, go start a new thread, and post the specific problem you are having in there. You should at least be able to identify a portion of code that isn't working. At this point, when the thread is 3 pages long, the people who have been helping you probably don't remember everything about what problems you were having, the people who have been helping you probably don't know which problems you successfully solved and which remain unsolved, and the people who weren't helping you don't want to read 3 pages in order to figure out what is going on in here. I explain all of this only because you ignored my advice last time.

BestJewSinceJC 700 Posting Maven

http://java.sun.com/javase/6/docs/api/java/io/File.html#length(

That is the documentation for the File class. You are trying to use the length() method with an Object of the class FileReader, when in fact, the length() method is a method of the class File. Go back and re-read my original post to you. You're obviously pretty confused, so I'll give you some code examples to help. Typically we aren't supposed to give away code on daniweb, but considering the simplicity of this, I'm going to assume you gave it effort and are just confused by my explanation. I can't really explain it any differently, so maybe seeing the examples along with the explanation will clarify things:


This is how you do it with a FileReader. Remember, with a FileReader, you are reading through everything in the file, character by character, and incrementing a counter. The final value of the counter is how many characters were in the file.

while((int i = fileReader.read()) != -1){
counter++;
}

Now, below is a different way of doing the same thing. Below is how you do it with a File Object. You already created a file Object, so I'll use the one you created, and call it's length() method. The length() method for the File class tells you how many bytes are in the file. Since a character is usually represented by one byte, this also tells you how many characters are in the file.

File file = new File("name");
System.out.println("Chars in the …
BestJewSinceJC 700 Posting Maven

All of the ways I mentioned are pretty easy, but the easiest way would be to make a File object (like you already did), and then use file.length(). file.length() returns the number of bytes in the file, which is the same as the number of chars in the file.

(Note: on some systems, chars may be two bytes, in which case, what I just said would be incorrect. Do a simple test with a small file and count it by hand to make sure)

BestJewSinceJC 700 Posting Maven

No, it does not, because Scanner's hasNext() method does not get the next character, or get anything for that matter. It tells you if the Scanner has any more tokens in its input, and it does not advance past any input. So you'd be sitting in an infinite loop (if there were actually tokens). A token is just matched by the delimiter pattern, which by default, is whitespace. So if you had the following:

blah deee weeee

The first token is blah, the second is deee, and the third is weeee. Anyway, I don't see why you don't just construct the file Object then use the File's length method to see how many bytes are in the File, which tells you how many characters are in the file. Here is the documentation I am referring to when I'm talking about Scanner and File. Although it is a good idea to get familiar with both, so you don't need to look it up.
http://java.sun.com/javase/6/docs/api/java/io/File.html#length()
http://java.sun.com/javase/6/docs/api/java/util/Scanner.html#hasNext()

Alternatively, you can either look up FileReader here on Daniweb (this will bring you to other threads where people had similar questions to the one you are asking), or you can look at this documentation: http://java.sun.com/j2se/1.5.0/docs/api/java/io/FileReader.html . In particular, consider using the read() method of the FileReader class after you construct your FileReader object. It reads a single character at a time.

The modification of your program, one way or another, to produce the correct result …

BestJewSinceJC 700 Posting Maven

One test program is worth a thousand expert opinions.

(Not that I'm an expert, because frankly, I'm not. But it's the truth.)

BestJewSinceJC 700 Posting Maven

Well, first of all, I'd make it Object Oriented. . so the board would be part of a class, and you could create a new board by creating a new Object of that class type. You would also need two types of constructors: one that took an existing board (so that your new Object's board would be the same as the previous board). And one empty constructor, which would create a blank board.

BestJewSinceJC 700 Posting Maven

If you want to start a completely new game, then the ideal way would be to have Life set up as a class, and you'd simply create another Object of that class type. Alternatively, you could set all your variables back to blank/however they were initially. But if you're referring to somehow continuing a game already in progress, then nevermind what I just said. You should also create another thread and explain your problem in there.

BestJewSinceJC 700 Posting Maven
if (stream != null) {
    stream.close();
}

return stream.read();

Why would you close the stream, then read from it? ....

BestJewSinceJC 700 Posting Maven

If you want to read from a file and count how many characters are in it, use FileReader or FileInputStream, not InputStream, since you cannot open a File with InputStream. Then use a while loop like they said, incrementing a counter for each byte you read. The final value of the counter is how many characters were in the file.

Also, note that FileInputStream is not recommended for reading characters. I'm not sure why, but a wild guess would be that it deals with the fact that chars in Java are 16 bits, but chars on your computer might be represented as 8 bits. This might be completely wrong, feel free to do some research on your own.

[FileReader] Convenience class for reading character files. The constructors of this class assume that the default character encoding and the default byte-buffer size are appropriate. To specify these values yourself, construct an InputStreamReader on a FileInputStream.

BestJewSinceJC 700 Posting Maven

From my assessment, the JPanel is sized according to the LayoutManager of the container that it is in. In this case, it is in the JFrame. So calling getSize from the JPanel's constructor doesn't make much sense. When it is still in the constructor, your JPanel isn't even finished creating yet, so how could it's height possibly be anything other than 0 unless you explicitly set it to something other than 0? And the JPanel also isn't visible yet, so its height will be 0. In any case, consider this code:

public static void main(String[] args) {
		// TODO Auto-generated method stub
		JFrame frame = new JFrame();
		JPanel panel = new JPanel();
		panel.add(new JButton("what"));
		frame.add(panel);
		frame.setSize(200,200);
System.out.println(panel.getSize().height);
		frame.setVisible(true);
System.out.println(panel.getSize().height);
	}

This prints:
0
166

This example is meant to show you that if your panel is inside another Component, such as my panel being inside the JFrame, the panel will be resized according to the size of the JFrame. However, in your code that you are having trouble with, since your panel hasn't finished being created (and your frame has not yet been setVisible), the JFrame has not resized the panel yet. Therefore, its height is 0.

Now consider this piece of code:

public static void main(String[] args) {
		// TODO Auto-generated method stub
		JPanel panel = new JPanel();
		panel.setSize(0,166);
		System.out.println(panel.getSize().height);
	}

This is just meant to show you that one way the panel could have a height other than 0 is if you …

BestJewSinceJC 700 Posting Maven

Did you try calling setSize on the JPanel, then calling getSize afterwards? Also, post your code.

BestJewSinceJC 700 Posting Maven

Judging by the fact that you got the expected output, and not an error, it seems like a safe assumption, doesn't it? If you're concerned about it, run some tests on varying inputs. You'll probably find that it works fine. My guess is that the toLower() function uses the ASCII table to verify that something is a letter and acts appropriately (there are plenty of symbols that aren't letters OR numbers). Also, are you sure you can't look at the function's code yourself, by looking in some standard library?

BestJewSinceJC 700 Posting Maven

Heh. That invalidates everything I just said about customizing the buttons, I didn't realize they already had one with the buttons yes and no on it. *hangs head* ....

BestJewSinceJC 700 Posting Maven
boolean validChoice = false;

while(!validChoice){
//Get the user's input, if it is y or n, set validChoice to true.
}

You said you "need exception", do you mean you want to throw an exception? If so there are a few ways you can do that.

edit: I just realized you're using GUIs to get the input, in which case, James' code is obviously better since it lets the user input through a GUI. There is also a lot of information here showing you how to force the user to input either yes or no (the window won't close until they choose one or the other) and there is an example here of how to put the buttons yes and no on the window. So obviously, combining those two ideas, you can force them to input either yes or no with no loop if you really want to do that.

BestJewSinceJC 700 Posting Maven

Why are there so many spaces between the last 0's but not between the first numbers? In your other post, there are much fewer spaces. Perhaps you should identify some patterns in the input file before attempting to produce the corresponding output file. Either way, I don't really understand what your rules are for the output file; as far as I know, it's a random number of spaces, so I'll stop wasting your time. It seems like James knows whats going on here though so you'll just have to wait until he gets back on. Good luck & happy coding.

BestJewSinceJC 700 Posting Maven

The number of spaces you put before each number needs to be based on the length of the number. So you have to get the length of the String that you want to print out and do some sort of subtraction to figure out how many spaces you need to put before it. Can you post your print method? Also, are these the rules for the output file:

1. there must be at least one space between each column of numbers in the output?
2. The number of spaces between two columns is 3-(number of digits in the second column)?

BestJewSinceJC 700 Posting Maven

^^^ Grisha never even had i = a -2 anywhere in his code? And I'm pretty sure what I mentioned was the actual problem, not what you are talking about.

BestJewSinceJC 700 Posting Maven

All of this is do-able in one class. But I've seen the texts before, they usually do it using two classes. Good luck & mark this as solved if your question was answered