7,116 Posted Topics
Re: Just a guess - but do you have a loop with a sleep or wait in it to display the images? If so, read up on the Event Dispatch Thread (EDT) AKA the Swing Thread, and use a javax.swing.Timer instead. If not, ignore this post. | |
Re: Java DB (a version of Apache) is bundled with the JDK from version 6 onwards and is guaranteed compatible, supported by Sun/Oracle, free, and runs on the same platforms as Java itself (apart from some Java ME versions). It's a safe choice and all you need for small-medium apps. | |
Re: [url]http://download.oracle.com/javase/tutorial/deployment/applet/security.html[/url] | |
Re: This is a lot easier if you indent the code so you can see which else goes with which if: [CODE]if (x>5) y=1; else if (x<5) { if (x<3) y=2; else y=3; } else y=4;[/CODE] | |
Re: Line 98 is a BIG mistake. If you have a problem reading the scores file you have chosen NOT to be told anything about it! In every catch block of a new program you should request a full print of all the info available on your error. [CODE]catch(Exception e) { … | |
Re: [QUOTE=scarletfire;1533816]I think 2118789 is the object. as I was suppose to store the player's info such as age,weight,height,games played and goals scored. and using the club class I was suppose to fetch a player's info using his name. the thing is, it only fetches the name and 2118789 instead of … | |
Re: I'm gonna vote on the side of never having public instance variables (except static final immutables), even if you do believe your class is safe against some bozo arbitrarily changing its values from some arbitrary concurrent thread. | |
![]() | Re: Yes, I'd expect that a web crawler would benefit from a few concurrent threads. Have a look at Executor and ThreadPool (JDK 1.5 and later) - they do exactly what you describe. Start here: [url]http://download.oracle.com/javase/tutorial/essential/concurrency/executors.html[/url] also [url]http://developer.amd.com/Pages/1121200683_3.aspx[/url] ![]() |
Re: [I@1ea5671 is the result of calling toString() on an array - its the method inherited from Object that just gives the object type and address The Arrays class has a toString method that you can use to get a quick text version of an int array. Details in the API. | |
Re: It would help if you told us the line number where the NPE is thrown. | |
Re: If you know how to work with a char array then a boolean array is just the same except that all the values are true or false. Where exactly are you stuck? | |
Re: No, that's not what masijade was referring to. It's your empty catch blocks like [CODE]} catch (MalformedURLException e) { } catch (IOException e) { }[/CODE] If either of these exceptions is thrown you will never know. If you have a e.printStackTrace(); in the catch block you will know exactly what … | |
Re: After a InputMismatchException the Scanner still contains the offending text, so you can catch the exception, then in the catch block use Scan.next() to see exactly what it was that it objected to. | |
Re: @Prem I know you are trying to help, but if you give the OP a complete solution then what have you done? You have helped them cheat, and taught them nothing. It's better to help by pointing him in a good direction, and suggesting relevant topics to read up. | |
Re: The printStatement method signature looks wrong to me. I would expect it to have no parameters, and just print a statement for the current account ("this"), OR, to take a list of accounts as parameter, in which case it should be a static method (ie belong to the class, not … | |
Re: Sun have saved you the bother - see java.util.GregorianCalendar in the Java API. If you have to do this yourself then a read through the preamble to the doc for java.util.GregorianCalendar will give you a good intro into what you need to achieve. | |
Re: [CODE]for (int i = 0; i < 10; i++) { // stuff here will be executed 10 times }[/CODE] | |
Re: It's enough to have the server listen and the client make a connection to it. Both ends can then open input and output streams over the connection so messages will flow both ways. Both client and server need to have a Thread that loops blocked listening on its input stream … | |
Re: An instance of the Class class represents a class in your program. Using that instance you can find and access all the attributes of that class (variables, methods, annotations etc etc). Its used as part of Java reflection (that's the keyword to Google), which is used to find out the … | |
Re: The error message should give you the exact line number where it happened. Care to share it with us? | |
Re: Your overall approach, with the public getData is good. The problem lies in [CODE]FormA page = new FormA(); // displays a new copy of the form String user = page.getData(); // gets the data immediately - before the user can enter anything![/CODE] Somewhere you should have a button or some … | |
Re: You need to declare your variable "buttons" as an array of Buttons, as in JButton[] myArrayOfJButtons; then, and only then, you can assign an new array of buttons to that variable myArrayOfJButtons = new JButton[2]; | |
Re: I've lost count of how many round-trip UML/code tools I've tried, but not one of them was any good for anything more than a simple class diagram. If anyone knows of an exception I would be genuinely grateful for details... Also, if you are unfamiliar with UML you'll have no … | |
Re: 1. To use Button's getLabel() method you must cast the Object returned by getSource() to a Button 2. You can't compare Strings with ==, use equals(String) instead, if you must. 3. If you want to know which button was pressed, test that directly [CODE]if( (ae.getSource() == ok) ...[/CODE] just remember … | |
Re: When / how often is this run? Possibly there is a thread-related problem with your (possibly long-ish running) thread and the user (and you own) updates to the JTextPane on the Swing thread (EDT). Both are updating the document, but there's no synchronisation between them. Maybe the fact that it … | |
Re: Use an AlphaComposite to set the drawing mode and alpha before drawing your image. Here's a simple sample... [CODE]Image myImage = ... float alpha = 0.5; @Override public void paintComponent(Graphics g) { Graphics2D g2D = (Graphics2D) g; AlphaComposite composite = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, alpha); g2D.setComposite(composite); // Set current alpha g2D.drawImage(myImage, 0, 0, … | |
Re: @ztini is right. But if you can't do that for some reason then you can enhance your sort methods to sort both arrays at the same time, eg in sortGradesByNames you swap elements with [CODE]int temp = grades[largest]; grades[largest] = grades[i]; grades[i] = temp;[/CODE] so then, in the same place, … | |
Re: It keeps printing every number you enter because the print statement is inside the loop where you enter numbers! Try splitting this into three stages, it's easier to think about things one at a time: 1. Get the 10 numbers from the user, saving them in the array 2. calculate … | |
Re: Have a look at the Arrays class - it has sort methods for arrays (and binary searches). You just need to implement a compareTo method for your Friends class (you'll find docs and examples in all the usual places). | |
Re: .jar files are just .zip files with some conventions about what's in them. A full description is on the Oracle java web site. You can edit them with your favourite zip file utility. | |
Re: The official Sun/Oracle tutorials are excellent. Start here: [url]http://download.oracle.com/javase/tutorial/[/url] | |
Re: A "loading", AKA "splash" screen is always a good idea. Java 6 includes a feature to show one even while your program is loading, so the user sees something as soon as he starts the program. Strongly recommended. [url]http://java.sun.com/developer/technicalArticles/J2SE/Desktop/javase6/splashscreen/[/url] On the other hand, if your program then goes wrong you … | |
Re: Second problem sounds like a firewall problem and/or a router problem blocking and/or not forwarding inbound traffic. | |
Re: leftSide is the contentpane for the window (previous listing line 5) bothSides is also the contentpane for the window (previous listing line 14) so on line 17 you are trying to add the content pane to itself, == error. At a guess, leftSide should be a new container. | |
Re: Once you have your .png read into a Java Image you can use the getScaledInstance method to re-size it to any size you want,any time you want. | |
Re: [CODE]WT[i] = Integer.parseInt(txtField2[i].getText())-1; WT[i] += Integer.parseInt(txtField2[i].getText())-Integer.parseInt(txtField[i].getText()); ie WT[i] = 2* Integer.parseInt(txtField2[i].getText()) -Integer.parseInt(txtField[i].getText()) -1;[/CODE] That looks odd to me, but anyway, have you printed ALL the values returned by all these parseInts to see if that are what you expect? Also, there's nothing in that part of the code that should … | |
Re: Eclipse : File : Export... Java - Runnable jar file | |
Re: Nobody here will do this for you. Try, and we will help. | |
Re: You need to makedirs on C:/d1/d2 to set up the directory structure, then write your C:/d1/d2/sample.txt file to the directory. | |
Re: [QUOTE]to keep DaniWeb a student-friendly place to learn, don't expect quick solutions to your homework. We'll help you get started and exchange algorithm ideas, but only if you show that you're willing to put in effort as well.[/QUOTE] Nobody here will do your homework for you, or help you get … | |
Re: The folder/subfolder structure MUST match the package structure - so as long as you keep these two in step (ie create a sub-package and a sub-folder at the same time for the same classes) it's no problem. In Eclise you can right cluck a package to add a sub-package and … | |
Re: In your method you have access to the size of the current CyberPet, and you also have access to the size of the other CyberPet that is passed as a parameter, so you can write a couple of if tests comparing those two things to decide what String to return. … | |
Re: Hi sumprit. What exactly are you having difficulty with? You need a method that retrieves and displays the right set of results. You need an instance variable (ie not declared within any method) that keeps track of which results to display (clickCount?). You need action listeners for the buttons that … | |
Re: You can create an array of swing components exactly like an array of any other class, eg [CODE]JButton[] myArrayOfJButtons = new JButton[6]; // creates empty array for 6 JBUttons for (int i = 0; i < myArrayOfJButtons ; i++) { myArrayOfJButtons[i]= new JButton... // put a button into the array[/CODE] | |
Re: Line 11 I think you misunderstand the isLetter method. It returns true if a is a letter (as opposed to a number or a punctuation symbol) so you are replacing every letter with 'v'. You should be testing whether the char is equal to 'a' | |
Re: That's how a standard ActionListener works anyway. Just Google it. | |
Hi y'all. I'm looking for feedback and discussion on the use of annotations to eliminate the boilerplate code for linking buttons and methods. Hopefully this will be especially useful in RAD or rapid prototyping environments. Over the weekend I hacked together a little proof of concept that supports two ways … | |
Re: If you check the posting dates you'll see that it was @casinoua who disinterred this corpse. @stultuske was just telling him off (quite rightly). | |
Re: 5 on one side 2 on the other says "two JPanels" to me. Having said that, I have yet to find a layout (based on rectangles) that couldn't be done with GridBagLayout. You have total control over every position, size, gap, and inset, which with 7 components to place gives … | |
Re: s[] obviously is of size 0, so index 0 is out of bounds. Did you pass in any parameters when you ran this? |
The End.