Drawing on top of a gif image.

I need to be able to have a JPanel that holds a .gif image, have another JPanel over top of it that can be drawn upon. An example of this is placing a map on a table and laying a piece of clear plastic over top of it, then drawing on the plastic the route you want to take. Just as in this example, I want to be able to erase lines on the top image, but I can probably figure that part out OK, I just need the code to layer the drawing panel on top on the image.
How can this be done?
Thanks.

Exactly what problem are you having with getting a layered pane? The Java Tutorial on this site can give you all the basics regarding setting one up.

Similar Messages

  • To place text or gif image on another gif image

    We have requirement to write some content on top of a GIF image. Is it possible to write a text or embed a GIF image on top of a GIF image? We are using jdk1.3.1.
    The final image should be a gif or jpeg image.
    Using graphics2d drawstring method, we can write a text on a image but graphics2d can be placed on the canvas for displaying purpose but how to convert this graphics2d to bufferedimage so that we can save as gif or jpeg image.

    Uh oh, another consultancy firm not supplying the correct output to a client. Who woulda thunk?

  • Drawing on top

    Is it possible to layer a see through pane on top of my contents pane so that i can effectively draw on top of my current image without having to call paintComponent().
    how can i do it?

    from the desciption of panes glasspane seems to be what you want but i never have done anything with theese panes so don't count on it.

  • How can I draw on top of an image?

    I'm using a JApplet with three JPanel's inside of it.
    Inside one of those JPanel's I would like to place an image and a button. When the button is clicked, I want to draw an oval on top of the image . Each subsequent time the button is clicked, the oval will move to a different location.
    So here are my questions:
    1) What should I use to draw the image? (a JLabel with an ImageIcon on it?)
    2) Could I simply use g.drawOval() in paintComponent() to directly draw on top of the image/JLabel?
    Any help will be greatly appriciated.

    Here's a sample to study;-import java.awt.*;
    import java.awt.event.*;
    public class DrawOnImage extends java.applet.Applet{
      int xPos, yPos;
      Image img;
      public void init() {
        add(new Label("Hello World") );
        Button press = new Button("press");
        add(press);
        press.addActionListener(new ActionListener(){
          public void actionPerformed(ActionEvent e){
            xPos = (int)(Math.random()*270);
            yPos = (int)(Math.random()*170)+30;
            repaint();
        img = getImage(getDocumentBase(), "anImage.JPG");
      public void paint(Graphics g){
        g.drawImage(img,0,30,this);
        if(yPos>=30)g.fillOval(xPos, yPos, 45, 45);
    }

  • Drawing moving GIF images?

    Is it possible to draw moving gif images on a simple Frame applet?
    I made an image drawer class for my applet and i can draw simple 2d images.
    Here is the basis of my GameSprite class;
        public byte[] pixels;
        public int width;
        public int height;
        public GameSprite(String imageName, int requestIndex) {
         try {
                    // Removed code, it's zipInputStream, but it can be used just as ./image.jpg etc
         javax.swing.ImageIcon icon = new javax.swing.ImageIcon(fileBytes);
         width = icon.getIconWidth();
                     height = icon.getIconHeight();
                     pixels = fileBytes;
         } catch(Exception e) {
              e.printStackTrace();
        public void drawSprite(int x, int y) {
         try {
              Image image = Toolkit.getDefaultToolkit().createImage(pixels);
                                    //Removed code here
              graphics.drawImage(image, x, y + 7, width, height, observer);
         } catch(Exception e) {
              e.printStackTrace();
        }If i try to draw an animated gif image it dosn't move.
    Thanks for any help.

    In Java you need to override the paint method in AWT and paintComponenet method in SWING to do graphics/animation. If you go to an offscreen rendering, then you can paint to the graphics context of an image you use for a drawImage in your paint/paintComponent...
    If you where overriding a Panel in AWT you would override paint:
    public void paint(Graphics g){
      g.drawImage(im, 0, 0, this);
    }Then where you are maipulating your graphics you would do something like this:
    //code snippet
    Graphics g = im.getGraphics();
    //make what ever changes to im by manipulating the graphics context g
    repaint();

  • Drawing multiple .gif images

    Hello, I am creating a Card class and a Deck class, and I have .gif images for each card. I am trying to create a CardDisplay class to test my images. The Card/Deck classes work fine, but I am running into problems getting the images to display. What I have is a JFrame and I use a JLabel for each .gif image. When I add the JLabel to the contentPane, it is still only showing a blank window. Can someone give me any guidance as to how to go about this? Also, I am assuming once I get it to display 1 gif, it will display the remaining 51 in the same place. What I am trying to do is to display them all in a row.. well 4 rows of 13 cards that is. Thanks in advance,
    dub stylee

    Also, just wanted to add that this is not for school. I am doing this for a personal exercise using swing components. I made a card game when I was taking java 1 class, but now I am trying to familiarize myself with the use of graphics. Thanks to anybody who can help.
    dub stylee

  • Problem placing buttons on top of a background image

    My knowledge of Java isn't the greatest and I am currently having problems placing buttons on top of a background image within a JApplet (this is also my first encounter with Applets).
    I'm using a Card Layout in order to display a series of different screens upon request.
    The first card is used as a Splash Screen which is displayed for 5 seconds before changing to the Main Menu card.
    When the Main Menu card is called the background image is not shown but the button is.
    While the Applet is running no errors are shown in the console.
    Full source code can be seen below;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import java.net.*;
    // First extend JApplet
    public class WOT extends JApplet {
         //--------------- Variables are declared here -----------------
         private CardLayout contentCardLayout = new CardLayout();  // declare CardLayout
         private Container contentContain;     // declare content Container
         private JPanel contentCard, splashScreen, mainMenu, menuImage; // declare content Panels
         private JLabel splash, menu, map; // declare image labels
         private ImageIcon mapBtn; // declare ImageIcons
         private JButton mapOption; // declare option Buttons
         private Timer timer; // declare Timer
         private ActionListener actionListener, mapOptionListener; // declare ActionListener
    //--------------- Initialise Applet -----------------
      public void init() {
         //--------------- Set-up Card Layout -----------------
         contentCard = new JPanel(contentCardLayout); // assign card panels to CardLayout
         //--------------- Splash Screen -----------------
         splashScreen = new JPanel();
         splash = new JLabel(new ImageIcon(getClass().getResource("img/bg.gif")));
         splashScreen.add(splash);
         splashScreen.setSize(600,800);
         splashScreen.setLocation(0,0);
    //--------------- "View Map" Option Button -----------------
         mapBtn = new ImageIcon(getClass().getResource("img/map.gif"));
         mapOption = new JButton(mapBtn);
         mapOption.setBorder(null);
         mapOption.setContentAreaFilled(false);
         mapOption.setSize(150,66);
         mapOption.setLocation(150,450);
         mapOption.setOpaque(false);
         mapOption.setVisible(true);
    //--------------- Main Menu Screen -----------------
         //menuImage = new JPanel(null);
         //menuImage.add(mainMenu);
         //menuImage.setLocation(0,0);
         mainMenu = new JPanel(null);
         menu = new JLabel(new ImageIcon(getClass().getResource("img/menu.gif")));
         menu.setLocation(0,0);
         mainMenu.add(menu);
         //mainMenu.setBackground(Color.WHITE);
         mainMenu.setLocation(0,0);
         mainMenu.setOpaque(false);
         //mainMenu.setSize(150,66);
         mainMenu.add(mapOption);
         //--------------- Map Image Screen -----------------
         map = new JLabel(new ImageIcon(getClass().getResource("img/map.gif")));
         //--------------- Add Cards to CardLayout Panel -----------------
        contentCard.add(splashScreen, "Splash Screen");
         contentCard.add(mainMenu, "Main Menu");
         contentCard.add(map, "Map Image");
    //--------------- Set-up container -----------------
          contentContain = getContentPane(); // set container as content pane
          contentContain.setBackground(Color.WHITE); // set container background colour
           contentContain.setLocation(0,0);
           contentContain.setSize(600,800);
          contentContain.setLayout(new FlowLayout()); // set container layout
           contentContain.add(contentCard);  // cards added
           //--------------- Timer Action Listener -----------------
           actionListener = new ActionListener()
                    public void actionPerformed(ActionEvent actionEvent)
                             //--------------- Show Main Menu Card -----------------
                             contentCardLayout.show(contentCard, "Main Menu");
         //--------------- Map Option Button Action Listener -----------------
           mapOptionListener = new ActionListener()
                    public void actionPerformed(ActionEvent actionEvent)
                             //--------------- Show Main Menu Card -----------------
                             contentCardLayout.show(contentCard, "Map Image");
         //--------------- Timer -----------------               
         timer = new Timer(5000, actionListener);
         timer.start();
         timer.setRepeats(false);
    }Any help would be much appreciated!
    Edited by: bex1984 on May 18, 2008 6:31 AM

    1) When posting here, please use fewer comments. The comments that you have don't help folks who know Java read and understand your program and in fact hinder this ability, which makes it less likely that someone will in fact read your code and help you -- something you definitely don't want to have happen! Instead, strive to make your variable and method names as logical and self-commenting as possible, and use comments judiciously and a bit more sparingly.
    2) Try to use more methods and even classes to "divide and conquer".
    3) To create a panel with a background image that can hold buttons and such, you should create an object that overrides JPanel and has a paintComponent override method within it that draws your image using the graphics object's drawImage(...) method
    For instance:
    an image jpanel:
    import java.awt.Dimension;
    import java.awt.Graphics;
    import java.awt.image.BufferedImage;
    import java.io.File;
    import java.io.IOException;
    import java.net.URISyntaxException;
    import java.net.URL;
    import javax.imageio.ImageIO;
    import javax.swing.JButton;
    import javax.swing.JPanel;
    public class BackgroundImage
        // **** this will have to be changed for your program:
        private static final String IMAGE_PATH = "../../m02/a/images/Forest.jpg";
        private BufferedImage myImage = null;
        private JPanel imagePanel = new JPanel()
            @Override
            protected void paintComponent(Graphics g)
            {   // *** here is where I draw my image
                super.paintComponent(g);  // **** don't forget this!
                if (myImage != null)
                    g.drawImage(myImage, 0, 0, this);
        public BackgroundImage()
            imagePanel.setPreferredSize(new Dimension(600, 450));
            imagePanel.add(new JButton("Foobars Rule!"));
            try
                myImage = createImage(IMAGE_PATH);
            catch (IOException e)
                e.printStackTrace();
            catch (URISyntaxException e)
                e.printStackTrace();
        private BufferedImage createImage(String path) throws IOException,
                URISyntaxException
            URL imageURL = getClass().getResource(path);
            if (imageURL != null)
                return ImageIO.read(new File(imageURL.toURI()));
            else
                return null;
        public JPanel getImagePanel()
            return imagePanel;
    }and an applet that uses it:
    import java.lang.reflect.InvocationTargetException;
    import javax.swing.JApplet;
    import javax.swing.SwingUtilities;
    public class BackgrndImageApplet extends JApplet
        @Override
        public void init()
            try
                SwingUtilities.invokeAndWait(new Runnable()
                    @Override
                    public void run()
                        getContentPane().add(new BackgroundImage().getImagePanel());
            catch (InterruptedException e)
                e.printStackTrace();
            catch (InvocationTargetException e)
                e.printStackTrace();
    }

  • Digital watermarking gif images

    I ve writed a program which watermarks png and non-animated gif images .But there is a problem because we started to use animated gif images. How can we watermark animated gif images without corrupting animation of the image?
    Regards
    Murat

    I haven't done much with gif animation, but here's an example that extracts the series of BufferedImages
    from a gif file. Good luck!
    import java.awt.*;
    import java.awt.event.*;
    import java.awt.image.*;
    import java.io.*;
    import java.net.*;
    import java.net.URL;
    import java.util.*;
    import javax.imageio.*;
    import javax.imageio.metadata.*;
    import javax.imageio.stream.*;
    import javax.swing.*;
    import org.w3c.dom.*;
    public class ViewGif extends JPanel {
        private BufferedImage[] images;
        private Point[] offsets;
        private BufferedImage composite;
        public static void main(String[] args) throws IOException {
            JPanel app = new ViewGif();
            app.setBackground(Color.RED);
            JFrame frame = new JFrame("ViewGif");
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.getContentPane().add(new JScrollPane(app));
            frame.pack();
            frame.setLocationRelativeTo(null);
            frame.setVisible(true);
        public ViewGif() throws IOException {
            URL url = new URL("http://members.aol.com/royalef/sunglass.gif");
            Iterator readers = ImageIO.getImageReadersBySuffix("gif");
            if (!readers.hasNext())
                throw new IOException("no gif readers");
            ImageReader reader = (ImageReader) readers.next();
            if (readers.hasNext())
                System.out.println("(there were oither readers)");
            ImageInputStream iis = ImageIO.createImageInputStream(url.openStream());
            reader.setInput(iis);
            final int numImages = reader.getNumImages(true);
            images = new BufferedImage[numImages];
            offsets = new Point[numImages];
            for(int i=0; i<numImages; ++i) {
                images[i] =  reader.read(i);
                offsets[i] = getPixelOffsets(reader, i);
            composite = new BufferedImage(images[0].getWidth(), images[0].getHeight(),
                BufferedImage.TYPE_INT_ARGB);
            final Graphics2D g2 = composite.createGraphics();
            g2.drawImage(images[0], offsets[0].x, offsets[0].y, null);
            new javax.swing.Timer(100, new ActionListener(){
                int j = 1;
                public void actionPerformed(ActionEvent evt) {
                    g2.drawImage(images[j], offsets[j].x, offsets[j].y, null);
                    j = (j+1) % numImages;
                    repaint();
            }).start();
        protected void paintComponent(Graphics g) {
            super.paintComponent(g);
            Insets insets = getInsets();
            g.drawImage(composite, insets.left, insets.top, null);
        public Dimension getPreferredSize() {
            Insets insets = getInsets();
            int w = insets.left + insets.right + composite.getWidth();
            int h = insets.top + insets.bottom + composite.getHeight();
            return new Dimension(w,h);
        static Point getPixelOffsets(ImageReader reader, int num) throws IOException {
            IIOMetadata meta = reader.getImageMetadata(num);
            Point point = new Point(-1,-1);
            Node root = meta.getAsTree("javax_imageio_1.0");
            for (Node c = root.getFirstChild(); c != null; c = c.getNextSibling()) {
                String name = c.getNodeName();
                if ("Dimension".equals(name)) {
                    for (c = c.getFirstChild(); c != null; c = c.getNextSibling()) {
                        name = c.getNodeName();
                        if ("HorizontalPixelOffset".equals(name))
                            point.x = getValueAttribute(c);
                        else if ("VerticalPixelOffset".equals(name))
                            point.y = getValueAttribute(c);
                    return point;
            return point;
        static int getValueAttribute(Node node) {
            try {
                return Integer.parseInt(node.getAttributes().getNamedItem("value").getNodeValue());
            } catch (NumberFormatException e) {
                return -2;

  • Problem at displaying animated gif images !!!!!!!!!!!!

    hello everyone......i am trying to display an animated gif image..............so till far i have no issues on this....
    but i face problem when :
    i have created a class called SimpleGame which extends JPanel....
    public class SimpleGame extends JPanel
    //code
    public void paintComponent(Graphics g)
    //code to draw image
    }now i have written another class with main method
    public class MyGame extends SimpleGame
    public MyGame()
            JFrame frame=new JFrame();
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.setSize(800, 600);
            frame.setUndecorated(true);
            frame.setLocationRelativeTo(null);
            frame.getContentPane().add(this);
            frame.setVisible(true);
            this.repaint();
    }so image gets displayed but only one frame of animated image......image that is displayed is static.....since it is a animated gif,,,,,so some how animation is not rendered......only one frame is displayed......
    why is it happening ??
    if i try to display animated image from a single class i mean my paintComponent method and main method is at same class then i do not face problem.....
    but if my paint method is in another class and i am using that method from another class then animation does not get rendered.........
    any help !!!!! please...........

    class SimpleGame extends JPanel
    Image img=new ImageIcon("y.gif");
    public void paintComponent(Graphics g)
    g.drawImage(img,150,150,this);
    }main class//
    class MyGame extends SimpleGame
    public MyGame()
            JFrame frame=new JFrame();
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.setSize(800, 600);
            frame.setUndecorated(true);
            frame.setLocationRelativeTo(null);
            frame.getContentPane().add(this);
            frame.setVisible(true);
            this.repaint();
    public static void main(String[] args)
    new MyGame();
    }my image gets displayed.......but only single frame of a animated image....animation is not happening..........

  • Adding GIF images to a stand-alone program

    To add a GIF image to an applet one can use the "getImage" function defined in the applet class.
    How do i add an image to a stand-alone program in java when one doesn't extend the Applet class ( and so one doesn't have access
    to the "getImage" procedure)
    I have just begun with Java so please reply in simple english and not in some hard-to-understand "Javian" crap!
    Thank u

    You mean a JFrame?
    import java.awt.*;
    import javax.swing.*;
    public class JFrameImage extends JFrame {
      public JFrameImage() {
          Container c    = getContentPane();
          JPanel panel = new JPanel(){
                 public void paintComponent(Graphics g)     {
    // puts an image on the whole program as background
                      ImageIcon img = new ImageIcon("myBackground.jpg");
                      g.drawImage(img.getImage(), 0, 0, null);
                      super.paintComponent(g);
            panel.setOpaque(false);
    // puts an image on the button
          ImageIcon icon = new ImageIcon("myButton.jpg");
          JButton button = new JButton(icon);
          panel.add(button);
          c.add(panel);
      public static void main(String[] args) {
        JFrameImage frame = new JFrameImage();
    // puts your own personal image on the frame itself
          Image onFrame = Toolkit.getDefaultToolkit().getImage("myIcon.gif") ;
        frame.setIconImage(onFrame);
        frame.setSize(200,200);
    // stops the thing looking sh*tty and amateurish by putting it nearer the middle
    // of the screen, instead of the default top left hand corner
        frame.setLocation(300,200);
        frame.setDefaultCloseOperation( EXIT_ON_CLOSE );
        frame.setVisible(true);
    }

  • (Urgent)help: how to use sdk add a gif image into a pdf document

    I had use sdk plus-in add a new button of mine,if I click the button,a gif image will be inserted into the current page of pdf document
    My questions:
    one : When I clicked the button,there was a warnning box said:the image has not enough data.I don't known why?
    two : How can I be sure the position of the image which I inserted? and how to change it's position?
    three:  how to use sdk get the content of the document?

    hi Leonard:
    I do it like you said, but
    Why my image can not display in the pdf.
    code is:
    //====================================================================
    const ASInt32 theImageByteSize = IMG_WIDTH * IMG_HEIGHT;
    char* buff = new char[theImageByteSize];
    PDEImage volatile pdeImage = NULL;
    PDEImageAttrs pdeImageAttrs;
    PDEColorSpace pdeColorSpace;
    ASFixedMatrix imageMatrix;
    memset(&pdeImageAttrs, 0, sizeof(PDEImageAttrs));
    int hdl = _open(ImagePath, _O_RDONLY | _O_BINARY, _S_IWRITE | _S_IREAD);
    if (hdl == -1)
         AVAlertNote("[%s] create fail !!!!") ;
    if (_read(hdl, buff, theImageByteSize) == -1)
         AVAlertNote("read image fail!") ;
    pdeImageAttrs.width = IMG_WIDTH;
    pdeImageAttrs.height = IMG_HEIGHT;
    pdeImageAttrs.intent = ASAtomNull;
    pdeImageAttrs.bitsPerComponent = 8;
    pdeImageAttrs.flags = kPDEImageExternal | kPDEImageIsIndexed;
    pdeImageAttrs.decode[0] = fixedZero;
    pdeImageAttrs.decode[1] = fixedOne;
    pdeImageAttrs.decode[2] = fixedZero;
    pdeImageAttrs.decode[3] = fixedOne;
    pdeImageAttrs.decode[4] = fixedZero;
    pdeImageAttrs.decode[5] = fixedOne;
    ASFixedRect theMediaBox;
    PDPageGetMediaBox( AVPageViewGetPage(pageView), &theMediaBox );
    ASFixed theFixedWidth = (theMediaBox.right - theMediaBox.left);
    ASFixed theFixedHeight = (theMediaBox.top - theMediaBox.bottom);
    imageMatrix.a = ASInt16ToFixed(theFixedWidth);
    imageMatrix.d = ASInt16ToFixed(theFixedHeight);
    imageMatrix.b = imageMatrix.c = fixedZero;
    imageMatrix.h = 0;
    imageMatrix.v = 0;
    const Int32 cPaletteColors = 256;
    PDEIndexedColorData theIndexedData;
    theIndexedData.size = sizeof(theIndexedData);
    theIndexedData.baseCs = PDEColorSpaceCreateFromName(ASAtomFromString( "DeviceRGB"));
    theIndexedData.hival = cPaletteColors - 1;
    unsigned char data[3] = {255, 0, 0};
    theIndexedData.lookup = (char *)data;
    theIndexedData.lookupLen = cPaletteColors * 3;
    PDEColorSpaceStruct theColorData;
    theColorData.indexed = &theIndexedData;
    pdeColorSpace = PDEColorSpaceCreate(ASAtomFromString( "Indexed" ), &theColorData );
    pdeImage = PDEImageCreate(&pdeImageAttrs, sizeof(pdeImageAttrs), &imageMatrix,
                                                0, pdeColorSpace, NULL, NULL, NULL, (unsigned char*)buff, theImageByteSize);
    I want die, I had done this for so many days, My GIF doesn't insert into pdf,
    unsigned char data[3] = {255, 0, 0};
    theIndexedData.lookup = (char *)data;  "
    whether the data set wrong?
    I confused what I do next   

  • Adding a gif image

    At the moment I have just drawn checkers but I would like to add a .gif image so it looks alot better. But im really unsure how to do this without completely messing things up. Thanks to any help guys
    import java.applet.*;
    import java.awt.*;
    import java.awt.event.*;
    public class MyDraughts1edited extends Applet
                             implements MouseListener, MouseMotionListener{
      private int top = 0, left1 = 0, bWidth = 200, n = 4;
      private Point counter1, counter2, counter3, counter4, counter5, counter6,
       counter7, counter8, mouse;
      private int select;
      public void init() {
        this.addMouseMotionListener(this);
        this.addMouseListener(this);
        counter1 = new Point(15,15);
        counter2 = new Point(65,15);
        counter3 = new Point(115,15);
        counter4 = new Point(165,15);
        counter5 = new Point(15,165);
        counter6 = new Point(65,165);
        counter7 = new Point(115,165);
        counter8 = new Point(165,165);
      public void paint (Graphics g) {
        Draw_Board(g);
        g.setColor (Color.black);
        g.fillOval(counter1.x, counter1.y, 20,20);
        g.fillOval(counter2.x, counter2.y, 20,20);
        g.fillOval(counter3.x, counter3.y, 20,20);
        g.fillOval(counter4.x, counter4.y, 20,20);
        g.setColor (Color.white);
        g.fillOval(counter5.x, counter5.y, 20,20);
        g.fillOval(counter6.x, counter6.y, 20,20);
        g.fillOval(counter7.x, counter7.y, 20,20);
        g.fillOval(counter8.x, counter8.y, 20,20);
      public void mouseDragged(MouseEvent e) {
        mouse = e.getPoint();
        // continuously change the coordinates of the selected counter
        switch(select){
          case 1 : counter1 = mouse; break;
          case 2 : counter2 = mouse; break;
          case 3 : counter3 = mouse; break;
          case 4 : counter4 = mouse; break;
          case 5 : counter5 = mouse; break;
          case 6 : counter6 = mouse; break;
          case 7 : counter7 = mouse; break;
          case 8 : counter8 = mouse; break;
          default :
        repaint();
      // required for the interface
      public void mouseMoved(MouseEvent e) {}
      public void mousePressed(MouseEvent e) {
        mouse = e.getPoint();
        if (mouse.x > counter1.x - 20 && mouse.x < counter1.x + 20 &&
            mouse.y > counter1.y - 20 && mouse.y < counter1.y + 20){
          select = 1;
        else if (mouse.x > counter2.x - 20 && mouse.x < counter2.x + 20 &&
            mouse.y > counter2.y - 20 && mouse.y < counter2.y + 20){
          select = 2;
        else if (mouse.x > counter3.x - 20 && mouse.x < counter3.x + 20 &&
            mouse.y > counter3.y - 20 && mouse.y < counter3.y + 20){
          select = 3;
        else if (mouse.x > counter4.x - 20 && mouse.x < counter4.x + 20 &&
            mouse.y > counter4.y - 20 && mouse.y < counter4.y + 20){
          select = 4;
        else if (mouse.x > counter5.x - 20 && mouse.x < counter5.x + 20 &&
            mouse.y > counter5.y - 20 && mouse.y < counter5.y + 20){
          select = 5;
        else if (mouse.x > counter6.x - 20 && mouse.x < counter6.x + 20 &&
            mouse.y > counter6.y - 20 && mouse.y < counter6.y + 20){
          select = 6;
        else if (mouse.x > counter7.x - 20 && mouse.x < counter7.x + 20 &&
            mouse.y > counter7.y - 20 && mouse.y < counter7.y + 20){
          select = 7;
        else if (mouse.x > counter8.x - 20 && mouse.x < counter8.x + 20 &&
            mouse.y > counter8.y - 20 && mouse.y < counter8.y + 20){
          select = 8;
        else{
        repaint();
      // required for the interface
      public void mouseClicked(MouseEvent event){}
      public void mouseReleased(MouseEvent event){}
      public void mouseEntered(MouseEvent event){}
      public void mouseExited(MouseEvent event){}
      private void Draw_Board(Graphics g) {
        int sqWidth = bWidth/n; // Rounds down
        for (int row = 0; row < 4; ++row){
          for(int Col=0; Col<4; Col++) {
            g.setColor(posColor(row, Col));
            g.fillRect
             (left1 + Col * sqWidth, top + row * sqWidth, sqWidth, sqWidth);
      private boolean isEven(int x) {
        return(x == 2 * (x / 2));
      private Color posColor(int row, int Col) {
        if ( (isEven(row) && isEven(Col)) ||
            (! isEven(row) && ! isEven(Col))){
          return(Color.GRAY);
        else{
          return(Color.lightGray);
    }

    If you can use Swing instead of AWT, then maybe this posting will give you some ideas:
    http://forum.java.sun.com/thread.jspa?forumID=57&threadID=518707&start=3

  • Safari downloads gif images for no reason

    When I visit this site
    www.jsonline.com
    some gif images are automatically downloaded (called p-01-OVlaSjnOLG.gif). Every click results in a download. How do I stop this?
    Safari version 4.0.4, running on OS X 10.5.8. Lots of space on hard drive.

    HI and Welcome to Apple Discussions...
    If you right or control click an image a pop up menu will appear but just clicking on an image shouldn't result in the file automatically downloading.
    Try resetting Safari and emptying the cache.
    From the Safari Menu Bar, click Safari / Empty Cache. When you are done with that...
    From the Safari Menu Bar, click Safari / Reset Safari. Select the top 5 buttons and click Reset.
    Go here for trouble shooting 3rd party plugins or input managers which might be causing the problem.
    http://support.apple.com/kb/TS1594
    Make sure Safari is not running in Rosetta. Right or control click the Safari icon in your Applications folder then click Get Info. In the Get Info window click the black disclosure triangle so it faces down. Where you see Open using Rosetta... make sure that is NOT selected.
    Carolyn

  • How to resize a gif image

    hi
    i need to resize a gif image to my preferable height and width . i have copied some code from net , its working fine for small images . but when i resize large images the background becomes back .... so
    any body help me put in this....
    regards
    mano

    hi
    thanks for ur reply . can u plz tell me were to insert the code here
    Image image = Toolkit.getDefaultToolkit().getImage("C:\\image.gif");
    MediaTracker mediaTracker = new MediaTracker(new Container());
    mediaTracker.addImage(image, 0);
    mediaTracker.waitForID(0);
    // determine thumbnail size from WIDTH and HEIGHT
    int thumbWidth = Integer.parseInt("120");
    int thumbHeight = Integer.parseInt("75");
    double thumbRatio = (double)thumbWidth / (double)thumbHeight;
    int imageWidth = image.getWidth(null);
    System.out.println("imageWidth "+ imageWidth);
    int imageHeight = image.getHeight(null);
    double imageRatio = (double)imageWidth / (double)imageHeight;
    if (thumbRatio < imageRatio) {
    thumbHeight = (int)(thumbWidth / imageRatio);
    } else {
    thumbWidth = (int)(thumbHeight * imageRatio);
    // draw original image to thumbnail image object and
    // scale it to the new size on-the-fly
    BufferedImage thumbImage = new BufferedImage(thumbWidth,
    thumbHeight, BufferedImage.TYPE_INT_RGB);
    Graphics2D graphics2D = thumbImage.createGraphics();
    graphics2D.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
    RenderingHints.VALUE_INTERPOLATION_BILINEAR);
    graphics2D.drawImage(image, 0, 0, thumbWidth, thumbHeight, null);
    // save thumbnail image to OUTFILE
    BufferedOutputStream out = new BufferedOutputStream(new
    FileOutputStream(args[1]));
    JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);
    JPEGEncodeParam param = encoder.
    getDefaultJPEGEncodeParam(thumbImage);
    int quality = Integer.parseInt("75");
    quality = Math.max(0, Math.min(quality, 100));
    param.setQuality((float)quality / 100.0f, false);
    encoder.setJPEGEncodeParam(param);
    encoder.encode(thumbImage);
    out.close();
    System.out.println("Done.");

  • When I "save page as" I also get a folder with gif images, jscript script files and other similar items. how can I stop this.

    When I "save page as" via the file button at the top edge of the page, I also get a folder containing gif images, jscript script files and other similar items. I am not is allowed to delete it unless I also delete the page I need. How can I stop this from happening. is it the way I've configured firefox perhaps.
    == since I installed firefox

    Make sure that you have selected "Web Page, complete" to save the page.

Maybe you are looking for