Results 21 to 30 of 30
Thread: Add keys to arraylist
- 07-19-2010, 06:32 PM #21
How were you able to write such a large, complicated program and then give up?
You need to know how to debug the code. One way is by adding println() statements that show you where the execution goes and what values variables have at each point.
You MUST have some ideas about where the execution should go and how variables change as you go thru the code.
By printing out the trace you should be able to see where the program doesn't do what you want it to do. Then you need to look at that code and see why it does what it does.
- 07-19-2010, 06:47 PM #22
- 07-19-2010, 07:11 PM #23should work fine
Your code is too big for anyone to easily explain to you how to pass references from one method to another.
In one method you are collecting data. When you get all the data you need for the paint() method to show, then call repaint() and have the system call your paint method which should have the data that was collected and be able to draw it.
- 07-20-2010, 01:21 PM #24
Ok, for some reason, the username is nothing in the drawPaint method.
I am trying to do this:
Java Code:g.drawString("" + app.username2, 273, 221);
and variable should get changed here.Java Code:sb.append(ke.getKeyChar()); gamePanel.repaint(); sM("Username in runApp is " + sb.toString()); username2 = sb.toString(); sM("Username2 in runApp is " + username2); gamePanel.repaint();
Last edited by PhQ; 07-20-2010 at 01:25 PM.
- 07-20-2010, 01:51 PM #25
Trace thru the program to see when username is set to a value and when you try to draw it on the screen. You have to set it before you can draw it.
One way to Do the tracing by putting println()s at where its set and where its used.
- 07-20-2010, 01:55 PM #26
sM() <- is same as println()
Java Code:public void sM(String s){ System.out.println(s); }
Username in runApp is a
Username2 in runApp is a
Loading game panel..
Username2 in drawLogin
drawLogin has been called.
should be
Username2 in drawLogin a
- 07-20-2010, 02:23 PM #27
For a bit more clarity in the printout of the contents of a string, surround it with delimiters. Something like:
println(".... >" + theString + "<");
So where is username being cleared?
In runApp it is "a"
In drawLogin its "" (empty)
A problem could be that there is more than one copy of an object floating around. You set the value of username in one and then call the other one to draw it. The other one still has the empty value.
Put a println() in the constructor for the class holding username to see if you have more than one.
To see who is creating the extra copy add the following:
try{throw new Exception("Who called?");}catch(Exception x){x.printStackTrace();};
You'll get a stack trace for every call.
- 07-20-2010, 02:27 PM #28
- 07-20-2010, 02:34 PM #29Is it possible to add a JTextField to the paint
A JTextField is a component that is added to a container. It has a lot of logic behind it.
The paint method uses a Graphics object to draw on a graphics context.
- 07-20-2010, 02:37 PM #30
Similar Threads
-
foreign keys in jtable gui
By blackpearlmoni in forum New To JavaReplies: 0Last Post: 10-31-2009, 05:52 PM -
Getting all the keys for a specific value from a multimap??
By Ms.Ranjan in forum New To JavaReplies: 0Last Post: 05-13-2009, 04:55 PM -
auto generated keys
By abhi_iips in forum New To JavaReplies: 3Last Post: 03-13-2009, 08:14 AM -
Media Keys
By tikigod in forum New To JavaReplies: 0Last Post: 01-29-2009, 12:30 AM -
Java Project Trouble: Searching one ArrayList with another ArrayList
By BC2210 in forum New To JavaReplies: 2Last Post: 04-21-2008, 12:43 PM
Bookmarks