473,414 Members | 1,567 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,414 software developers and data experts.

Removing a text written over a background image

36
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????????????
Apr 18 '08 #1
2 3138
JosAH
11,448 Expert 8TB
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
Apr 18 '08 #2
BigDaddyLH
1,216 Expert 1GB
Sometimes I was a Border to draw the background image. This may be cheating...

Expand|Select|Wrap|Line Numbers
  1. import java.awt.*;
  2. import java.awt.image.*;
  3. import javax.swing.border.*;
  4.  
  5. public class CentredBackgroundBorder implements Border {
  6.     private final BufferedImage image;
  7.  
  8.     public CentredBackgroundBorder(BufferedImage image) {
  9.         this.image = image;
  10.     }
  11.  
  12.     public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
  13.         int x0 = x + (width-image.getWidth())/2;
  14.         int y0 = y + (height-image.getHeight())/2;
  15.         g. drawImage(image, x0, y0, null);
  16.     }
  17.  
  18.     public Insets getBorderInsets(Component c) {
  19.         return new Insets(0,0,0,0);
  20.     }
  21.  
  22.     public boolean isBorderOpaque() {
  23.         return true;
  24.     }
  25. }
  26.  
Expand|Select|Wrap|Line Numbers
  1. import java.awt.*;
  2. import java.io.*;
  3. import java.net.URL;
  4. import javax.imageio.*;
  5. import javax.swing.*;
  6. import javax.swing.border.*;
  7.  
  8. public class BackgroundBorderExample {
  9.     public static void main(String[] args) throws IOException {
  10.         JFrame.setDefaultLookAndFeelDecorated(true);
  11.         JFrame f = new JFrame("BackgroundBorderExample");
  12.         f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  13.         JTextArea area = new JTextArea(24,80);
  14.         area.setForeground(Color.WHITE);
  15.         area.setOpaque(false);
  16.         area.read(new FileReader(new File("BackgroundBorderExample.java")), null);
  17.         final JScrollPane sp = new JScrollPane(area);
  18.         sp.setBackground(Color.BLACK);
  19.         sp.getViewport().setOpaque(false);
  20.         f.getContentPane().add(sp);
  21.         f.setSize(600,400);
  22.         f.setLocationRelativeTo(null);
  23.         f.setVisible(true);
  24.  
  25.         String url = "http://blogs.sun.com/jag/resource/JagHeadshot.jpg";
  26.         final Border bkgrnd = new CentredBackgroundBorder(ImageIO.read(new URL(url)));
  27.         Runnable r = new Runnable() {
  28.             public void run() {
  29.                 sp.setViewportBorder(bkgrnd);
  30.                 sp.repaint();
  31.             }
  32.         };
  33.         SwingUtilities.invokeLater(r);
  34.     }
  35. }
  36.  
Apr 18 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Markus Mohr | last post by:
Hi, everyone, I have a special problem: For every monitor resolution in 200 pixel steps from 800 to 1600 pixels I have an image to be shown as centered background-image. Those images all...
0
by: roger | last post by:
I have a text field set with a background image using CSS. Is it possible to prevent the background from scrolling in IE? it seems to not do it in Opera. if you look here...
4
by: lindsey.crocker | last post by:
I have this links list with background images set on them which changes when they roll over. The <td> is set valign="middle" however as soon as you apply the rollover to the link, the text jumps...
2
by: AS | last post by:
Hi, I have a windows form with a background image - set through the forms background image property. The form also has panels and icons on top of it. When this form is loading, there's a...
24
by: TC | last post by:
Hi folks I want to enhance my website to distinguish "external" hyperlinks from "internal" ones. With that aim, I've written the following two small files for testing purposes: ...
7
by: Wes Groleau | last post by:
Any kind soul feel like ending my efforts to figure out why two images are removing the top few rows of pixels but repeating them at the bottom? http://www.northwestallentrails.org/ Looks the...
5
by: Michael | last post by:
Is there a way to specify a background-image for a html table cell in a theme's css file. I know a lot of things I can't do... can't figure out one that I can do: 1) ~/ Images/logo.gif...
16
by: stevedude | last post by:
CSS newbie again. I have a problem trying to get coffee mug images within anchor tags to center with my link text for a vertical list menu. If I use the horizontal/vertical properties of...
2
by: thephatp | last post by:
I'm having a problem with IE rendering correctly. I'm experimenting with using all div's in my pages now, and I'm not very familiar with the quirks of IE. I have created a sample page, and I'm...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.