0

I'm trying to get look and feel to work with no success. I'm creating a Frame and painting an Applet inside it. No exceptions are thrown when I execute the program.

AppScreen < Applet:

public class AppScreen extends Applet implements Runnable {

    protected AppFrame frame;
    protected Graphics appGraphics;

    public void createFrame(int width, int height) throws Exception {
        UIManager.setLookAndFeel("org.jvnet.substance.skin.SubstanceRavenGraphiteGlassLookAndFeel");
        frame = new AppFrame(this, width, height);
        appGraphics = getAppComponent().getGraphics();
        startThread(this, 1);
    }

    public void startThread(Runnable runnable, int i) {
        final Thread thread = new Thread(runnable);
        thread.start();
        thread.setPriority(i);
    }

    public Component getAppComponent() {
        if (frame != null)
            return frame;
        else
            return this;
    }
}

AppFrame < Frame:

public final class AppFrame extends Frame {

    private final AppScreen screen;

    public AppFrame(AppScreen screen, int width, int height) {
        this.screen = screen;
        setBounds(500, 500, width, height);
        setResizable(false);
        setVisible(true);
        toFront();
    }

    @Override
    public final void update(Graphics g) {
        screen.update(g);
    }

    @Override
    public final void paint(Graphics g) {
        screen.paint(g);
    }

}

For instance, I call createFrame(width, height) method.

mKorbel
  • 109,525
  • 20
  • 134
  • 319
Snake
  • 43
  • 4
  • L&F is Swing concept and pertains only to Swing components. java.awt.Applet and java.awt.Frame are not Swing components and will always be rendered using native UI system. – Oleg Estekhin Jun 18 '14 at 10:14
  • @OlegEstekhin Is there a way I can use to get around it. Like creating a javax.swing.JFrame and painting the applet inside it? – Snake Jun 18 '14 at 10:17
  • 2
    Use Swing components instead of AWT(`Applet`->`JApplet`, `Frame`->`JFrame`...) – alex2410 Jun 18 '14 at 11:37
  • @alex2410 should be an answer because AWT haven't access to L&F, is strictly based on peers from Native OS – mKorbel Jun 18 '14 at 11:49
  • Use Swing components as said by others and set L&F in your main method before creating any component. – spgodara Jun 19 '14 at 05:06
  • *"I'm creating a Frame and painting an Applet inside it."* That is a horrid way to go about things. Code the GUI as a `JPanel` that can be added to a frame or applet (then avoid applets like the plague). – Andrew Thompson Jun 20 '14 at 09:31

0 Answers0