I'm starting to learn Java.
Example: you need a picture (circle) to reach the border of the window and come back. One way I did it, the other way I do not know how to return it.
The code itself:
import java.awt.*; import java.awt.event.*; import java.io.*; import javax.imageio.*; import javax.swing.*; public class Proj { public static void main(String[] args) { myFrame o = new myFrame(); } } class myFrame extends JFrame{ public myFrame() { myPanel p =new myPanel(); Container c = getContentPane(); c.add(p); setBounds(0,0,800,600); setVisible(true); } } class myPanel extends JPanel { private Image img; private int x=0, y=0; private Timer t1,t2; public myPanel() { t1= new Timer(5, new ActionListener() { public void actionPerformed (ActionEvent e) { x++; repaint(); } }); t1.start(); try { img = ImageIO.read(new File("./cir.png")); } catch(IOException exp) { JOptionPane.showMessageDialog(null, "Error!"); } t2 =new Timer(10, new ActionListener() { public void actionPerformed (ActionEvent e) { if((x+img.getWidth(null))>=790) { t1.stop(); } } }); } public void paintComponent (Graphics g) { super.paintComponent(g); g.drawImage(img, x, y,50,50,null); } }