Popular Posts

Java Move JPanel Inside The JForm

Share it:

How To Move Object Around The Form In Java 

move object inside the jframe in java

In This Java Tutorial  We Will See How To Move JPanel UP, RIGHT, DOWN, LEFT In The Form By Pressing Arrow Keys Using Java Programming Language And NetBeans Editor.


Project Source Code:

private void formKeyPressed(java.awt.event.KeyEvent evt) {                                
        
        int key = evt.getKeyCode();
        
        switch(key)
        {
            case KeyEvent.VK_UP:
                jPanel1.setLocation(jPanel1.getLocation().x, jPanel1.getLocation().y - 5);
                break;
                
                case KeyEvent.VK_DOWN:
                jPanel1.setLocation(jPanel1.getLocation().x, jPanel1.getLocation().y + 5);
                break;
                
                case KeyEvent.VK_RIGHT:
                jPanel1.setLocation(jPanel1.getLocation().x + 5, jPanel1.getLocation().y);
                break;
                
                case KeyEvent.VK_LEFT:
                jPanel1.setLocation(jPanel1.getLocation().x - 5, jPanel1.getLocation().y);
                break;
        }
        
    }
      
///////////////OUTPUT:


moving jpanel in the frame using java




Share it:

java

Java Move JPanel Inside The JForm

JFrame

jpanel

moving object in the jframe using java

Post A Comment:

0 comments: