Logo 
Search:

Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

Inserting An Image

  Asked By: Bastet    Date: Sep 09    Category: Java    Views: 1164
  

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.

Share: 

 

2 Answers Found

 
Answer #1    Answered By: Jonathan Harrison     Answered On: Sep 09

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);

 
Answer #2    Answered By: Eileen Carr     Answered On: Sep 09

How would I insert  the insert picture  code into
my application  code shown below:package
picture;import java.awt.*;import java.awt.event.*;import
javax.swing.*;import javax.swing.border.*;public class Frame1
extends JFrame { JPanel contentPane; JMenuBar
jMenuBar1 = new JMenuBar(); JMenu jMenuFile = new
JMenu(); JMenuItem jMenuFileExit = new JMenuItem();
JMenu jMenuHelp = new JMenu(); JMenuItem
jMenuHelpAbout = new JMenuItem(); BorderLayout borderLayout1
= new BorderLayout(); Border border1;
/**Construct the frame*/ public Frame1() {
enableEvents(AWTEvent.WINDOW_EVENT_MASK); try { jbInit(); }
catch(Exception e)
{ e.printStackTrace(); } } /**Component
initialization*/ private void jbInit() throws Exception {
setIconImage(Toolkit.getDefaultToolkit().createImage(Frame1.class.getResource("[\
Your Icon]"))); contentPane = (JPanel)
this.getContentPane(); border1 =
BorderFactory.createLineBorder(Color.white,1);
contentPane.setLayout(borderLayout1);
this.setSize(new Dimension(400, 300)); this.setTitle("Frame
Title"); jMenuFile.setText("File");
jMenuFileExit.setText("Exit"); jMenuFileExit.addActionListener(new
ActionListener() { public void actionPerformed(ActionEvent e)
{ jMenuFileExit_actionPerformed(e); }
}); jMenuHelp.setText("Help");
jMenuHelpAbout.setText("About"); jMenuHelpAbout.addActionListener(new
ActionListener() { public void actionPerformed(ActionEvent e)
{ jMenuHelpAbout_actionPerformed(e); }
}); contentPane.setBorder(border1);
jMenuFile.add(jMenuFileExit); jMenuHelp.add(jMenuHelpAbout);
jMenuBar1.add(jMenuFile); jMenuBar1.add(jMenuHelp);
this.setJMenuBar(jMenuBar1); } /**File | Exit action performed*/
public void jMenuFileExit_actionPerformed(ActionEvent e)
{ System.exit(0); } /**Help | About action
performed*/ public void
jMenuHelpAbout_actionPerformed(ActionEvent e) {
//System.out.println("Java Video
Shop Database System");
//System.out.println("Written by: Noel Maloney"); } /**Overridden so we
can exit when window is closed*/ protected void
processWindowEvent(WindowEvent e) { super.processWindowEvent(e); if
(e.getID() == WindowEvent.WINDOW_CLOSING) {
jMenuFileExit_actionPerformed(null); } }}

 
Didn't find what you were looking for? Find more on Inserting An Image Or get search suggestion and latest updates.




Tagged: