[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y ] [Search | Free Show | Home]

Any java programmers here? I'm getting some strange behavior

This is a blue board which means that it's for everybody (Safe For Work content only). If you see any adult content, please report it.

Thread replies: 15
Thread images: 3

File: java.jpg (107KB, 1280x768px) Image search: [Google]
java.jpg
107KB, 1280x768px
Any java programmers here? I'm getting some strange behavior in Netbeans. Here is the code that executes if any key is pressed (evt is the event):

jButton7.setBackground(c);
if (evt.getKeyCode() == 192)
{
System.out.print("I'm here");
jButton4.setBackground(c);
}

If I press any key, jButton7 turns blue. If I press the key with keyCode 192, "I'm here" is displayed on the monitor but jButton4 DOESN'T change color.

It's like the conditional statement is making setBackground() unable to execute.
>>
>>8427593
>>>/g/
Anyway, you can always place a breakpoint at that line and get into the function to see if they actually do what they do.
>>
File: 1449666876335.jpg (1MB, 1500x1000px) Image search: [Google]
1449666876335.jpg
1MB, 1500x1000px
Java has nothing to do with science/mathematics. It's not even used in scientific computation since it's so slow compared to C/C++. GTFO and never come back.
>>
>>8427599
Place a what where to get into which function to see if who does what?

Please explain. I'm a beginner to Java.
>>
>>8427593

stupid question, but is the button already blue? what colour are you expecting it to change to?
are you 100% sure jButton4 is referencing the thing you think it is?

it's hard to know any more without any extra context.
>>
>>8427619
Let me give you some more information.

-All the buttons are non-blue, and they're supposed to turn blue when pressed.

-This works:

>switch (evt.getKeyChar())
>{
>case '~': jButton4.setBackground(c);
>break;
>}

~ is keyCode 192, btw.

The problem is that I want the buttons to change color based on the key pressed, not the character.

Also, I just tried this:

if (evt.getKeyChar() == '~')
{
System.out.print("I'm here");
jButton4.setBackground(c);
}

and it works.
>>
>>8427593
>jButton7
>192
>jButton4
Learn to choose meaningful variable names.
>>
>>8427669
You should still be able to cast a char to a int value.

>>8428160
He probably let some editor do that for him
>>
>>8427593
>using netbeans
>not killing youself
>>
File: Jshit.jpg (210KB, 1024x768px) Image search: [Google]
Jshit.jpg
210KB, 1024x768px
>>8427608
Fuck off, java has nothing to do with /sci/
>>
>>8428160
>fourth button
>jButton4 isn't meaningful
>>
>>8427593
>java
>you actually have to memorize all those messy named functions
Jesus.
>>
>>8429083
>>you actually have to memorize all those messy named functions
>Wat is documentation
I program Swing all the time. I don't know a lot of the methods by heart. A lot of the IDE's, like Eclipse, have build in documentation and even suggests the methods you're trying to find.

>>8427669
>The problem is that I want the buttons to change color based on the key pressed, not the character.
Writing a piano/synth?

Also, haven't tested it (you should post a mcve). But I always refresh the widow when I do any changes to the GUI. You can put next method in any component and call it after a color change happens:

public void refreshWindow(){
JFrame frame = (JFrame) getRootPane().getParent();
frame.revalidate();
frame.repaint();
}
>>
>>8429083
>>you actually have to memorize all those messy named functions

You really don't. They are quite obvious. Consider for example, when you want to create beans that create beans that create only singletons. Well it would logically follow that if you just read those words in order, you would arrive at the AbstractSingletonProxyFactoryBean. It's a lot like phonetic spelling.
>>
>>8429075
good description: "subject field"
bad description: "third text field"
As a rule of thumb, if your variable names end with numbers, it should either be refactored into real names or an array/list.
Thread posts: 15
Thread images: 3


[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y] [Search | Top | Home]

I'm aware that Imgur.com will stop allowing adult images since 15th of May. I'm taking actions to backup as much data as possible.
Read more on this topic here - https://archived.moe/talk/thread/1694/


If you need a post removed click on it's [Report] button and follow the instruction.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com.
If you like this website please support us by donating with Bitcoins at 16mKtbZiwW52BLkibtCr8jUg2KVUMTxVQ5
All trademarks and copyrights on this page are owned by their respective parties.
Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
This is a 4chan archive - all of the content originated from that site.
This means that RandomArchive shows their content, archived.
If you need information for a Poster - contact them.