Hey ! :)
Below is my code for a about page ! i need to load a image instead of suing drawString to draw the image ! :icon_redface:
what i need to do is to load a jpg and center it to screen ! can any1 help me to modify the code ? :icon_rolleyes:
it will be great if you can explin the code with the modification :icon_cheesygrin:
Thanks in advance ! :*
package G2.Test.About.interface;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.GridLayout;
import java.awt.Image;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
public class AboutFrame extends JDialog {
public static final long serialVersionUID = 1l;
private JLabel lbAbG2;
private JPanel G2Logo;
public AboutFrame(JFrame owner) {
super(owner, Messages.getMessage("about"), true);
getContentPane().setBackground(Color.RED);
G2Logo = new JPanel();
G2Logo.setBackground(Color.ORANGE);
G2Logo.setPreferredSize(new Dimension(176, 176));
G2Logo.add(new LogoPanel());
// images goes here
JPanel panelText = new JPanel();
lbAbG2 = new JLabel(Messages.getMessage("aboutMessage"), JLabel.CENTER);
JLabel lbLink = new JLabel("http://www.G2designLabs.com", JLabel.CENTER);
lbLink.setForeground(Color.BLACK);
pack();
setLocationRelativeTo(null);
setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
}
private class LogoPanel extends JPanel {
public static final long serialVersionUID = 1l;
private Image imMobile;
private Image imComputer;
public LogoPanel() {
super();
imMobile = Imagem.createMobileImage(Color.BLACK);
imComputer = Imagem.createComputerImage(Color.BLACK);
this.setPreferredSize(new Dimension(150, 176));
}
public void paintComponent(Graphics g) {
super.paintComponent(g);
Graphics2D g2 = (Graphics2D) g;
int width = getWidth();
int height = getHeight();
g2.setColor(Color.ORANGE);
g2.fillRect(0,0,width, height);
g2.setColor(new Color(200,10,15));
g2.drawImage(imComputer, width/2 - 18, height/2 - 26, this); computador
g2.drawImage(imMobile, width/2 - imMobile.getWidth(null) - 6, height/2 - 8, this); //desenha o celular
}
}
}