• Post Reply Bookmark Topic Watch Topic
  • New Topic

Problems with Key Listeners  RSS feed

 
B. Schulz
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

I got a typical newbie Problem:

I got a class extending von JFrame which calls in a method start.

What happens there is the typical setSize and so on and: Pan pan = new Pan(); where Pan is a class that extends from JPanel and uses paintComponent.
The Panel has, among other things, a backgroundcolor Color.BLACK.
also, it implements KeyListener.

I added the KeyListener to my class extending JFrame, the Code being: this.addKeyListener(pan);
I wrote a Println into the keypressed-method which works fine, that is, whenever I press a Key I get a line of text.
However I also put in there "this.backgroundcoler = Color.Pink; this repaint();
The repaint doesn't seem to work, that is, while I get my textline evry time I press a key which shows me that the Listener actually works, the picture I Have on the monitor (i.e. the JFrame with the Panel) never seems to change.
Does anyone have any Idea what I am doing wrong here?

Thank you very much....I am sorry for the clumsy Englisch, it is not my native language.
 
sachin potu
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
try doing this.setBackGroudColur()
 
Campbell Ritchie
Sheriff
Posts: 53779
128
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And welcome to the Ranch
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!