i need to know how i can add to my background Image any fish tank -like effects
ID: 3635207 • Letter: I
Question
i need to know how i can add to my background Image any fish tank -like effects Bubbles , translucent color etc )
here is the code
import javax.swing.*;
public class FishTank extends JFrame{
public FishTank(){
ImageIcon sea = new ImageIcon("sea.jpg");
SeaImage panel = new SeaImage(sea);
setTitle("Fish Tank");
setSize(800,400);
setLocation(250,150);
panel.setOpaque(false);
panel.setOpaque(false);
add(panel);
setVisible(true);
}
class SeaImage extends JPanel{
private ImageIcon img;
public SeaImage(ImageIcon img) {
this.img =img;
}
public void paint(Graphics g) {
Dimension d = getSize();
for (int x = 0; x < d.width; x += img.getIconWidth())
for (int y = 0; y < d.height; y += img.getIconHeight())
g.drawImage(img.getImage(), x, y, null, null);
super.paint(g);
}
public static void main (String []args)
{
FishTank fsh = new FishTank();
}//end main
}//end Fish-Tank
Explanation / Answer
This code will set Background image...
but you have to change your image path.....where you located your image..The highlated Path you have to change
PLz Rate it........
/*
Class Created By
RAKESH M
*/
import java.awt.Dimension;
import java.awt.Graphics;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class FishTank extends JFrame{
public FishTank(){
ImageIcon sea = new ImageIcon("C:\swap.jpg");
SeaImage panel = new SeaImage(sea);
setTitle("Fish Tank");
setSize(800,400);
setLocation(250,150);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
panel.setOpaque(false);
panel.setOpaque(false);
add(panel); setVisible(true);
}
public static void main (String []args) {
FishTank fsh = new FishTank(); }//end main
class SeaImage extends JPanel {
private ImageIcon img;
public SeaImage(ImageIcon img) { this.img =img; }
public void paint(Graphics g) {
Dimension d = getSize();
for (int x = 0; x < d.width; x += img.getIconWidth())
for (int y = 0; y < d.height; y += img.getIconHeight())
g.drawImage(img.getImage(), x, y, null, null);
super.paint(g);
}
}
}
If you have any assist Plz contact me.........
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.