Removing a text written over a background image

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • pankajs
    New Member
    • Mar 2008
    • 36

    Removing a text written over a background image

    Hello freinds ! I am writing a code for a simple shooting game. But a problem occur that I could not remove a message written over a background image
    How can I remove it without any change in background????? ???????
  • JosAH
    Recognized Expert MVP
    • Mar 2007
    • 11453

    #2
    Originally posted by pankajs
    Hello freinds ! I am writing a code for a simple shooting game. But a problem occur that I could not remove a message written over a background image
    How can I remove it without any change in background????? ???????
    How about: draw the image again but don't draw the text over it?

    kind regards,

    Jos

    Comment

    • BigDaddyLH
      Recognized Expert Top Contributor
      • Dec 2007
      • 1216

      #3
      Sometimes I was a Border to draw the background image. This may be cheating...

      [CODE=Java]import java.awt.*;
      import java.awt.image. *;
      import javax.swing.bor der.*;

      public class CentredBackgrou ndBorder implements Border {
      private final BufferedImage image;

      public CentredBackgrou ndBorder(Buffer edImage image) {
      this.image = image;
      }

      public void paintBorder(Com ponent c, Graphics g, int x, int y, int width, int height) {
      int x0 = x + (width-image.getWidth( ))/2;
      int y0 = y + (height-image.getHeight ())/2;
      g. drawImage(image , x0, y0, null);
      }

      public Insets getBorderInsets (Component c) {
      return new Insets(0,0,0,0) ;
      }

      public boolean isBorderOpaque( ) {
      return true;
      }
      }
      [/CODE]

      [CODE=Java]import java.awt.*;
      import java.io.*;
      import java.net.URL;
      import javax.imageio.* ;
      import javax.swing.*;
      import javax.swing.bor der.*;

      public class BackgroundBorde rExample {
      public static void main(String[] args) throws IOException {
      JFrame.setDefau ltLookAndFeelDe corated(true);
      JFrame f = new JFrame("Backgro undBorderExampl e");
      f.setDefaultClo seOperation(JFr ame.EXIT_ON_CLO SE);
      JTextArea area = new JTextArea(24,80 );
      area.setForegro und(Color.WHITE );
      area.setOpaque( false);
      area.read(new FileReader(new File("Backgroun dBorderExample. java")), null);
      final JScrollPane sp = new JScrollPane(are a);
      sp.setBackgroun d(Color.BLACK);
      sp.getViewport( ).setOpaque(fal se);
      f.getContentPan e().add(sp);
      f.setSize(600,4 00);
      f.setLocationRe lativeTo(null);
      f.setVisible(tr ue);

      String url = "http://blogs.sun.com/jag/resource/JagHeadshot.jpg ";
      final Border bkgrnd = new CentredBackgrou ndBorder(ImageI O.read(new URL(url)));
      Runnable r = new Runnable() {
      public void run() {
      sp.setViewportB order(bkgrnd);
      sp.repaint();
      }
      };
      SwingUtilities. invokeLater(r);
      }
      }
      [/CODE]

      Comment

      Working...