oroszCapa Blaszczekievicz

Greenhorn
+ Follow
since Oct 11, 2019
Merit badge: grant badges
For More
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
10
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by oroszCapa Blaszczekievicz

Thanks everyone for the input!
4 years ago
Hey, guys!

A user enters months into text field using numbers, e.g. number 5 is entered, and it should be converted to String "May".
I used the following solution. I don't know, it doesn't feel right. Is there a better way?


4 years ago

Knute Snortum wrote:Would you like to post your solution back here, or tell us what you did?  There may be other people with similar problems that would want to know.



Ok, since I'm new to this, I kinda solved it intuitively, I can't even explain what I did, and why my first approach didn't work, so I hope someone could chip in and explain what happened there better than I'm going to do now.

Anyway, basically my understanding is, that when the table is created the selected col/row is 0 0 by default and that's when I call method setCellEnterAction, so basically the method is called once on creation of the table, so why would it be called every time I select a cell in a table during runtime? It won't, right?
So I have to prepare all cells to do smth when enter is pressed beforehand, before runtime.

Hence the nested for loop that I did and it worked like a charm.

for (int rows = 0; rows <= totalRows - 1; rows++ ){
     for (int cols = 0; cols <= totalCols -1; cols++){
         setCellEnterAction (cols, rows, ACTION);
 }
}

So now whichever cell I select, if I press Enter it does what I told it to do. Maybe someone could give me some tips on this whole mess, I'd really appreciate it.
Thank you!
4 years ago

Junilu Lacar wrote:Are those classes you wrote or did someone else write them?



Not me, third party library.
I figured it out, though. My approach was wrong altogether, issue closed.

Junilu, thanks for your help!
4 years ago

Junilu Lacar wrote:For a Column, isn't its equivalent int stored in the x field? Similarly for Row, I would think it's the y field. Do those fields have getters?



Actually, yes! There's a getX() / getY()

But they also return zeroes:(

I tried the following, but now there were no zeroes, nothing at all...

4 years ago
Hey, guys!

As a newbie in programming, nevermind Java, I got myself in yet another conundrum, *sigh*.

Ok, here we go.
I'm using a third party GUI library that, much like Swing, creates a table based off of a csv file.

Now I want to set and action for a selected cell when Enter is pressed. There's a method for that.



Now as you can see this method requires two arguments of type int, which are row and column numbers, so it knows which cell to set action to.
How do we get selected col/row? Well, there's a method for that, too!



Now you noticed that it does not return int, instead it returns Objects.
How do I get my col/row numbers, given the above?

There's a variable selectedColumn in that method, but it's private.

There's also a method that returns that variable, but I always get zeroes. Does it have to do something with the fact that variable is private?



Any ideas?

Here's the constructor for Column/Row




4 years ago

Carey Brown wrote:Most people hate this but I'm going to offer it up anyway because it works. Regular expressions and other lexars generate state machines behind the scenes, this one is just unrolled.



I think I got it to work (fingers crossed), now to the next stages of making this app happen. Stay tuned for more questions)))
4 years ago

Piet Souris wrote:In my reply I suggested to use a dedicated class to collect all the fields of a block, and I suggested to converse some strings of a block into more useful types. For instance, if, after splitting a block, we have the fields f1 = "Dec 17" and f2 = "2019 9:00:00 PM", then we can put these into a useful LocalDateTime, with a suitable DateTimeFormatter. I did not tell how that could be done, but here is a way

With this, we can get:



Looks interesting, thanks!
4 years ago
Hi, Knute! Really appreciate you taking the time to help me. Thanks a lot!

I've been reading,googling and thinking about this so much recently that what's inside my head is a mess right now, and I lost that fragile and delusive structure of knowledge I had on the subject)) I'm not even sure I understand now what OOP is all about.
Anyway.

> How would you go about doing this?

Well, first we split the string at "]" to get blocks. The so called 12 element "original line" from my latest post. Simultaneously we populate a String array.


Then we split it by commas adding the elements to a String ArrayList:


Finally we use ArrayList.removeIf to get rid of the quotes:


Now as to reconstructing the fields... this gives me nightmares, I don't think I'm ready for this yet.

I was thinking of something along the lines of:


Repeat for other blocks and do the same with the names.


Sorry for the sordid attempt))
4 years ago
Ok, I guess it's not the loop.
This is what I get right after all the split and remove functions.

[      ,  Jun 19, 2017 4:00:00 AM,       , M1145,       , LASTNAME,NAME MR,       , ZP6411,       , X,       , P-I10,       , FOUND\nPRESENT/NST/PL JT,       3,      , TWA,       ,       , 347637463,       458720485   ]

And the original line:

[      "Jun 19, 2017 4:00:00 AM",      "M1145",      "LASTNAME,NAME MR",      "ZP6411",      "X",      "P-I10",      "FOUND\nPRESENT/NST/PL JT",      3,      "TWA",      "COMMENTED",      "347637463",      458720485    ]

4 years ago

Ok, I think I need your help here))
I guess celebrations and patting myself on the back that was a bit premature))

The code I said was working, was actually tested with sample lines of data (you can see in the original post) and in an online java editor (JDOODLE). Now when I threw that code into the real world app and into the Eclipse, the real world app kicked me in the balls.

Here's the data received (already cleaned by cutting the first 12 characters and the last 172):

[      "Jun 19, 2017 4:00:00 AM",      "M1145",      "LASTNAME,NAME MR",      "ZP6411",      "X",      "P-I10",      "FOUND\nPRESENT/NST/PL JT",      3,      "TWA",      "COMMENTED",      "347637463",      458720485    ]

I call this a "block", it contains 12 elements. These "blocks" of 12 elements are gonna be included in the 2D string array[blocks][12]

Now this is what ended up in the array:

Jun 19, 2017 4:00:00 AM

M1145

LASTNAME,NAME MR

ZP6411

X

P-I10


Only half of the data is saved, and it looks like it saves a bunch of white spaces, instead of the payload. There must be something wrong with the nested loop that creates the 2D array. Could you please check the damn thing and see if it's correct? Thank you!
I added comments to the code, so the loop is easier to find.
[UPDATE]: It is probably a split and remove part that is not working correctly, please see the next post, thank you!



4 years ago
Thank you guys a lot for your input!

Here's my ugly code. The surprising thing is that it works.
I get clean entries in the ArrayList and in the end, using nested loops I get 2D string array, which is what I need exactly to feed it to the JTable in Swing. Hooray!

If you see something too ugly, which could be refactored, please do chip in!

4 years ago

Knute Snortum wrote:I'm not sure that's going to work properly.  There is an element

   "LASTNAME, FIRSTNAME"

that should be all one element and not be split by the comma.  I would look into using a CSV library like

http://commons.apache.org/proper/commons-csv/



Yeah, that one is easily fixed by changing   to
4 years ago
Oh, that's great. Thanks, man!

Now I have a string array that has n amount of blocks. What do you think is the best way to extract data within quotes " " from these blocks?

I tried doing this:



But the a mount of array items in arr[] is variable, and if I put this expression in a loop, to cycle through all the items in arr[], it isn't working.
4 years ago