Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Dec 13th, 2005, 4:53 PM   #1
mariogarcia
Newbie
 
Join Date: Mar 2005
Posts: 4
Rep Power: 0 mariogarcia is on a distinguished road
jbuilder

hello
i have to classes that put an image as background in a jframe, i would love to import them into jbuilder in order to add more items such as buttons and text field into the window but I don't know how, if I open a new project, then create classes and paste the code on these classes there are errors while compiling, instead if i use another IDE the classes compile well and i got the windows.
It's mandatory that I use jbuilder.
here i's the code from my two classes:
import javax.swing.*; 
import java.awt.*; 
import java.awt.image.*; 

public class JPanelImageBg extends JComponent
{
	private int mode;
	private TexturePaint texture; 
	private BufferedImage bufferedImage; 

	public static final int CENTRE = 0;
	public static final int TEXTURE = 1;

	JPanelImageBg( String fileName, int mode )
	{	this.mode = mode;
		this.bufferedImage = this.toBufferedImage(Toolkit.getDefaultToolkit().getImage(fileName));
		this.texture = new TexturePaint(bufferedImage,new Rectangle(0, 0, bufferedImage.getWidth(), bufferedImage.getHeight())); 
	} 

	public void paintComponent(Graphics g)
	{	switch( mode )
		{	case TEXTURE :
				Graphics2D g2d = (Graphics2D)g; 
				g2d.setPaint(texture);
				g2d.fillRect(0, 0, getWidth(), getHeight() );
				break;
			case CENTRE :
				g.setColor(this.getBackground());
				g.fillRect(0,0,getWidth(), getHeight() );
				g.drawImage(bufferedImage,(getWidth()-bufferedImage.getWidth())/2,(getHeight()-bufferedImage.getHeight())/2,null);
				break;
			default :
				super.paintComponents(g);
		}
	}


	private BufferedImage toBufferedImage(Image image)
	{	image = new ImageIcon(image).getImage(); 

		BufferedImage bufferedImage = new BufferedImage( image.getWidth(null), image.getHeight(null), BufferedImage.TYPE_INT_RGB); 
		Graphics g = bufferedImage.createGraphics(); 

		g.setColor(Color.white); 
		g.fillRect(0, 0, image.getWidth(null), 
		image.getHeight(null)); 
		g.drawImage(image, 0, 0, null); 
		g.dispose(); 
		return bufferedImage; 
	}

}
import javax.swing.*;

public class JPanelImageBgTest extends JFrame
{


	JPanelImageBgTest(String titre, int mode )
	{	
		super(titre);
		this.setContentPane(new JPanelImageBg("butterfly.jpg",mode));
		this.getContentPane().add(new JButton("test"));
		setSize(500,500);
		this.setVisible(true);
	}



	public static void main( String[] argv )
	{	new JPanelImageBgTest("Centre",JPanelImageBg.CENTRE);
		new JPanelImageBgTest("Texture",JPanelImageBg.TEXTURE);
	}




}

thank you very much in advance... I really don't know how to use jbuilder.. and i really need to use it for a work and the deadline is short.
__________________
printf("\n I might need you to help me tonight");
getch();
mariogarcia is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 12:06 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC