Marcus Hirschbine

Greenhorn
+ Follow
since Apr 15, 2015
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
2
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Marcus Hirschbine

Where I don't understand what goes wrong...



I am consistently getting a NullPointerException immediately following this code when attempting to assign these variables to a map.
I have already been debugging and observed that immediately after the declaration of the arrays, splNm and splDt, they are not containing what they should.

I thought this logic would yield...
(debugging example)
spl[0] == "gradient.top " (yes that whitespace is there... not that it matters)
spl[1] == "60, 60, 60;"

(after variables, splNm and splDT are declared with the .split() method called on the spl[0] and spl[1] elements... respectively assigned...)
splNm == {"gradient", "top"}
splDt == {"60", "60", "60"}

HOWEVER, following the declaration of splNm and splDt, literally at the next possible breakpoint in the code what we see is...

spl[0] == "gradient.top "
spl[1] == "60, 60, 60;" (as expected since we didn't make any changes here...)

splNm == {}
splDt == {""}

>insanity

Here is the rest of the block to give you a better idea of the problem area...



Edit: Also, I'm sorry about the variable names. They're just temporary local variables so I give them wacky names. (spl = split, splNm = split name, splDt = split data)
6 years ago

Rob Camick wrote:I'm not sure what you expect to see since the foreground color of the text is basically the same color as the gradient color.

Use the setForeground(...) and setCaretColor(...) methods to change the color of the text and caret so it contrasts with your gradient paint.



Yes, I ended up changing the foreground and I got the colors. I do not know why I went so damn long without realizing that.

I actually meant to post saying I had realized that I saw the text after changing the font color to white.

Thank you so much for your help, just got it working.
7 years ago

Rob Camick wrote:Take a look at your painting code.

First you invoke super.paintComponent(), which does the default painting of the text area which is to paint the background and then paint the text.

Then you do your gradient painting, which paints over top of the text.

So the order of the code should be:

1. do the gradient painting
2. super.paintComponent();

Now to prevent the default painting code from clearing the gradient background you need to use:



So now when you invoke super.paintComponent() the default background painting code will not be executed.



I made the changes to the code you had me make. I did but it did not resolve the issues regarding the text being painted over. I can see that the text area is there, when I move the cursor over the text area the cursor does change into the text cursor. But I still am not able to visibly see the carot when the text area is focused nor do I see the text. I'll provide a picture of the result of the changes I made in the code shown below.



7 years ago

Rob Camick wrote:The SSCCE code should be posted in forum just like your other code.

I would expected the code to be less than 50 lines since it only has a JFrame and a JTextArea with some simple custom gradient painting.



Oh, my bad.

7 years ago
Source and build of SSCCE:
build is in dist/

SSCCE:
https://www.dropbox.com/s/xdaw86w2xhrbjue/GradientSSCCE.rar?dl=0

*Necessarily elaborate commentate warning
7 years ago
Pseudo code warning.

I have a GUI for what is a sort of console for a series of apps I'm making.

The components that make up this SWING JForm include...

JPanel, which is centered on a Jframe. The JPanel's paintComponent method is overridden to include a gradient background.

(It's a modified gradient paint initialization as to be able to set custom colors read in from a text file for component colors).

The code is here:


The JPanel is added to the JFrame's contentPane() using BorderLayout's Center.
On the JPanel are components that include a JTextField and a JScrollPane.

They are arranged on the JPanel using GridBagLayout.

The JScrollPane has a JTextArea which is occupying the viewport.

You can find the rest of the initComponents() method here.


The problem is, how do I go about painting the backgrounds of the JTextArea and JTextField in the same manner that I did the JPanel while maintaining the visibility of text/foreground entities?

I have tried overriding the components' paintComponent() methods but the foreground entities (text, carot etc.) were not visible (or as I could imagine it, foreground entities were painted under the gradient background). How do I fix this?

Before overriding paintComponent().... (Text and carot is visible, I should note I only care about the carot in the JTextField as the JTextArea is not edible).


After overriding paintComponent().... (No text, no carot, no juice).


Quick edit: The scrollbar UI is not visible either after overriding.

Correction: The scrollbar UI is visible. Just didn't type enough to make it visible X$
7 years ago

Dave Tolls wrote:That code will occasionally fail.

It's a common mistake I've seen, but the while clause should be:


If you use the current '> 0' it is possible for the reader to pick up 0 bytes on a read (for example, something else is using the disk at the time). '0' does not mean EOF, -1 does.



Oh thanks for this, will be sure to make amends to the practice.

Also, thanks for the feed back. Helped clear up the assembled concept I had in my head for what was going on in the code.
I suppose it was mostly confirmation I was looking for but without a doubt I'll have to keep things like that FileChannel transfer methods in mind too when revising this code.
7 years ago


I would really like elaboration on what is going on in here because, though I understand the concept that is taking the data as bytes from the src file to a buffer that is X in size, (an array of bytes with 1024 elements in this case). So it pulls as much as it is allotted from the src, writes what it has, the len var is some sort of counter, once the end of the buffer is reached, it fetches the next segment of bytes, and repeats until it runs out of bytes to get from the src.

Is there a history to this method?

Any where I can get information or insight on to understanding the knowledge that this structure builds upon because it is honestly confusing me.
7 years ago
These two libraries I will be implementing into a text based game engine! (Since the primary focus is on these APIs, I decided to use the API board instead of the game development board.)

Specifically from the OpenNLP project, (Open Natural Language Processing), I am focused on the SentenceDetector (and related), as well as the Parser (and related).

Look, here in my constructor I have initiated these two tools with their, "Trainers" which give them the... 'brains' to do what they do in breaking down and recognizing natural language in english.



And now the reason I created this thread, is that an appropriate method for initializing these objects/tools?

Their purpose will be to analyze and parse various kinds of input from the user, to determine what the user is doing, because by text based,
I don't just mean choose your own adventure, I'm talking of implenting a full on complex control structure.

> Go west, grab that sword and swing at the orc with it.

The sentence detector would do it's thing to that, and tell me, "Yup, that is one sentence."

Next,

The parser will do some crazy %!#@ to it which I have a hard time describing, but it comes out looking like this...

Input: The quick brown fox jumps over the lazy dog .

Output: (TOP (NP (NP (DT The) (JJ quick) (JJ brown) (NN fox) (NNS jumps)) (PP (IN over) (NP (DT the)
(JJ lazy) (NN dog))) (. .)))

The tags and such generated I have yet to have memorized the glossary for, NN=Noun... and such...

The parenthesis is the framework too a tree mapping of the sentence structure I'm assuming but I have yet to visualize methods of applying this...

Anyways,

I am wondering if anyone is familiar with the libraries OpenNLP and the commons.lang from Apache.
And if one might be available to reply on this thread for the ongoing future to come because I will be working
heavily with these libraries implementing their interfaces into my engine.

OpenNLP

Commons

Edit: Turns out I scrapped the parser tool! All I needed were the other tools, POSTagger (Part-of-speech Tagger) and the tokenizer!

Process of using these tools:

1. Sentences are separated into different elements of an array as Strings.
2. Each sentence is tokenized and the tokenized sentences are stored into an ArrayList<String[]>. (Each String array, contained the tokenized sentences.)
3. Then the POSTagger iterates through the sentences' tokens, and generates an ArrayList<String[] of tags! (Each element to each array corresponds to the matching tokens from the sentences.)

The results yield:

Sentence: Crypto_PRP ,_, please_VB execute_VB command_NN zero_NN ._.
> Crypto, please execute command zero.

7 years ago
This is what I've got now:



From my tests it works, but perhaps there is a better method/optomizing? Thank you Clapman for those citations.

Ritchie, as for the action listener, what would be the advantages? I haven't had any problems with the key listener thus far to say the least.
7 years ago
So this is the set up to my GUI...



Simply, a JTextArea inside a JScrollPanel, The JScrollPanel @ BorderLayout.CENTER
with a JTextField @ BorderLayout.SOUTH

I'm making a text engine so...

1. Collect input from textField object.
2. Process input, build output
3. Print output to textArea object
4. Print input to textArea object
5. ???
6. Profit!

Anyways.

Here is the current problem I am tasked with.



From the listener upon enter press in the textField, the input if !empty is sent (in the future to processing beforehand) to the enlister which from there is sent to be printed in this method.



Now I know this won't work because the thread will get held up and I won't have the text printed until other tasks are finished.

I need to be able to do other things while text should be printed to the textArea, how do I go about this?

the .append() method is fantastic, but unfortunately I do not know how to make it so I can split off with another thread so it can finish itself up on its own
without having to wait on the thread to come back around to it because it results in my GUI locking up.
7 years ago