HI, i've got this problem.
My program doesnt show button on startup(but it does show it when i move my cursor over it).
What do i have to do that it will display button on startup?
/*
* PrikazOzadja.java
*
* Created on Sreda, 18 julij 2007, 18:29
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/
package knjiga;
/**
*
* @author Bojevnik
*/
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
import java.util.*;
import java.awt.geom.*;
import javax.sound.sampled.*;
import java.io.*;
import javax.sound.midi.*;
import java.net.*;
import javax.swing.*;
public class PrikazOzadja extends JApplet{
int width;
int height;
Image img;
JButton test = new JButton("TEST");
/** Creates a new instance of PrikazOzadja */
public PrikazOzadja() {
}
public void init(){
setSize(500,500);
img= getImage(getFURL("D:/ozadjeTest.jpg"));
setLayout(null);
test.setBounds(100,100,100,100);
//test.grabFocus();
add(test);
test.setFocusPainted(true);
}
public void paint(Graphics g){
width = getSize().width;
height = getSize().height;
Graphics2D g2d = (Graphics2D) g;
g2d.drawImage(img,0, 0, width, height, this);
}
public URL getURL(String filename){
URL u = null;
try{
u = getClass().getResource(filename);
if(u==null) throw new Exception("url je null");
}
catch(Exception ex){
JOptionPane.showMessageDialog(this,ex.getMessage());
}
return u;
}
private URL getFURL(String filename){
File im=new File(filename);
URL u=null;
try{
u=im.toURL();
}
catch(Exception ex){
JOptionPane.showMessageDialog(this,ex.getMessage());
}
return u;
}
}