7,116 Posted Topics
Re: All you need is a counter in your DisplayButtonMessage class that you can increment inside the actionPerformed until it reaches 6. You need to declare it in the class so its value will persist between the sucessive calls to actionPerformed. | |
Re: Take a short break, then go back to 1stDAN's post above, which spells out exactly what you need to do. | |
Re: Hello again Matt. These follow-on questions could have been added to your original thread, but if you want to start a new thread when the actual question changes perhaps you could take a second to mark the previous threads as solved. Just consider what conclusions people may draw from you … ![]() | |
Re: Youhave the Event - it's the parameter in actionPerformed. That gives you the source component. You can then test the attributes of that component (eg its actionCommand) to see which component it is. Eg if ( ae.getSource().getActionCommand().equals("Save"))... | |
Re: That link refers to the old Runtime.exec method, which was mostly superceeded in Java 1.5 by the ProcessBuilder class - the doc is in the usual places.. http://docs.oracle.com/javase/7/docs/api/java/lang/ProcessBuilder.html | |
Re: Java chars are really numeric values that represent Unicode (ASCII) characters, and as it happens the ASCII value for the character '1' is decimal 49 (see http://web.cs.mun.ca/~michael/c/ascii-table.html). Your bit0 variable is an int, so Java displays it as a numeric value, not the character that it represents. If you declare … | |
Re: If you read it in as a String you can then use String's toCharArray method to give you an array where each element is a single character from the String. | |
Re: See http://www.daniweb.com/software-development/java/threads/430542/java-projects-for-learners One of the more advanced projects there should be suitable as a starting point. | |
Re: Do you mean cut into quarters, or reduce to one quarter of the size (in which case use Image's getScaledInstance method)? | |
Re: [QUOTE]Error: The serializable class MyGrid2 does not declare a static final serialVersionUID field of type long[/QUOTE] Serialisable classes are supposed to have a serialVersionUID field so, in theory, you can update the serialisation in the future and know which version you are using. In practice this is complete rubbish, but … | |
Re: A JTextArea is really bad choice of component to display an image - it's specifically designed to display lines of text. Maybe you should re-think your choice of components? If you explain what you are trying to achieve maybe someone can suggest an easier way to achieve it. | |
Re: getScaledInstance - just pass it the desired width/height and a scaling method (use SCALE_DEFAULT if yo don't know). It returns a new Image that is the size you requested. | |
Re: On lines 34-46 you prompt for first and second number, even if the user's menu choice was not a calculation (1,2,3 or 4) If the user's choice was 5 your program exits properly after prompting for those two values. You may want to make prompting for 1st and 2nd number … | |
Re: No time to read your code now.. but... You will learn an awful lot now from looking at the source code fr the actual API classes (eg how exceptions are handled in arrayCopy) - you should have a source.zip file in your jdk directory which contains it all. I recommend … | |
Re: Yes, you can read or write the bytes of any file, Java doesn't care what the extension is. But you will need extra libraries to interpret the contents of MS office files, PDFs etc. It's easy to find them, just Google. | |
Re: Just use readLine inside a simple loop to read all the lines and append them to your edit buffer. | |
Re: 3 errors: First is self-explanatory while(i... i is defined inside the while loop's {}, so it's not accessible outside those {}. Define it before starting the loop. Ditto result - defined inside the loop so not accessible outside it. Define it before starting the loop | |
Re: Iterable would be a good thing so you can use the enhanced for/each loop with your data structure. For the absolute pinnacle of professionalism implement the whole Collection interface. Frankly I think your code is very good. | |
Re: Lines 118-125 you get the date info, but you don't call your set method to save those values. Without date of birth the age/target heart rate etc won't give correct values. | |
Re: Yes, it will help show just how bad a beginner's code can be. If you enjoy schoolboy howlers like these then go ahead and feast on Vaibhav's code. if you want to score more than an "E" on your assignment then write something yourself. public static void main(String args[])throws IOException … | |
Re: I don't understand how "Welo" is an increasing sequence! I would have thought that "elo" was the answer for "Welcome", and either "el" or "co" from the longer example. Maybe a few more examples would help? | |
Re: There are lots of people here who will freely give their time to help you become the best Java programmer you can be. There's nobody here who is interested in helping you cheat or doing your homework for you. DaniWeb Member Rules (which you agreed to when you signed up) … | |
Re: There are lots of people here who will freely give their time to help you become the best Java programmer you can be. There's nobody here who is interested in helping you cheat or doing your homework for you. DaniWeb Member Rules (which you agreed to when you signed up) … | |
Re: Oracle's tutorials are excellent - see http://docs.oracle.com/javase/tutorial/essential/concurrency/ | |
Re: Hi Neha Sorry so late in replying; somehow I failed to notice you original post. What you did was a good solution - for the length of the line you can just call getWidth() which you inherit from JSeparator and which tells you the current width (ie the necessary line … | |
Re: You will find excellent tutorials, plus the complete detail of every single API class and method on Oracle's web site http://www.oracle.com/technetwork/java/javase/documentation/api-jsp-136079.html For example, in the API doc you will find the detail on the Calendar class that alows you to add or subtract hours, days, months etc to a date/time | |
Re: == means "refers to exactly the same object (same address in memory)" equals(...) usually means "may be a different object, but the two objects have equivalent values, so I will treat them as equal" | |
Re: Did you `setFont` for your `Graphics` befroe drawing the text? | |
Re: ArrayList is a Collection, which means you can use its `contains` method to see if it already contains an "equal" Line > contains(Object o) returns true if and only if this collection contains at least one element e such that (o==null ? e==null : o.equals(e)). | |
Re: It's exacty the same as addition except for the occasional minus sign instead of a plus sign. Just compare those two methods to see where sub deviates from the correct pattern in add | |
Re: DaniWeb Member Rules (which you agreed to when you signed up) include: "Do provide evidence of having done some work yourself if posting questions from school or work assignments" http://www.daniweb.com/community/rules Post what you have done so far and someone will help you from there. | |
Re: I have no major comments, but There a some loops that could use the simpler enhanced for loop syntax, eg for (int index = 0; index < data.length; index++) { dmap.put(data[index], 0.0); } vs for (String s : data) { dmap.put(s, 0.0); } Instead of `for (Double s : dmap.values().toArray(new … | |
Re: To debug a problem like this, put a temporary print startement inside your loop (eg print the value of nSlices). Then you will be a ble to see if it is looping, and ifits an infinite loop you will get clues as to why that is. And yes, you will … | |
Re: DaniWeb rules include: "Do post in full-sentence English" It is OK if your English is not perfect. | |
Re: the counting looks ok, but when you print I don't understand why you do that stuff with "num". countA[i] contains the count for value i, so why not just print that? | |
Re: MVC, Listener/Observer - all the time. They're essential for Jave UI work. | |
Re: There are lots of people here who will freely give their time to help you become the best Java programmer you can be. There's nobody here who is interested in helping you cheat or doing your homework for you. DaniWeb Member Rules (which you agreed to when you signed up) … | |
Re: DaniWeb Member Rules (which you agreed to when you signed up) include: "Do provide evidence of having done some work yourself if posting questions from school or work assignments" http://www.daniweb.com/community/rules Post what you have done so far and someone will help you from there. | |
Re: I guess there are quite a few of us here who don't understand exactly what you are trying to achieve. Perhaps you could make it clearer with an example? You have an exec of WinWord.exe in one of your earlier posts. Suppose your application was complete and correct; what output … | |
Re: Hi Aditya, wecome to DaniWeb. kingarthur posted this 4 years ago, and hasn't been seen here for the last 2 years, so you probably won't get a reply from him now. Start a new thread of your own and someone will help. ps Don't be surprised by long run times … | |
Re: The declarations on 42/43 hide the variables declared on lines 17/18 - probably not causing trouble in this case, but a bad idea anyway. | |
Re: Swing has been double-buffered by default from around Java 1.5, so all this stuff, while interesting, is now completely unnecessary. Also overriding paint is a bad idea for JFrame - override paintComponent for a JPanel inside a JFrame instead. See http://www.oracle.com/technetwork/java/painting-140037.html#swing | |
Re: rs is an instance of ResultSet, so you can use the Java API documentation to learn all about its methods, eg http://docs.oracle.com/javase/7/docs/api/java/sql/ResultSet.html#getString%28int%29 ![]() | |
Re: That cross-posted version shows two different versions of the SQL satement (both different from this one), so until OP gets his head straight we're all just chasing will-o-the-wisps here. | |
Re: Lines 259-297 contain empty methods that will be called when the user clicks etc on the corresponding controls. All you need to do is to put your code into those methods. Start by just putting a simple System.out.println, so you can confirm that the method is being called when you … | |
Re: Yes, what exactly is the question? Which part of the exercise can't you do? Is it just to extend the prof's code to perform the same calculation using your new class? | |
Re: Yes, it's possible, in fact easy, and a very common kind of thing to do. It's directly supported in the Java language. The Oracle Java tutorials are an excellent source of info. For "a brief overview on how to tacle this problem" start reading about locks [here](http://docs.oracle.com/javase/tutorial/essential/concurrency/locksync.html). | |
Re: Without seeing the relveant code it's impossible for anyone to know what's wrong with your application. | |
Re: Presumably you could start a java.util.Timer when you start the query, then when the Timer expires after 6 seconds its TimerTask could call Connection's abort method to terminate the connection (which in turn will abort the query with a SQLException). It's a bit crude, but should work. | |
Re: Your e.getStackTrace on line 208 is presumably a mis-type for e.*print*StackTrace. Fix that and see if you are getting any exceptions |
The End.