freelanceprogrammers.org Forum Index » Java
Inserting An Image
Joined: 31 Jan 2002
Posts: 24
Inserting An Image
Hi everyone, I was hoping some one could help me.
I am creating an application using Jbuilder 5
(professional edition) and was wondering if anyone could tell
me how to insert a picture into teh application as a
backgound.<br><br>I have done this using Jbuilder 2 before by
clicking one of the buttons in the editor toolbar but
cannot find this button in Jbuilder 5. Perhaps Borland
have not included this function in JB5 or perhaps they
are using a different button.<br><br>Any help would
be appreciated. <br><br>Thanks
Joined: 01 Feb 2002
Posts: 13
Inserting An Image
private class thePane extends JPanel<br> {<br>
public void thePane()<br> {<br> }<br> public void
paintComponent(Graphics g)<br> {<br>Image image =
Toolkit.getDefaultToolkit().getImage("/dir/imagename.jpg-or-gif");<br>g.drawImag
e(image,0,0,Iwidth,Iheight,this);<br> }<br> }
Joined: 31 Jan 2002
Posts: 24
Inserting An Image
How would I insert the insert picture code into
my application code shown below:<br><br>package
picture;<br>import java.awt.*;<br>import java.awt.event.*;<br>import
javax.swing.*;<br>import javax.swing.border.*;<br><br>public class Frame1
extends JFrame {<br> JPanel contentPane;<br> JMenuBar
jMenuBar1 = new JMenuBar();<br> JMenu jMenuFile = new
JMenu();<br> JMenuItem jMenuFileExit = new JMenuItem();<br>
JMenu jMenuHelp = new JMenu();<br> JMenuItem
jMenuHelpAbout = new JMenuItem();<br> BorderLayout borderLayout1
= new BorderLayout();<br> Border border1;<br><br>
/**Construct the frame*/<br> public Frame1() {<br>
enableEvents(AWTEvent.WINDOW_EVENT_MASK);<br> try {<br> jbInit();<br> }<br>
catch(Exception e)
{<br> e.printStackTrace();<br> }<br> }<br> /**Component
initialization*/<br> private void jbInit() throws Exception {<br>
setIconImage(Toolkit.getDefaultToolkit().createImage(Frame1.class.getResource("[
Your Icon]")));<br> contentPane = (JPanel)
this.getContentPane();<br> border1 =
BorderFactory.createLineBorder(Color.white,1);<br>
contentPane.setLayout(borderLayout1);<br>
this.setSize(new Dimension(400, 300));<br> this.setTitle("Frame
Title");<br> jMenuFile.setText("File");<br>
jMenuFileExit.setText("Exit");<br> jMenuFileExit.addActionListener(new
ActionListener() {<br> public void actionPerformed(ActionEvent e)
{<br> jMenuFileExit_actionPerformed(e);<br> }<br>
});<br> jMenuHelp.setText("Help");<br>
jMenuHelpAbout.setText("About");<br> jMenuHelpAbout.addActionListener(new
ActionListener() {<br> public void actionPerformed(ActionEvent e)
{<br> jMenuHelpAbout_actionPerformed(e);<br> }<br>
});<br> contentPane.setBorder(border1);<br>
jMenuFile.add(jMenuFileExit);<br> jMenuHelp.add(jMenuHelpAbout);<br>
jMenuBar1.add(jMenuFile);<br> jMenuBar1.add(jMenuHelp);<br>
this.setJMenuBar(jMenuBar1);<br> }<br> /**File | Exit action performed*/<br>
public void jMenuFileExit_actionPerformed(ActionEvent e)
{<br> System.exit(0);<br> }<br> /**Help | About action
performed*/<br> public void
jMenuHelpAbout_actionPerformed(ActionEvent e) {<br><br>
//System.out.println("Java Video
Shop Database System");<br>
//System.out.println("Written by: Noel Maloney");<br> }<br> /**Overridden so we
can exit when window is closed*/<br> protected void
processWindowEvent(WindowEvent e) {<br> super.processWindowEvent(e);<br> if
(e.getID() == WindowEvent.WINDOW_CLOSING) {<br>
jMenuFileExit_actionPerformed(null);<br> }<br> }<br>}<br><br>Thanks
All times are GMT
Page 1 of 1
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Freelace Website Designer - Customer web design and software building.
Booking Calendar - reservation calendar script
Land Surveying - total station instruments and equipments
China Wholesale - Electronics Products
Character Studio - Tutorials and Help
Booking Calendar - reservation calendar script
Land Surveying - total station instruments and equipments
China Wholesale - Electronics Products
Character Studio - Tutorials and Help







