Hello, I have two problems. First, I am trying to have a set background image that displays with two jbuttons on the bottom. My error is that when the back ground image is displayed it hides the buttons (until you mouse over them). Second, I want the buttons on the bottom of the frame. Thanks for any help.
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import java.util.*;
public class Greeting extends JFrame {
private JButton startButton;
private JButton exitButton;
private Image background;
public JButton getStartButton() { return startButton; }
public JButton getExitButton() { return exitButton; }
public Greeting(String title) {
super(title);
setDefaultCloseOperation(EXIT_ON_CLOSE);
setSize(800,600);
show();
background = Toolkit.getDefaultToolkit().getImage("island.jpg");
GridBagLayout layout = new GridBagLayout();
GridBagConstraints layoutConstraints = new GridBagConstraints();
setLayout(layout);
startButton = new JButton("Start");
layoutConstraints.gridx = 3;
layoutConstraints.gridy = 0;
layoutConstraints.gridwidth = 1;
layoutConstraints.gridheight = 1;
layoutConstraints.fill = GridBagConstraints.BOTH;
layoutConstraints.insets = new Insets(10, 10, 10, 10);
layoutConstraints.anchor = GridBagConstraints.PAGE_END;
layoutConstraints.weightx = 0.0;
layoutConstraints.weighty = 0.0;
layout.setConstraints(startButton, layoutConstraints);
add(startButton);
exitButton = new JButton("Exit");
layoutConstraints.gridx = 5;
layoutConstraints.gridy = 2;
layoutConstraints.gridwidth = 1;
layoutConstraints.gridheight = 1;
layoutConstraints.fill = GridBagConstraints.BOTH;
layoutConstraints.insets = new Insets(10, 10, 10, 10);
layoutConstraints.anchor = GridBagConstraints.LAST_LINE_END;
layoutConstraints.weightx = 0.0;
layoutConstraints.weighty = 0.0;
layout.setConstraints(exitButton, layoutConstraints);
add(exitButton);
}
public void paint(Graphics g) {
g.drawImage(background, 0, 0, null);}
public static void main(String args[]) {
Greeting frame = new Greeting("Greeting");
frame.setVisible(true);
}
}