Results 1 to 3 of 3
- 08-12-2010, 06:07 AM #1
keyListener how to modify object which called it?
Hi im using keylistener for my buttons but i cant work out how to determin inside the keylistener, which button is being called.
because once i know which button is being called i wish to change its background.
PHP Code:for (int i=0; i < colorShow.length;i++){ colorShow[i] = new JButton(); colorShow[i].setPreferredSize(new Dimension(20,20)); colorShow[i].setBorder(BorderFactory.createLineBorder(Color.black)); colorShow[i].addKeyListener(this); dataPanel.add(colorShow[i]); }
PHP Code:@Override public void keyPressed( KeyEvent e ) {} @Override public void keyReleased( KeyEvent e ) { } @Override public void keyTyped( KeyEvent e ) { //code here to change background when any key is pressed }Teaching myself java so that i can eventually join the industry! Started in June 2010
- 08-12-2010, 06:23 AM #2
figured it out
e.getComponent().setBackground(Color.red);Teaching myself java so that i can eventually join the industry! Started in June 2010
- 08-12-2010, 07:30 AM #3
Senior Member
- Join Date
- Apr 2010
- Location
- Philippines
- Posts
- 580
- Rep Power
- 4
Similar Threads
-
How do I modify the values in an object array?
By ConMan in forum New To JavaReplies: 1Last Post: 06-02-2010, 11:26 PM -
Help Using KeyListener to Move an Object
By jjonesmu in forum New To JavaReplies: 3Last Post: 04-20-2010, 10:35 PM -
KeyListener - Is this what I need?
By dbashby in forum New To JavaReplies: 26Last Post: 04-18-2009, 04:14 PM -
Does anyone know how this Swing Object is called ? Image inside
By hannehomuth in forum Advanced JavaReplies: 1Last Post: 07-26-2008, 05:26 PM -
how to add a KeyListener
By leonard in forum New To JavaReplies: 1Last Post: 08-06-2007, 04:44 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks