Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

A problem; please help.
The picture will not appear, but why??????????
When I use a simple applet, it works.

----------------------------------------------------------------------------
---------------------------------------------
package test;

public class TestClass
{

public TestClass()
{
}

public static void main(String[] args)
{
TestClass testClass = new TestClass();
TestFrame test = new TestFrame();
test.show();
}

}
----------------------------------------------------------------------------
-------------------------------------------------

package test;

import java.awt.*;
import javax.swing.*;

public class TestFrame extends JFrame
{
JButton jButton1 = new JButton();

public TestFrame()
{
try
{
jbInit();
}
catch(Exception e)
{
e.printStackTrace();
}
}

private void jbInit() throws Exception
{
jButton1.setText("jButton1");
jButton1.setBounds(new Rectangle(67, 37, 182, 114));
this.getContentPane().setLayout(null);
this.setSize(new Dimension(300, 300));
this.getContentPane().add(jButton1, null);
}

// ????????????????????????????
// ????????????????????????????
// ????????????????????????????
private void picture()
{
ImageIcon pic = new ImageIcon("images/duke.gif");
jButton1.setIcon(pic);
}

}



Report this thread to moderator Post Follow-up to this message
Old Post
H. Sommers
12-30-04 09:00 PM


Re: A problem; please help.
"H. Sommers" <H.Sommers@freeler.nl> wrote in message
news:c347a$41d40a21$513a6d81$5894@news1.zonnet.nl...
> The picture will not appear, but why??????????
> When I use a simple applet, it works.
>
[...]
>  private void picture()
>  {
>    ImageIcon pic = new ImageIcon("images/duke.gif");
>    jButton1.setIcon(pic);
>  }
[...]

It could have something to do with the fact that you never call the picture
method.



Report this thread to moderator Post Follow-up to this message
Old Post
Ryan Stewart
12-30-04 09:00 PM


Re: A problem; please help.
On Thu, 30 Dec 2004 15:01:22 +0100, H. Sommers wrote:

>   private void picture()
>   {
>     ImageIcon pic = new ImageIcon("images/duke.gif");
>     jButton1.setIcon(pic);
>   }

You are working blind here, try this instead..

URL imageURL = this.getClass().getResource( "images/dike.gif" );
System.out.println( "imageURL: " + imageURL );
ImageIcon pic = new ImageIcon( imageURL );
...

BTW - You're subject.. 'A problem; please help' is an extremely
poor one, something like 'ImageIcon does not appear in application'
would be much better.

HTH

--
Andrew Thompson
http://www.PhySci.org/codes/  Web & IT Help
http://www.PhySci.org/  Open-source software suite
http://www.1point1C.org/  Science & Technology
http://www.LensEscapes.com/  Images that escape the mundane

Report this thread to moderator Post Follow-up to this message
Old Post
Andrew Thompson
12-30-04 09:00 PM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

Java Help archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 08:52 AM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.