7,116 Posted Topics
Re: You are going to need 26 of some kind of 2-dimensional array that shows where to print the As in in large block of As, the B's in a large block of Bs etc. | |
Re: Before you get carried away with more advanced apps, there's a lot more you can learn from this one. eg * use a proper layout manager (eg GridLayout) rather than the un-portable null layout * replace all those repeated variables and repeated blocks of code with an array of JButtons … | |
Re: Hi kluonius. Welcome to DaniWeb. Did you notice this thread is 4 years old? It's unlikely the original poster is still waiting for an answer! ps stultuke's answer above is the right one. | |
Re: If you define a Food class, and create an instance of that class then you have an object no different from a String or an Integer in terms of how you can access or pass it to/from a method. It's just like bguild says, just imagine how you would do … | |
Re: You need to start a Timer with a delay of 10 secsonds. When that time is up the Timer will run a method that you provide, eg to send the next question. If the user answers in time, just cancel the Timer. Here's a simple intro: http://enos.itcollege.ee/~jpoial/docs/tutorial/essential/threads/timer.html | |
Re: Sorry, I don't have time to study all your code now, but I'll bet 100:1 that it's a problem with keyboard focus. Youy add the key listener to your canvas, but that probably does not have the keyboard focus, so it doesn't get any keyboard events. KeyListener is pretty much … | |
Re: DId you try Liuqahs15's suggestion? It looked perfectly sensible to me... ps: Liuqahs15: Nice post. And yes, Java has enums just like that. | |
Re: > finds the rows and columns with the most 1s. It's asking you to Look at each row of the matrix, count the number of 1's in each row, find the row (or rows) with the most 1's (in this case row 2, with 3 1's compared to 2 1's … | |
Re: public class WordMeaningNode { WordMeaning word; WordMeaning next; You are getting confused between WordMeaning and WordMeaningNode. A WordMeaning is some info about a word, a WordMeaningNode is an entry in linked list (that happens to include a WordMeaning as its data). So in the code above, one of those two … | |
Re: root.left.code = root.code + "0"; public Node code; the variable *code* is of type Node, and you try to concatenate a String with it! Maybe the variable *code* should not be a Node? | |
Re: The more descriptive it is, the easier it is for someone else to understand. In a real-worldenvironment this the most important consideration. | |
| |
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: http://www.oracle.com/technetwork/java/javase/downloads/index.html | |
Re: You are mixing AWT components and Swing components - this is a formula for confusion and errors. Unless you have some very special reason you should always use Swing components rather than AWT. The swing components have names that begin with a J (JFrame, JButton etc). The ones without the … | |
Re: Hi game06. Beware incorrect Java terminiology that makes it really hard to understand your questions. A *class* is something you define in your source code. The *new* keyword creates an *instance* , not a class. Many of your uses of *class* above should be *instance* (I think). You would say … | |
Re: Two quick points: 1. Date.getHours etc have been deprecated since Java 1.1 (in 1997!) You should use GregorianCalendar instead 2. For updating a GUI you should use a javax.swing.Timer to run your updates on the swing thread, not a java.util.Timer which runs in its own thread. | |
Re: > so what's that year % 4 == 0 about? the above if should only say if( year % 400 == 0 && year % 100 != 0 ) ) because if these 2 conditions are satisfied then the year is leap year > Or am I getting it wrong? … | |
Re: " is not working right " tells us nothing. If you have a compiler or runtime error message post the complete message plus the actual code it refers to. If your code is giving an incorrect result explain what result you get and what the correct result should be. | |
Re: You should not have to change the logic classes - that's why we separate logic from user interface in the first place. Obviously you will need new listeners, but they should call the same methods that the mouse listeners call | |
Re: Scanners are just a simple fix for easy input, if you try to use them for formatted data you run out of steam really quickly. Here you have a scanner delimiting on blanks (default behaviour), but you want to keep month and day together. You will find this easier if … | |
Re: Do you inherit x, y, dx, dy from the Item class? If so you can just set dx in the default constructor for Bullet. You haven't given enough info for a proper answer, but my instinct is that if you have two similar items then you should create two instances … | |
Re: [QUOTE=stultuske;1767081]you can run each (desktop) or command line java application, by running ... javac yourClass[/QUOTE] Are you sure? java or javaw work better in this reality :) | |
Re: Short version: A JPanel is a container that you can add to a JFrame to help organise and lay out fields and buttons. In your code 1. You have two JFrames and that's confusing you. CelsiusConverterCoded extends JFrame, so your new CelsiusConverterCoded() is a JFrame, but then you create another … | |
Re: Depends on the methods - do you mean different methods for one map (in which case see IIM's post), or that there are multiple maps each with its own implementation of the same method signature (in which case build a java.util.Map<String, Maps> to hold the name as key and a … | |
Re: Why not just create an empty ArrayList<Integer> before entering that loop, then inside the loop just add each parsed int value to that ArrayList? Then you will have an arraylist with all the values, where you can do whatever processing or calculations you want. | |
Re: Depending on how many things vary from level to level it may make sense to have a Level class with 4 instances, each instance having its own values for all counter etc etc. | |
Re: Do you really mean "translate"? - in which case see stultuske's post Or do you mean "transliterate" - replace each letter by it's nearest cyrillic equivalent regardless of meaning, in which case you could use something like this pseudo-code: for each letter in the original string find that letter in … | |
Re: Your methods are all static, and static methods cannot access instance variables without an instance. Your simplest fix is just to leave clientList where it is, but declare it as static so all the methods can access it. (There are all kinds of reasons why Java programs are usually not … | |
Re: "Whenever I try to run this nothing happens. " Wrong. It throws an exception which you cannot ignore. > Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 3 > at Hobbits.main(Hobbits.java:8) h is an array of size 3, so valid index values are 0,1,2 On line 8 you try to access index 3 | |
Re: > should i try putting in some System.out.println(""); codes in the methods to see where it is not working from? Yes, absolutely yes. That's always a good thing to do right from the start. | |
Re: This looks relevent: http://www.rgagnon.com/javadetails/java-0598.html (especially the first example) | |
Re: public Boolean isFull() { if( isFull()) { ... When you call isFull(), on its first line it calls isFull(), which, on its first line calls isFull(), which, on its first line calls isFull(), which, on its first line calls isFull(), which, on its first line calls isFull()... | |
Re: Neither. Stick to a programmer's editor and the commmand line compiler until you have a good feel for Java and what's going on. An IDE is just going to add confusion and learning curve to a situation that already has a lot of confusion and learning curve. Then move to … | |
Re: There's no easy way to move the actual JButtons in a grid. What you can do is to keep a track of the x,y coordinates of the player (etc) so you can change the text or icon of the appropriate JButton as the player moves. In pseudo code, for example … | |
Re: Static initialisers are OK, but in radhakrishna.p's example watch out for the scope of arr! You can also use an instance initialiser http://docs.oracle.com/javase/tutorial/java/javaOO/initial.html which (to answer stultiske's question) save having to duplicate code between multiple constructors, and can be used in anonymous inner classes. | |
Re: If you want your "functional" buttons to do something you should add an action listener to them ;) | |
Re: "more random"? I don't know what that means. If your code is intended to enter the if block half the time at random, just use `if (ran.nextBoolean())` ... which is as random as Sun's mathematicians know how to make it. | |
Re: Within a single thread statements will be executed in the correct order. Between two different threads there are no guaarantees unless you explicitly synchronise. | |
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: current_node is an instance variable. It has one value (maybe null) for each instance of the class. You cannot use it without an instance. Your main method is static - it executes without an instance of the class - so you can't use current_node unless you specify explicity an instance … | |
Re: No, sorry radhakrishna.p, that explanation is not right. The problem is that the parameter and the newCheckBox variable are local to the makeCheckBox method. As soon as that method finishes both those variables are discarded. Some time later the ItemListener is called, which tries to use those variables, but they … | |
Re: "Urgent" means "I left this too late"? 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 … | |
Re: You get a null pointer because you have not initialised the variable *socket*. You seem to be missing the call to create a DatagramSocket and *connect* that to the server. | |
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: Hi, welcome to DaniWeb. The way it works here is that people post their problems/questions and other people then reply and try to help. If you see a problem posted and you know the answer then please post a reply. You may also want to review the [DaniWeb rules](http://www.daniweb.com/community/rules) - … | |
Re: Scanner is "A simple text scanner", you can't use it to parse a binary file. Have a look at DataInputStream which reads binary data - although you may need to write a bit of code to handle text that's encoded as zero delimited bytes | |
Re: With all those == tests you are testing for exactly just touching, but depending on dx, dy, and the whole history of the movement an exact touch may be unlikely. (If any of the variables is floating pint an == is even more unlikely.) You coud try using >= or … | |
Re: jignam: 1. Don't hijack other people's posts. Start your own for your won question. 2. 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 Create a new thread, post … | |
Re: 6: Animal c = new Animal(); // creates a new Animal (1) 13: Animal e = new Animal(); // part of initialisation of Animal (1) - creates another new Animal (2) 13: Animal e = new Animal(); // part of initialisation of Animal (2) - creates another new Animal (3) … |
The End.