iam not getting what is the mistake in the following code. i know i am missing a concept smewhere. i am adding a panel in a frame and adding a keylistener to that panel, but whenever i presses the key the key events are not delievered to the panel, i dont know why?
public class Testing extends JPanel implements KeyListener{
public testing(){ setSize(800,600); setLayout(null); addKeyListener(this); }
public void keyReleased(KeyEvent e) { System.out.println("hi"); }
public void keyTyped(KeyEvent e) {} }
the keyevents if generated are not handled by this listener. --------------------------------------------------------------------- -------------------------------------------------------------------------- if i change the code slightly it works----------- if instead of adding the keylistener to panel i add it to jframe it works.
public class testing extends JPanel implements KeyListener{
public testing(){ this.setSize(800,600); this.setLayout(null); }
public void keyReleased(KeyEvent e) { System.out.println("hi"); }
public void keyTyped(KeyEvent e) {} } ------------------------------------------------------ i was setting focus when it wasn't set and it was not wrking. ur code really wrks, it may b a bug in java code.
thanks 4 dat 2, i was actually in a hurry at that time and missed that. thanks once again. can u plz tell me how do draw lines of variable widths as v can draw in vb and vc
by default the drawLine(x1,y1,x2,y2) method draws line of 1 pixel width, but i want to draw lines that r more thicker then 1 pixel.
Sorry, I am not a Java GUI guy. I manage to help you with the previous question with few google searches and Java API. I hope someone else will answer that question.