How do I change the background color of a frame in Java from another class?

Public DirectionPanel(){ addKeyListener(new DirectionListener()); setFocusable(true);// INSERT THIS setBackground(Color. Yellow); } JPanel needs to be focusable to receive KeyEvents.

Reference: forums.sun. Com/thread. Jspa?

ThreadID=5424784. (I was just about to answer the same thing. ) – Michael Myers?

Feb 5 '10 at 18:23 Thanks for the reference.. – Erkan Haspulat Feb 5 '10 at 18:25.

Swing components should use Key Bindings (not KeyListeners) for invoking an Action when the keyboard is used. A side benefit of this is that way you don't have to worry about focusability. Action left = new AbstractAction() { public void actionPerformed(ActionEvent e) { System.out.

Println( "Left" ); } }; Object key1 = "left"; KeyStroke ks1 = KeyStroke. GetKeyStroke(KeyEvent. VK_LEFT, 0); panel.

GetInputMap(JPanel. WHEN_ANCESTOR_OF_FOCUSED_COMPONENT). Put(ks1, key1); panel.getActionMap().

Put(key1, left).

I also had it with no keycode test thinking that no matter the key it would work but it did not.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions