Results 1 to 3 of 3
  1. #1
    paty is offline Member
    Join Date
    Jul 2007
    Posts
    41
    Rep Power
    0

    Default how to place an image in an applet

    Hello people can anyone tell me how I place an image in an applet once someone has clicked the mouse.

    I have already got an image drawn on the applet, imgBackground, and I want to place the image, imgZero, over the top of the image already there when someone clicks the mouse. Here is my code :
    Java Code:
    import java.applet.*;
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    
    public class gameClass extends Applet implements ActionListener
    {
    
    private Image imgBackground, imgZero;
    
    public void init()
    {
    imgBackground = getImage(getDocumentBase(), "Back.gif");
    imgZero = getImage(getDocumentBase(), "zero.gif");
    }
    
    public void paint(Graphics g)
    {
    g.drawImage(imgBackground,0,0,this);
    }
    
    
    public void mouseClicked(MouseEvent event)
    {
    
    }
    public void actionPerformed(ActionEvent event)
    {
    
    }
    
    }

  2. #2
    hardwired's Avatar
    hardwired is offline Senior Member
    Join Date
    Jul 2007
    Posts
    1,576
    Rep Power
    9

    Default

    Java Code:
    //  <applet code="GameClassRx" width="400" height="400"></applet>
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    
    public class GameClassRx extends JApplet implements ActionListener
    {
        private Image imgBackground, imgZero;
        DrawingPanel drawingPanel = new DrawingPanel();
    
        public void init()
        {
            imgBackground = getImage(getDocumentBase(), "Back.gif");
                                                        //"images/cougar.jpg");
            imgZero = getImage(getDocumentBase(), "zero.gif");
                                                  //"images/Bird.gif");
            setLayout(new BorderLayout());
            add(drawingPanel);
            drawingPanel.addMouseListener(locater);
        }
    
        private class DrawingPanel extends JPanel
        {
            Point origin = new Point();
    
            protected void paintComponent(Graphics g)
            {
                super.paintComponent(g);
                g.drawImage(imgBackground,0,0,this);
                g.drawImage(imgZero, origin.x, origin.y, this);
            }
    
            public void setOrigin(Point p) {
                origin = p;
                repaint();
            }
        }
    
        private MouseListener locater = new MouseAdapter()
        {
            public void mouseClicked(MouseEvent event)
            {
                drawingPanel.setOrigin(event.getPoint());
            }
        };
    
        public void actionPerformed(ActionEvent event)
        {
    
        }
    }

  3. #3
    paty is offline Member
    Join Date
    Jul 2007
    Posts
    41
    Rep Power
    0

Similar Threads

  1. How can i copy a folder from one place to another..
    By rajeshgubba in forum New To Java
    Replies: 4
    Last Post: 06-14-2008, 02:21 AM
  2. Image upload applet 2.0
    By jfileupload in forum Java Software
    Replies: 0
    Last Post: 03-24-2008, 04:15 PM
  3. Replies: 0
    Last Post: 01-08-2008, 05:29 PM
  4. How to place panel into frame
    By vivek_9912 in forum AWT / Swing
    Replies: 2
    Last Post: 11-19-2007, 11:21 PM
  5. how to place a divider of the splitpane?
    By christina in forum New To Java
    Replies: 1
    Last Post: 08-06-2007, 07:41 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •