title: Draw objects on a loaded image in java
body: <p>I need help with loading an image of a map and drawing a point on the received location.
  Here is the code of the server:</p>
  
  <pre><code>import java.awt.Dimension;
  import java.io.IOException;
  import java.net.DatagramPacket;
  import java.net.DatagramSocket;
  import javax.swing.JFrame;
  import javax.swing.SwingUtilities;
  
  public class Server extends JFrame{
  
      private  static int PACKETSIZE = 100 ;
      private static  int WIDTH = 1340;
      private static  int HEIGHT = 613;
      public DatagramSocket socket;
      public DrawPoint drawPoint;
  
      public Server()  {
  
          setDefaultCloseOperation(EXIT_ON_CLOSE);
          drawPoint = new DrawPoint();
          drawPoint.setPreferredSize(new Dimension(WIDTH, HEIGHT));
          add(drawPoint);
          pack();
          setVisible(true);
      }
  
      //This method converts the lat,lon coordinates to the coordinates of the pixels in the image of the map (which is 1319 by 664)
  
      public String GPStoCoord( double lat,  double lon){
  
           double latref = 30.631103;
           double lonref = -96.358981;
           double yref = 0.015128;
           double xref = 0.035589;
           int coordx = (int)((latref - lat)/yref*1319);
           int coordy = (int)((lon - lonref)/xref*664);
  
          return coordx + "," +coordy;
      }
  
      private void GPSlocdraw() {
          try {
               DatagramPacket packet_GPS1 = new DatagramPacket(new byte[PACKETSIZE], PACKETSIZE);
              socket.receive(packet_GPS1);
               String sGPS1 = new String(packet_GPS1.getData());
               String latlonGPS1[] = sGPS1.split(",", 2);
               double lat1 = Double.parseDouble(latlonGPS1[0]);
               double lon1 = Double.parseDouble(latlonGPS1[1]);
  
              //converting the GPS data to coordinates
               String coord = GPStoCoord(lat1,lon1);
               String latlon[] = coord.split(",");
               int lat = Integer.parseInt(latlon[0]);
               int lon = Integer.parseInt(latlon[1]);
  
              drawPoint.setCoordx(lat);
              drawPoint.setCoordy(lon);
              drawPoint.repaint();
          } catch( IOException e){}
      }
  
      public static void main(  String args[] ) {
  
          SwingUtilities.invokeLater(() -&gt;    new Server().GPSlocdraw());
      }
  }
  </code></pre>
  
  <p>Here is the code to the DRawPoint class, where I am trying to draw the image loaded and draw the oval graphic on top of it by it seems that whichever is drawn last erases the other.</p>
  
  <pre><code>import java.awt.Color;
  import java.awt.Graphics;
  import java.awt.image.BufferedImage;
  import java.io.File;
  import java.io.IOException;
  import javax.imageio.ImageIO;
  import javax.swing.JPanel;
  
  public class DrawPoint extends JPanel {
      private int coordx, coordy;
  
      @Override
      public void paintComponent( Graphics g){
          try {
              BufferedImage map = ImageIO.read(new File("CSmap.png"));
  
              super.paintComponent(g);
              g.setColor(Color.BLACK);
              g.fillOval(coordx,coordy,8,8);
              g.drawImage(map,0,0,this);
  
          } catch(IOException e){}
      }
  
      //use setters to change the state
      void setCoordy( int coordy) {this.coordy = coordy;}
      void setCoordx( int coordx) {this.coordx = coordx;}
  }
  </code></pre>
  
  <p>Also, how can I draw something to permanently stay on the image for the entire run?</p>