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
	        
		}
	}

}

Edited 6 Years Ago by g2gayan: n/a

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

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

Edited 6 Years Ago by JamesCherrill: n/a

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.

@prisonpassioner
:-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".

This article has been dead for over six months. Start a new discussion instead.