Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (542)
Games in Android Showcase (133)
games submitted by our members
Games in WIP (605)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  [JFrame with TextFields error] [SOLVED]  (Read 1112 times)
0 Members and 1 Guest are viewing this topic.
Offline GabrielBailey74
« Posted 2012-12-30 00:02:44 »

SOLVED: I'm lame sorry guys:
1  
2  
3  
4  
5  
6  
7  
8  
   public void keyPressed(KeyEvent e) {
      int ID = e.getKeyCode();
      if (ID == 8) { /* Backspace Button */
         if (userNameField.getText().length() == 0) {
            e.consume();
         }
      }
   }


Hello JGO Shocked
I have a JFrame, it contains 2 JTextField's, and multiple JPanel's (JPanel's are painting constantly).

Whenever I have one of the TextField's selected, if I hit 'back space' it causes my JPanel's paint rate to significantly speed up?

Picture:


Note: While I hit backspace, this glitch only occurs while there's NO text in the field.

I could supply some source code, if need be.
(How I noticed this was that the physics of the spheres would speed up)

Offline matheus23

JGO Kernel


Medals: 116
Projects: 3


You think about my Avatar right now!


« Reply #1 - Posted 2012-12-30 16:17:53 »

I know you already solved this, but I suggest using the
KeyEvent
constants for better readability:
1  
2  
3  
4  
5  
6  
7  
8  
   public void keyPressed(KeyEvent e) {
      int ID = e.getKeyCode();
     if (ID == KeyEvent.VK_BACK_SPACE) { /* Backspace Button */
         if (userNameField.getText().length() == 0) {
            e.consume();
         }
      }
   }


KeyEvent.VK_BACK_SPACE
is exactly this in source code:
public static final int VK_BACK_SPACE = 8;
.

I guess you already know this... I'm just sayin, because it's better readable Smiley

See my:
    My development Blog:     | Or look at my RPG | Or simply my coding
http://matheusdev.tumblr.comRuins of Revenge  |      On Github
Offline GabrielBailey74
« Reply #2 - Posted 2012-12-30 22:31:57 »

Thanks, I know a couple java constants which I use alot, easier to just write the digit XD:
1  
2  
3  
3
vs:
JFrame.DEFAULT_CLOSE_OPERATION


This was and still is a rather interesting glitch though.
On a JTextField/JPasswordField/JTextArea, if while it's blank the user hits 'Backspace' or 'Del', it causes all the JPanels on the same JFrame to tweak out lol, compare it like a steady FPS rate of 2, which increases to 100 FPS.
Wierd Tongue

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline davedes
« Reply #3 - Posted 2012-12-30 22:46:56 »

Using magic numbers defeats the purpose of the constants in the first place; it makes your code harder to read and more difficult to debug, and also makes it much more error prone.

Instead you should use IDE auto-completion if you are getting tired of typing things out.

You will probably come to realize the importance as you begin to make more complex applications.

Offline GabrielBailey74
« Reply #4 - Posted 2012-12-31 05:12:55 »

Using magic numbers defeats the purpose of the constants in the first place; it makes your code harder to read and more difficult to debug, and also makes it much more error prone.

Instead you should use IDE auto-completion if you are getting tired of typing things out.

You will probably come to realize the importance as you begin to make more complex applications.
Lolz, I used IDE auto-completion to find out the actual variable value in the first place.
If I find out it's 'one' character long in length, why would I type 20+ characters?
I said I know a couple of constants lol, and I use them quite often, wouldn't type the longer version for somebody else s eyes.
I'm the only one browsing my code for the most part O.O

Offline BoBear2681

JGO Coder


Medals: 19



« Reply #5 - Posted 2012-12-31 06:46:56 »

Do you give your classes and methods single-character names as well?  It would make your code even more terse!
Offline matheus23

JGO Kernel


Medals: 116
Projects: 3


You think about my Avatar right now!


« Reply #6 - Posted 2012-12-31 16:00:32 »

Guys, keep cool.

If he wants to do it that way, let him just do it that way. You learn from mistakes.

See my:
    My development Blog:     | Or look at my RPG | Or simply my coding
http://matheusdev.tumblr.comRuins of Revenge  |      On Github
Offline GabrielBailey74
« Reply #7 - Posted 2012-12-31 22:02:01 »

Do you give your classes and methods single-character names as well?  It would make your code even more terse!

Would you type:
1  
ch.setLocalTranslation(settings.getWidth() / 2 - guiFont.getCharSet().getRenderedSize() / 3 * 2, settings.getHeight() / 2 + ch.getLineHeight() / 2, 0);


Or this:
1  
ch.setLocalTranslation(x, y, 0);


So yes noob, I do name 'variables' with 1 letter sometimes, maybe you should try it, stop criticizing lulz.
As for method names no rofl, how did it get to method names, starting from 'known' constants?

Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

Elsealabs (16 views)
2014-12-28 10:39:27

CopyableCougar4 (20 views)
2014-12-28 02:10:29

BurntPizza (25 views)
2014-12-27 22:38:51

Mr.CodeIt (15 views)
2014-12-27 04:03:04

TheDudeFromCI (20 views)
2014-12-27 02:14:49

Mr.CodeIt (26 views)
2014-12-23 03:34:11

rwatson462 (58 views)
2014-12-15 09:26:44

Mr.CodeIt (47 views)
2014-12-14 19:50:38

BurntPizza (96 views)
2014-12-09 22:41:13

BurntPizza (115 views)
2014-12-08 04:46:31
How do I start Java Game Development?
by gouessej
2014-12-27 19:41:21

Resources for WIP games
by kpars
2014-12-18 10:26:14

Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!