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);
		G2Logo = new JPanel();
		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);

	private class LogoPanel extends JPanel {
		public static final long serialVersionUID = 1l;
		private Image imMobile;
		private Image imComputer;
		public LogoPanel() {
			imMobile = Imagem.createMobileImage(Color.BLACK);
			imComputer = Imagem.createComputerImage(Color.BLACK);
			this.setPreferredSize(new Dimension(150, 176));
		public void paintComponent(Graphics g) {
			Graphics2D g2 = (Graphics2D) g;
			int width = getWidth();    	  
	    	int height = getHeight();

	        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


Recommended Answers

All 7 Replies

Any Ideas ? :)

Use a JLabel with an ImageIcon to display a jpeg. Soemthing like:

JFrame window = new JFrame("Logo Window");
      JLabel label = new JLabel();
      label.setIcon(new ImageIcon(imageFileName));
      Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
      window.setLocation((screenSize.width - window.getWidth()) / 2,
            (screenSize.height - window.getHeight()) / 2);

use ImageIcon and locate the same by a label. Else simply declare the u r jpgs at the top of u r code as global

use ImageIcon and locate the same by a label.

I already said this. Didn't your read the whole thread?


Else simply declare the u r jpgs at the top of u r code as global

This is gibberish.

what Mr i just concentrate on the problem but not u r posts k

:-O ?
u better read all the posts before giving out your "solution" otherwise it leads to something called redundancy.

Also, from next time, be more specific as your posts are indeed "gibberish".

Thanks ALl OF you Guys !)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.