Java installed in the background Jpanel

Author:Anonymous    Updated:2008-3-20 12:17:30
1. ImagePanel create a category, the code below import java.awt.BorderLayout; import javax.swing.JPanel; import java.io.File; import javax.imageio.ImageIO; import java.io.IOException; import java.awt.Image ; import java.awt.Graphics; import java.awt.Graphics2D; class ImagePanel extends JPanel (public ImagePanel () (try (File f = new File ( "Img / Login.gif"); img = ImageIO.read (f) ;) catch (IOException e) (e.printStackTrace ();)) private Image img; public void paintComponent (Graphics g) (super.paintComponent (g); Graphics2D g2 = (Graphics2D) g; if (img! = null) (g2.drawImage (img, 0, 0, getWidth (), getHeight (), 0, 0, img.getWidth (null), img.getHeight (null), null);))) in the new JPanel panel Call: the public class Welcome extends JPanel to public class Welcome extendsImagePanel background can be realized. use in the dialog box as follows: public class Login extends JDialog (String pass; static String name; ImagePanel panel1 = new ImagePanel (); / / ImagePanel categories included in the background as a replacement of the default background Jpanel1

1. ImagePanel create a category, the code below import java.awt.BorderLayout; import javax.swing.JPanel; import java.io.File; import javax.imageio.ImageIO; import java.io.IOException; import java.awt.Image ; import java.awt.Graphics; import java.awt.Graphics2D; class ImagePanel extends JPanel (public ImagePanel () (try (File f = new File ( "Img / Login.gif"); img = ImageIO.read (f) ;) catch (IOException e) (e.printStackTrace ();)) private Image img; public void paintComponent (Graphics g) (super.paintComponent (g); Graphics2D g2 = (Graphics2D) g; if (img! = null) (g2.drawImage (img, 0, 0, getWidth (), getHeight (), 0, 0, img.getWidth (null), img.getHeight (null), null);))) in the new JPanel panel Call: the public class Welcome extends JPanel to public class Welcome extendsImagePanel background can be realized. use in the dialog box as follows: public class Login extends JDialog (String pass; static String name; ImagePanel panel1 = new ImagePanel (); / / ImagePanel categories included in the background as a replacement of the default background Jpanel1
Previous:Java programs encryption and anti-encryption
Next:Hibernate local use of a simple SQL query
User Reviews
Related Articles
Recommended article
AD