View Single Post
  #1 (permalink)  
Old 04-16-2008, 05:57 PM
Floetic's Avatar
Floetic Floetic is offline
Member
 
Join Date: Feb 2008
Location: Belfast, Northern Ireland, UK
Posts: 7
Floetic is on a distinguished road
Send a message via MSN to Floetic
Center background image
Hi!

The background image is showing but I would like to center it - how can this be done!?!

Thanks.


Code:
import java.awt.*; import java.awt.event.*; import java.awt.image.*; import java.io.*; import javax.imageio.*; import javax.swing.*; public class NewClass10 extends JPanel { final BufferedImage bi; public NewClass10() throws IOException { bi = ImageIO.read(new File("C:\\Documents and Settings\\Flo\\My Documents\\My Pictures\\bigstockphoto_Binary_Globe_55596.jpg")); } public void paintComponent(Graphics g) { g.drawImage(bi,getWidth()-bi.getWidth(),getHeight()-bi.getHeight(),null); } public static void main(String[] args) { EventQueue.invokeLater(new Runnable() { public void run() { try { JFrame f = new JFrame(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); NewClass10 t7 = new NewClass10(); f.setContentPane(t7); f.setSize(1025,703); f.setVisible(true); } catch (IOException ioe) { ioe.printStackTrace(); } } }); } }
Reply With Quote
Sponsored Links