BestJewSinceJC 700 Posting Maven

The default file selection mode for JFileChooser is FILES_ONLY so change it to FILES_AND_DIRECTORIES, see this link: http://docs.oracle.com/javase/tutorial/uiswing/components/filechooser.html . The method is setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES)... then try your code again. If it still doesn't work, please post it. I rarely use JFileChooser..

BestJewSinceJC 700 Posting Maven

http://docs.oracle.com/javase/tutorial/uiswing/components/tree.html#select See the section on "Responding to node selection". When the selection changes, get the selection and use the JFileChooser's setSelectedFile method to set it accordingly.

BestJewSinceJC 700 Posting Maven

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.

*blush*

Of course, you're correct, though it eluded me when I posted earlier. I'm leaving my original post intact so as to not make things even more confusing. Thanks for clearing that up James.

BestJewSinceJC 700 Posting Maven

I doubt your connection is closed because of garbage collection. It is probably closed because your connection is established, your code runs, your method exits, and the program is finished so it closes Sockets etc. Garbage collection does happen, but isn't the cause of your issue. In order to keep your connection alive you'd need to have a while loop or some other loop.

See http://download.oracle.com/javase/tutorial/networking/sockets/examples/KnockKnockClient.java for an example of a connection that would stay open.

See
http://download.oracle.com/javase/tutorial/networking/sockets/ to learn about Sockets in Java.

You should probably implement a system whereby the client/server can have slightly more advanced communication, e.g. client tells server "I want the list of files" then waits for the server to send them, etc.

BestJewSinceJC 700 Posting Maven

If you put it in Tomcat's webapps directory and then start Tomcat [either as a service or by double clicking the tomcat file in /bin] it will unpack the .war.

edit: Just read stul's link, which said basically the same thing. Sorry I wasted my time.

BestJewSinceJC 700 Posting Maven

please suggest, do not disgrade or disrespect others work....
atleast the person tried to solve and solved. if you had something to edit , could have mentioned , why to go harsh..

I think you meant do not "degrade". And they aren't being harsh, they are explaining the difference between being handed the answer and learning how to solve the problem.

1. Using an optimized method by not checking whether the number is divisible till one less than number,instead using the concept that is number is prime,it will nt be divible by any numbers between 2 and square root of the number.

No, a prime number is divisible only by one and itself. So the OP must check all numbers between 2 and half of the "possible prime number" to see if any of those are divisible. There may be other tricks that can be used, but that's the general idea.

BestJewSinceJC 700 Posting Maven

What happens if you execute those SQL statements from within SQL Server itself; does anything get updated? Are the results what you expect? Alternatively, have you tried running the C# code and using SQL Server Profiler to see what SQL statements get executed on the Server (you can run profiler from within SQL Server management studio)? Sometimes it is your SQL that is incorrect and not the C# code.

Example of using multiple sql statements in one query
http://www.java2s.com/Code/CSharp/Database-ADO.net/ExecutemultipleSQLstatementsusingaSqlCommandobject.htm

BestJewSinceJC 700 Posting Maven

Because the "and diet" portion of the query is invalid syntax. It must be getting appended to the end of your query from somewhere, so figure out where it gets appended to the query, and either remove it, or make it a properly formatted query (e.g. and diet=something).

BestJewSinceJC 700 Posting Maven

This is in the wrong forum. Generally you write an .aspx page and you can write a codebehind file in C# and hook into the asp.net Page lifecycle (google it) from your C# code. To actually get the page to load it would have to be in a location that the web server "knows" is a location where web accessible pages are located, but how you'd set that up I really don't know.

BestJewSinceJC 700 Posting Maven

Details. Code you have so far, specific questions, etc

BestJewSinceJC 700 Posting Maven

So do you need any more help? If not mark the thread as solved

BestJewSinceJC 700 Posting Maven

invokeLater() probably has nothing to do with the problem you are describing. You didn't really explain what you mean by "resuming the program after you go through all the MouseListeners". What does it mean to "go through all the MouseListeners"? MouseListener is an interface; it has several methods that respond to mouse events. Are you waiting until each of those methods gets called, then continuing your program afterwards? If so, you may want to declare some boolean variables that get set to "true" from within the corresponding MouseListener method. Once all of those variables are true, you can "continue your program" by calling a method from within the MouseListener method.

For example:

void mouseClicked(MouseEvent e){
if (all mouse methods have been called){
continueMyProgram();
}

void continueMyProgram(){
//Put the rest of your program's code here!!!

}
}

References: http://download.oracle.com/javase/tutorial/uiswing/events/mouselistener.html

BestJewSinceJC 700 Posting Maven

http://www.asp.net/mvc

Ask a specific question if you expect a specific answer.. Otherwise read through the provided link

kvprajapati commented: :) +12
debasisdas commented: must read +9
BestJewSinceJC 700 Posting Maven

edit: I just realized that you're probably a student, and if so, you may be looking to use flat (normal) files. If that is the case then I would still recommend saving the images elsewhere and referencing them (perhaps just by a pathname, if your program is a desktop app), and you could save the text in a file. So the file would consist of your text sections + a pathname to the image. You could separate your text sections in hundreds of different ways. You should look into the Scanner class

Are you concerned about where to store and retrieve the images/text or how to store them? The answer to where is definitely to do it in a database. Assuming that you could be supporting multiple users, I would use a relational database and create several tables. One table would be for storing images (ID, image). One table for storing usernames (ID, username), one table for storing text entries, and one for storing the view you described (text areas + image).

The table for storing the view you described would have a foreign key referencing the users table as well as foreign keys referencing the image for the view and the text areas for the view.

Disclaimer: I'm NOT a database developer and this approach would definitely work, but for efficiency's sake you should wait for some other opinions on this one. (And in the meantime, describe your requirements more thoroughly)

BestJewSinceJC 700 Posting Maven

I have html similar to this

<span><a href="link"><img.. /></a></span>

. In IE and Firefox, when the image is clicked, it highlights a box around the image. From that point on the box remains around the image. I don't want any highlighting effects whatsoever. How can I use css or an inline script to get rid of them, especially in IE?

Btw, I thought it was a:hover and a:visited and stuff like that but I tried

a:visited.myclassname{
text-decoration:none;
}

And it did not work. In IE, the developer tools showed that my inline style was getting overridden, even when I used !important with it. Why would an inline style ever get overridden? Are the browser settings themselves overriding it? And how do I fix this? (I'm probably just using the wrong property... but it is still annoying that it was getting overridden somehow)

BestJewSinceJC 700 Posting Maven

That's because I graduated, got a job, and stopped posting in there.

:p


edit: but I'm coming back now, in the java forum.

AndreRet commented: Funny! +0
BestJewSinceJC 700 Posting Maven

Use the Scanner class. There are tons of different ways you can do this with the methods in there, some involving regular expressions/Pattern, some with only the basic Scanner methods.

BestJewSinceJC 700 Posting Maven

How many for loops does bubble sort use?

BestJewSinceJC 700 Posting Maven

you put a ; after the main method. Erase the semicolon.

BestJewSinceJC 700 Posting Maven

isEmpty and isFull should be easy. Maintain a variable for the size. Whenever you enqueue, add 1 to that variable. Whenever you dequeue, subtract 1. isEmpty and isFull just depend on the value of that variable. For the actual enqueue operation, maintain the head of the queue as the index 0 and the tail of the queue as the last index. Then check the size variable I previously mentioned.

Example to help you get on the right train of thought for enqueue...

-- starting values --
queue[0] = something, queue size = 1
-- do an enqueue operation for the new element = 2 --
queue[0] = something, queue size = 1, queue[size] = queue[1] = 2

Hopefully that will help you for dequeue as well. Remember that when dequeueing, you need to shift the values in the array one place to the left (if you are using array[0] as the head) and you need to maintain the right queue size.

BestJewSinceJC 700 Posting Maven

To add to jon's reply, look into

Auto boxing and unboxing (example: Integer i = 5; will result in auto boxing) and especially look into inheritance. Don't sweat specific examples, such as your array example, until you have a thorough understanding of inheritance and the is-a relationship. Since Character 'is-a(n)' Object, that is why you can put a Character (or any other java class, since they all inherit directly or indirectly from Object) into an Object array.

BestJewSinceJC 700 Posting Maven

Agreed - that order would be preferable. Like I said, make your own class. In the class constructor, pass in your File Object. Get the String filename from that file Object. Use a Regular Expression (or even a simple character check - String.charAt(index).isDigit()) to figure out where the A-Z part of the filename ends and where the numerical part begins. Put the A-Z part in one String variable and the numerical part in an Integer variable. Make sure your class implements Comparable, and in your compareTo method, use your String variable and your Integer variable to do the comparison. For the comparison itself, you can use String.compareTo and Integer.compareTo.. when you do the String.compareTo, if there is a tie, you can resolve it by doing the Integer.compareTo..

BestJewSinceJC 700 Posting Maven

It is in correct alphabetical order. It's using the numerical value of each of those characters, regardless if it is a letter or number, then comparing the numerical values to do the sorting. 1 comes before 2, and it only breaks on ties, so 10 also comes before 2.

I'm way rusty on Java right now but I'd just find a library to do this for me. If not, just create a new class that implements Comparable. An easy way to do this, if your filenames are always in the format NameNumber is to use a Regular Expression to split the filename into two separate variables, name and number. Then in your compareTo method (required to implement Comparable) you'd compare the Strings. If there is a tie, then compare the numbers. For the String comparison and number comparison, you can just use Java's existing methods to do those comparisons. So implementing this shouldn't be that hard, though I'm not sure it is the best solution.

BestJewSinceJC 700 Posting Maven

Well, I do know that if you do not mark the class as public (which you did not), the default visibility is package level, which means your class can only be accessed by other classes in the same package. So either mark the class public, or put the other class in the same package. Then tell me what errors you're still getting, and paste the whole error this time.

BestJewSinceJC 700 Posting Maven

Yes, there are different features I'm sure. Can you use web services on SE?

BestJewSinceJC 700 Posting Maven

Ok, are you having any trouble with it? /What do you still need help with

BestJewSinceJC 700 Posting Maven

You have to pass your tire pressures as parameters to the constructor. You also have to modify your constructor so that it will take the parameters, and you also have to set your Pressure class's instance variables to the values you pass in when you call the constructor.

BestJewSinceJC 700 Posting Maven

I'm not sure Exceptions are your best bet here. They might be, but think carefully about what you want.

Here's an example of a WRONG use of exceptions, which I've actually seen in production code. Never do this:

public boolean isNumeric(String s)

{
  try{
    Integer.parseInt(s);
    return true;
  }
  catch (NumberFormatException e)
  {
    return false;
  }
}

If you ever come across code like this in a project you're working on, rewrite it. Exceptions are not flow control.

That's not what kramerd was suggesting, but the idea of using exceptions in this context brought it to mind.

I think what kramerd is talking about is making your own Exception - InvalidAccountNumberException, maybe - and throwing that back to the class that's trying to create the account.

That's a valid use of the Exception mechanism, but it seems a bit much for your purposes. In an enterprise sort of application, or a package that will be distributed out of your use, you would use Exceptions in this way to force people to check for things like well-formed account numbers. If you say "throws InvalidAccountNumberException", then anyone using it HAS to catch that and handle it. Try blocks get old real fast.
Maybe you want to play with that - it certainly can't hurt, and it might impress your prof.

However, a simpler way to get the job done would be to
a) validate the String before you use it in the constructor
or
b) write the constructor to take …

BestJewSinceJC 700 Posting Maven

You could set both the maximum and minimum size, although there may be a better/different way of doing it.

setMaximumSize()
setMinimumSize()

in Javadocs.

BestJewSinceJC 700 Posting Maven

Yes, you can add a second catch block right after the first one. The second catch block should catch InputMismatchException

BestJewSinceJC 700 Posting Maven

I guess you are using ArrayList a wrong way...
1)ArrayList is not supposed to hold collection type (array)

Not a test code below, but hopefully you would get an idea about how to do it.

public static void main(String args[]) {
    try {
 for (int j=0; j<arr.length; j++) {     // arr.length == finalTemp[i].length
          finalTemp[i][j] = Double.parseDouble(arr[j]);
        }
      }
    }catch( IOException ioException ) {}
  }
}

Why isn't it "supposed to be used to hold an array"? An array is an Object and therefore you can use an ArrayList to hold an array. Is it the best idea, usually not, but I'm not sure where you're getting information about that. Also, I thought I should mention that an IOException will not help you if parsing the double fails, since it will throw an InputMismatchException which is *not* an IOException. You either need another catch block (to catch the InputMismatchException) or you need to make your Exception more generic (e.g., Exception)

BestJewSinceJC 700 Posting Maven

No, you do not have to read it as a String - there are Java library methods that will allow you to read other types from a file. However, that is ignoring the point - that your code, the way you have it now, will work with very minor changes.

Read it in as a String, like you're doing now. Then use the Double.parseDouble() method that I mentioned in my first post to convert the String you just read in into a Double. Then put that Double into your ArrayList<Double> using the ArrayList class's add method.

BestJewSinceJC 700 Posting Maven

The <Double> means you can only put that type into the ArrayList. So if you try to put a String into the ArrayList, then yes, you'll get an error. If that doesn't help, you'll need to post your exact error.

BestJewSinceJC 700 Posting Maven

edit: I could be totally wrong, but I see nothing wrong with your code. Did you use the check on s.execute to verify that the query was successful? It returns 'true' if there are results. I see you used a similar check by checking if the ResultSet was null though. If your query isn't returning any data through java, after checking the return of s.execute, have you used any other tools to verify that the DB actually contains data for your query?

BestJewSinceJC 700 Posting Maven

Using ArrayList as a raw type isn't a good idea. You can use Java generics to enforce type checking. In other words you can change it to ArrayList<Double> list = new ArrayList<Double>(); in order to allow only Doubles in the list.


That being said, you can use the Double class's parseDouble method to parse a Double from a String. For example, Double result = Double.parseDouble(myString); . You'll need to be careful because an Exception will be generated if the 'myString' variable cannot be converted to a Double, so you will need to use a try/catch and deal with the condition where it can't be parsed appropriately.

The code you posted before would allow you to insert any type of Object into your ArrayList. However, as I've indicated, it is a better idea to keep the list of one type (Double in this case). Then you can use an add() method which takes a String parameter to add Doubles to your list. For example:

String myString = reader.getValueFromUser();

public boolean add(String str)
{
   try {
     //parse the Double in here and add to your list
   } catch(Exception e){
     //do something else here, probably just return 'false'
   }

}

Hope that helps. If any of the above didn't make sense, feel free to ask questions, but you should also check out Java Generics, the Double class documentation, and Exceptions.

BestJewSinceJC 700 Posting Maven

My inclination would be to have a class variable(s) that track the Mouse position. The way you could do this is by setting up the variables to track x, y position and in the MouseMoved method, first you'd update those variable, then you'd call repaint() which causes paint() to be called. In the paint() method you could then utilize these variables. As for detecting when the mouse moves off screen, use the MouseListener interface, specifically the mouseExited method. Combined with some simple if statements in your paint method, this should be all you need.

It's been a long time since I've coded Java ("coding" sharepoint now), so hopefully this was good advice.

BestJewSinceJC 700 Posting Maven

IndexOutOfBoundsException typically means that you attempted to access an index of an array, but the index you tried to access was greater than the highest index of the array. So somewhere in the getStringArray method this is happening, although you didn't post that method's code.

BestJewSinceJC 700 Posting Maven

If you want help ask a specific question. At the very least, point us to a part of your assignment requirements that you don't understand how to implement and ask for clarification. If you don't understand the entire assignment, that's fine, but explain what you don't understand, why you don't understand it, and relevant attempts at solving it, if any.

(I say the above 'cuz it looks to me like you copy pasted your assignment and then your code..)

BestJewSinceJC 700 Posting Maven

That depends whether you can insert elements to any cell you see fit just like a regular array. What you are describing is Vector.
javajavajava - can you please post the complete instructions?

It certainly isn't since a Vector doesn't increase its size by one when it grows, unless you've manually set the capacityIncrement to 1.

protected int capacityIncrement

    The amount by which the capacity of the vector is automatically incremented when its size becomes greater than its capacity. If the capacity increment is less than or equal to zero, the capacity of the vector is doubled each time it needs to grow.
BestJewSinceJC 700 Posting Maven

No, I cannot, unless you own a never ending hard drive.

;)

BestJewSinceJC 700 Posting Maven

Apologies if you already know about this/it isn't a problem for other people, but the banner at the top consistently covers up the Software Development drop down for me. Just letting someone know. Thanks

:)

BestJewSinceJC 700 Posting Maven

Can you explain your reason for putting Integers and Characters in the same array? Also why you'd want a "DoubleStack" ?

BestJewSinceJC 700 Posting Maven

What you did by calling replaceAll is construct a new String with all of the whitespace removed. The returned String was smaller than your original String, hence when you used the original index, it was larger than the size of the String. In my first post I gave a suggestion: use replaceAll (like you used it) to remove the whitespace. Then use a loop to check the strings to see if they're palindromes. Simple if statements can ignore punctuation ..

BestJewSinceJC 700 Posting Maven

In your new String, either "LHS" or "RHS" represents an Index which is no longer valid. Since replacing whitespace with "" makes your string shorter, your index is no longer valid in the new string. In your new string, which is shorter than the old string, more than likely the "RHS" is greater than the highest index

edit:

to add to that, the above is the reason why you should really be making a custom method which simply goes character by character through your string and ignores whitespace. The replaceAll technique isn't bad, but after you do that, you should use a for loop to check the two strings to see if they're the same.

BestJewSinceJC 700 Posting Maven

If you define a method as taking an int parameter (which is how your AccelerateSpeed() method is defined) you need to pass it an int when you call the method. And if you re-read James' post, he was saying that you have a variable 'speed' declared at the class level and then you have a different variable 'speed' declared at the method level (the name of your parameter is speed). If you want to refer to the 'speed' variable you declared at the class level (which you do) then use "this.speed".

this.speed = speed + 5;

http://download.oracle.com/javase/tutorial/java/javaOO/thiskey.html

If none of this is making sense to you, I suggest going through the beginner java tutorials at the top of the site and coming back with some specific questions about concepts you don't understand.

BestJewSinceJC 700 Posting Maven

#4 by rep. This only proves that rep means nothing :)

You're much too modest.

I'm also in the top 50 for rep, post count, and solved threads. Like Nick, looking at most of the other members in those ranks I feel that my knowledge definitely is dwarfed, but of course, this is relative.

Anyway, Dani, I remember being upset before when I visited, but it has been awhile since I've been active (due to finishing college, now work). I apologize for any previous offensive comments I made. And I have to say, I'm impressed by the site and the work you and (possibly others) have done with it.

Still hate the purple.

:p

BestJewSinceJC 700 Posting Maven

In this scenario, you are trying to make sure an Integer is in a certain range. So use a while loop and continuously prompt the user for a value until they enter one that is in the correct range. Generally, when you anticipate an event (such as an Integer that isn't in the right range) and can deal with it without Exceptions, you should not use Exceptions. An example of why you would need to use Exceptions here is if the user enters something that is not parseable as an Integer.. in which case, the parseInt method would throw an exception - probably InputMismatchException - (since it cannot reasonably deal with the condition where the String you gave it isn't an Integer) and your calling method would have to deal with that possibility.

A more reasonable scenario for your InvalidTestScore exception might be, lets say you have an Excel file where you have a list of test scores. Now lets say you use a Java program to read in those test scores from the Excel file. You could create a method addTestScore(int score) and use it to add each test score. If the user input an invalid score in their Excel file (< 0 or > 100) then you'd throw new InvalidTestScore, that way you can let the calling method deal with the scenario where that happened.

Anyway, I'm not trying to be critical or anything, but the code you gave just doesn't make sense to me. Who …

BestJewSinceJC 700 Posting Maven

Yes. The HashMap class's add() method takes an Object as a parameter. As you can see in the Java language specification, arrays are Objects.

See:
http://java.sun.com/docs/books/jls/second_edition/html/arrays.doc.html
http://download.oracle.com/javase/1.4.2/docs/api/java/util/HashSet.html

BestJewSinceJC 700 Posting Maven

If you're in a method, which you have to be, you could say "return;". I wouldn't worry about it too much if you have a working method though.

BestJewSinceJC 700 Posting Maven

Use an if statement.

boolean firstGuess = true;
long totalTimeMillis = 0;
if (firstGuess){
...
}

That should get you started