import java.awt.*;
import java.awt.image.*;
import java.awt.event.*;
import javax.imageio.*;
import java.lang.*;
import java.io.*;
import javax.swing.*;
public class MainClass extends Component{
private Image bg;
private ImageIcon newgame;
private ImageIcon quit;
private ImageIcon options;
private JButton bquit;
private JButton boptions;
private JButton bnewgame;
private static Container pane; //Container
public void loadImage() {
try {
bg=ImageIO.read(new File("bg1.png"));
} catch (Exception e) {
}
if(bg!=null)
repaint();
}
public void paint(Graphics g) {
g.drawImage(bg,0,0,null);
}
public void imageButtons(JFrame f) {
try {
quit= new ImageIcon("quit.png");
options=new ImageIcon("options.png");
newgame= new ImageIcon("newgame.png");
}catch(Exception e){}
bnewgame= new JButton(newgame);
boptions= new JButton(options);
bquit= new JButton(quit);
bnewgame.setBounds(150,100,400,89);
boptions.setBounds(150,200,400,89);
bquit.setBounds(150,300,400,89);
pane.add(bquit);
pane.add(boptions);
pane.add(bnewgame);
}
public static void main(String args[]) {
MainClass o=new MainClass();
FullScreen fs=new FullScreen();
JFrame f1=new JFrame("TITLE");
pane=f1.getContentPane();
fs.fullScreenIt(f1);
pane.add(o);
f1.setVisible(true);
o.loadImage();
o.imageButtons(f1);
}
}
The Fullscreen is another class which gives a full screen Frame. JButton have ImageIcon on them. bg1.png is a background image Problem is these JButton become visible only when mouse hovers else they do not appear.