Estou estudando Swing e copiei uma classe do livro, mas não intendi por que ela não funciona direito. Deveria aparecer um frame interno porém ele não aparece. Eis meu código
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class SimpleInternalFrame extends Frame implements ActionListener{
private JButton openButton, winButton, javaButton, motifButton;
private JLayeredPane desktop;
JInternalFrame internalFrame;
public SimpleInternalFrame() {
super("Internal Frame Demo");
setSize(500, 400);
openButton = new JButton("Open");
winButton = new JButton("Windows");
javaButton = new JButton("Metal");
motifButton = new JButton("Motif");
Panel p = new Panel();
p.add(openButton);
p.add(winButton);
p.add(javaButton);
p.add(motifButton);
add(p, BorderLayout.SOUTH);
addWindowListener(new BasicWindowMonitor());
openButton.addActionListener(this);
LnFListener lnf = new LnFListener(this);
winButton.addActionListener(lnf);
javaButton.addActionListener(lnf);
motifButton.addActionListener(lnf);
desktop = new JDesktopPane();
desktop.setOpaque(true);
add(desktop, BorderLayout.CENTER);
}
public void actionPerformed(ActionEvent e) {
if((internalFrame == null) || (internalFrame.isClosed())) {
internalFrame = new JInternalFrame("Internal Frame", true, true, true, true);
internalFrame.setBounds(50, 50, 200, 100);
desktop.add(internalFrame, new Integer(1));
}
}
public static void main(String[] args) {
SimpleInternalFrame sif = new SimpleInternalFrame();
sif.setVisible(true);
}
}
import java.awt.event.*;
import java.awt.Window;
public class BasicWindowMonitor extends WindowAdapter{
public void windowClosing(WindowEvent e) {
Window w = e.getWindow();
w.setVisible(false);
w.dispose();
System.exit(0);
}
}
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class LnFListener implements ActionListener{
private Frame frame;
public LnFListener(Frame f) {
frame = f;
}
public void actionPerformed(ActionEvent e) {
String lnfName = null;
if(e.getActionCommand().equals("Metal")) lnfName = "javax.swing.plaf.metal.MetalLookAndFeel";
else if(e.getActionCommand().equals("Motif")) lnfName = "com.sun.java.swing.plaf.motif.MotifLookAndFeel";
else lnfName = "com.sun.java.swing.plaf.windows.WindowsLookAndFeel";
try {
UIManager.setLookAndFeel(lnfName);
SwingUtilities.updateComponentTreeUI(frame);
}
catch(UnsupportedLookAndFeelException ex1) {
System.err.println("Unsipported LookAndFeel: " + lnfName);
}
catch(ClassNotFoundException ex2) {
System.err.println("LookAndFeel class not found: " + lnfName);
}
catch(InstantiationException ex3) {
System.err.println("Could not loaadLookAndFeel: " + lnfName);
}
catch(IllegalAccessException ex4) {
System.err.println("Cannot use loaadLookAndFeel: " + lnfName);
}
}
}