Logan Wilson

Greenhorn
+ Follow
since Sep 21, 2012
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
6
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
(keep public parts private until JForum day)
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt
Moderation Tools

Recent posts by Logan Wilson

Paul Clapham wrote:Okay. I'm looking at that readList() method. Apparently that's supposed to be there for the purpose of reading from a text file and adding the lines from it into a list. As I already said, if it were me I would just skip the whole list business and create the JButtons right there. But at any rate that's all moot because you aren't actually calling that method anywhere.



Got it! Thanks!!



I had to over complicate it. Now, to get the massive list of red compiler errors to disappear while pushing them. :)
5 years ago

Paul Clapham wrote:
What elements? My problem here is that I don't know what you mean by an "element".



Sorry, by element, I meant just the String name that's in all my nodes.

My guess is that all you have to do is to get a String out of your list and assign it to the JButton using its setText() method, but the whole thing seems like an excessively complicated way of doing something which should be quite simple.



Your guess is absolutely correct, I just have to get the String out of the list and populate the list of buttons. It was super easy with Arrays, I just had to do an insertion sort and then repopulate the list. This has quickly turned into an exercise in frustration for me. You're absolutely correct with how this is more complicated than it seems. Hell, it's probably me making it more complicated.

I built all these different methods where it worked reading the file and printing out the results to the console, but I tried importing my methods into the SwingGui. I'm wondering if something got lost along the way, and the file isn't getting read and populated.

One of the things I tried was a JButton.setText(node.readList), but I'm wondering if I should alter the code to only read and output one line at a time? Since it appears to be trying to load all the Strings into an i-th location.
5 years ago

Paul Clapham wrote:But you don't even have any code there (in the first fragment) which tries to get data out of the nodes you created in the second fragment.

So is that your question? What code you should write to get data?

If you have a ProbNode object, then you just call its getName() method to get the string which was stored in the node. Are you asking how to get one of those? My guess would be that you have a ProbMgr object handy somewhere, and you can get the nodes from that. But that's just a guess, though. I don't know what this list is for or why you are using it. If it were me I would just read the text file and generate the buttons from that, rather than mess about with an intermediate step where you stash the data somewhere and then read it back.



There's no code in that first section because I got extremely frustrated and deleted all the stuff that didn't work for me. I have a getName() method in my Node class that just returns the String name. I also have a method in my manager class to try and find the value and assign it to an array, the getName():



I'm lost trying to figure out how to place the String value in the JButton. Eclipse keeps warning me I have invalid type comparing them if I try to directly place the Node.name element, or even the Node.name.toString(), in there. I've tried multiple ways to fit a square peg into a round hole.

My question is: Is there a way to directly place those elements into the JButton, or should I assign my link list node Strings into an array, and then just repopulate the buttons with the array?
5 years ago

Paul Clapham wrote:Well, there's a lot of code there. And all we know is that somewhere in that code, you have a null value appearing somehow and you don't think that should be happening. So could you be a little bit more specific about just where in that code you see the null value appearing?



Shoot, sorry! I'm having the difficulty in this section.


and here:


I'm trying to get the value (String name) out of my node and populating into the JButton. But, I haven't been able to figure out how to get and set those values. :(
5 years ago
Here's the link to my updated code with the new difficulty. (always something, right?)

I'm still reading in a file, but it's just "A, B, C" stuff.

http://www.coderanch.com/t/594894/GUI/java/do-JButton-string-linkedlist-value#2712120
5 years ago
I've been working separately on methods to move nodes around in a linkedlist, and I've got that part all figured out. BUT, now that I've started incorporating all my code into my GUI, I'm lost trying to populate my JButtons with the String values from my linked list nodes. I'm winding up with nulls in their spot. Any idea what I could do?

5 years ago
you guys are awesome!

I've got the moves all figured out now, and it's working well. The only part I'm stumbling over now, is trying to figure out how to get the string values from my linked list nodes onto a JButton. I keep getting my list populated with 20 null string values.
5 years ago

Campbell Ritchie wrote:Is it a singly‑linked list? Sorry, I thought it was doubly‑linked. If it is singly‑linked, then you do not have the previous fields, nor do you have the tail reference. Only a head reference.
Advantage: you can reduce the number of steps in adding, removal, etc.
Disadvantage. You can only find nodes by going forwards from the head node (No 0) or the “current” node. I still think moving a node is better done by a combination of removal and adding. To move the No 14 node to position 10 when your “current” node is No 12:

  • 1: Go forward 2 nodes to No 14.
  • 2: Record that node temporarily.
  • 3: Reset the “current” node back to the head node No 0.
  • 4: Move 9 places to No 9.
  • 5: Insert the previous No 14 node after No 9.
  • You can see that finding a value in the List requires linear time, whereas finding a value in an array‑based List would take constant time (i.e. much faster).



    Well, after further playing around, I'm getting closer. I'm loosing my temp node address variable though, and it keeps getting deleted. Somehow, I'm screwing around and not capturing it like I thought. I'm betting, it's a multi-step process instead of keeping it simple like I tried. I tried enclosing all my calls into brackets under my for loop, but it either forced a recursion or it deleted every 2 element on the list.

    Ahh....oh well, I can at least look positively on this whole thing. I'm really learning a ton about this stuff.
    5 years ago

    Jeff Verdegan wrote:

    In the OP he mentioned that is was a singly-linked list. If that changed, my bad for not noticing.



    No, it's stayed the same. I'm still struggling trying to figure out the mechanics. I'm becoming well aware of null-pointer exceptions, which is driving me batty also. I'm going to keep diagramming it and changing my coding as I go along.

    Best part is, the only thing that gets hurt is 1's and 0's, right?
    5 years ago
    well, I've got the idea diagrammed out on paper and it makes perfect sense on how I can talk it through with pseudo code, but I'm just not getting it to pull out and reinsert a link at a specified point. I did like you said Campbell, and stripped all if it down to just a set of links with just some String names in it. Now, I've tried setting it up with two positions, (say 7 and 5). I want to grab the linklist at position 7 and move it into position 5. I figured, it's going to be a for list to count down to the position 6, grab the next address for position 7, assign that address to a tempNode, connect position 6 to position 8, and reassign my tempNode to position 5.

    To assign it to position 5, I'm using a for list again to look for position 4, assigning the tempNode to the .next address of position 4, assign the tempNode.next address to the current.next.next address (to connect tempNode to position 6). But, I'm either removing ALL the elements except the last 4 positions, OR I've been stuck in a loop printing out the elements being switched.

    arrg.....I'm betting it has something to do with improperly assigning that "to" tempNode I'm using. Any more pointers?
    5 years ago

    Jeff Verdegan wrote:
    I don't do Swing, so I don't know if it makes sense to store a list of buttons. However, when you are ready to actually use a list "for real" (rather than just writing one for the educational exercise, which is a worthwhile task in its own right), be aware that the core API includes java.util.LinkedList and java.util.ArrayList. You'll want to use those rather than rolling your own, unless you need special functionality that they don't offer.



    It's not that I'm needing a special function, it's that we're being made to shy away from the pre-built classes and work on creating our own models.
    5 years ago
    Thanks, Winston. I'm really discovering it's a pain in the butt to try all that stuff. I did mean the element "num" on each one, and it is more trouble then it's worth.

    Campbell, it makes sense what you were saying. I started making things work, and then I kept piling more and more stuff on top.

    It's ok, I'm studying up on doubly linked lists, and it's making a lot more sense on how to shift things around. I'm guessing once I get the foundations of that set, then it's just a matter of mapping JButtons to the list and refreshing them everytime I want to visually shift things around.

    Thanks for all the pointers!
    5 years ago
    I'm trying to figure out where my logic is screwy on this. I've been playing around with examples, and I'm trying to traverse a self-made linkedlist, remove an element of my choosing, and reinsert it at the point of my choice. So far, I can't figure out how to move something from the head towards the tail (not using a double linked list) or how to keep my element count correct.

    my linklist node constructor is pretty basic:



    This is my main method/driver program: it's where all my trouble is.



    This is my manager method:


    This is what my current output looks like right now.

    10: J
    9: II
    8: HHH
    7: GGGG
    6: FFFFF
    5: EEEEE
    4: DDDD
    3: CCC
    2: BB
    1: A
    -------------------
    looking at
    8: HHH
    skipping
    7: GGGG
    -------------------
    4: GGGG
    10: J
    9: II
    8: HHH
    6: FFFFF
    5: EEEEE
    4: DDDD
    3: CCC
    2: BB
    1: A
    -------------------
    looking at
    8: HHH
    skipping
    6: FFFFF
    -------------------
    4: GGGG
    8: FFFFF
    10: J
    9: II
    8: HHH
    5: EEEEE
    4: DDDD
    3: CCC
    2: BB
    1: A

    Any pointers on which way to take it? I'm thinking there's a better way instead of referencing my "i" index variable, but I'm still not sure how to keep the elements properly numbered. It's my goal to eventually reference these link list nodes and populate a gui JButton array with the contents.
    5 years ago
    Ok, I've worked on it a bit more, but I'm still having trouble wrapping my head around how to make the elements in the buttons shift. For instance, if I click on radio button 1, then click on 8, the text in button 1 should move to button 8, and the other elements shift up. Any more suggestions? I really feel like I'm nearly there, but I've put myself in a rut.



    Thanks for all the pointers and help!!
    5 years ago

    Tony Docherty wrote:Can you show the code you were trying to use






    My classmate advised I should use a set text on the separate string names to repopulate the buttons with switches, and IT will automatically refresh the buttons.
    (do the work in a method off to the set.) But, I'm not figuring that part out...I'm hung up somewhere.
    5 years ago