import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.Timer; import java.awt.event.ActionListener; import java.awt.event.ActionEvent; import java.awt.Color; import java.awt.event.KeyListener; import java.awt.event.KeyEvent; import java.awt.Point; class Program01 extends JFrame { JPanel panel; Timer timer; enum TDirection {left, right} TDirection direction = TDirection.left; Program01() { timer = new Timer (10, new ActionListener() { public void actionPerformed(ActionEvent e) { MehetIdozitoActionEvent(e); } }); addKeyListener(new KeyListener() { public void keyPressed(KeyEvent e) { OnKeyPressed(e); } public void keyReleased(KeyEvent e) {} public void keyTyped(KeyEvent e) {} }); panel = new JPanel(); panel.setBounds(10, 300, 100, 30); panel.setBackground(Color.green); add(panel); setLayout(null); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setSize(500, 400); setVisible(true); } private void MehetIdozitoActionEvent(ActionEvent e) { int x = panel.getX(); int y = panel.getY(); if(direction == TDirection.left) { if(x>0) x = x - 3; } else { int width = getWidth(); int a = width - panel.getWidth(); if(x