import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
class BackgroundFrame extends JFrame implements ActionListener {
JDesktopPane desktop;
ImageIcon icon;
BackgroundFrame() {
icon = new ImageIcon("C:\\Dokumente und Einstellungen\\All Users\\Dokumente\\Eigene Bilder\\Beispielbilder\\Sonnenuntergang.jpg");
desktop = new JDesktopPane() {
@Override
public void paint( Graphics g )
{
g.drawImage(icon.getImage(), 0, 0, getSize().width, getSize().height, null);
super.paint(g);
}
};
desktop.setOpaque(false);
desktop.setPreferredSize(new Dimension(800, 534));
setContentPane(desktop);
setJMenuBar(createMenuBar());
}
public static void main(String[] args) {
BackgroundFrame frame = new BackgroundFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.pack();
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}
protected void createFrame() {
MyInternalFrame frame = new MyInternalFrame();
frame.setVisible(true); //necessary as of 1.3
desktop.add(frame);
try {
frame.setSelected(true);
} catch (java.beans.PropertyVetoException e) {}
}
protected JMenuBar createMenuBar() {
JMenuBar menuBar = new JMenuBar();
//Set up the lone menu.
JMenu menu = new JMenu("Document");
menu.setMnemonic(KeyEvent.VK_D);
menuBar.add(menu);
//Set up the first menu item.
JMenuItem menuItem = new JMenuItem("New");
menuItem.setMnemonic(KeyEvent.VK_N);
menuItem.setAccelerator(KeyStroke.getKeyStroke(
KeyEvent.VK_N, ActionEvent.ALT_MASK));
menuItem.setActionCommand("new");
menuItem.addActionListener(this);
menu.add(menuItem);
//Set up the second menu item.
menuItem = new JMenuItem("Quit");
menuItem.setMnemonic(KeyEvent.VK_Q);
menuItem.setAccelerator(KeyStroke.getKeyStroke(
KeyEvent.VK_Q, ActionEvent.ALT_MASK));
menuItem.setActionCommand("quit");
menuItem.addActionListener(this);
menu.add(menuItem);
return menuBar;
}
public void actionPerformed(ActionEvent e) {
if ("new".equals(e.getActionCommand())) { //new
createFrame();
} else { //quit
quit();
}
}
protected void quit() {
System.exit(0);
}
}