How too.. ??

H

H. Sommers

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

}
 
A

anonymous

H. Sommers said:
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);
}

}
Have you tried calling picture()? Like this:
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);
picture();
}
 
N

newB

so far, u've defined the picture() function, but u didnt call the
function.
post up the codes of ur applet, too. i guess they're different
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,780
Messages
2,569,609
Members
45,254
Latest member
Top Crypto TwitterChannel

Latest Threads

Top