Results 1 to 3 of 3
  1. #1
    Join Date
    May 2011
    Location
    Herentals, Belgium
    Posts
    14
    Rep Power
    0

    Default No background in FESM

    Ok so here is the problem:
    When I execute this little program, it draws the text "Goodbye cruel world" to the screen in a red color. However, I have set the background to black, but isn't shown.

    All I get is this:
    No background in FESM-fullscreentest.jpg

    Anybody knows what happend to my background??

    SimpleScreenManager.java


    /**
    *
    * @author inf51
    *
    */

    import java.awt.*;
    import javax.swing.*;

    /**
    * The SimpleScreenManager class manages initializing and displaying
    * full screen graphics modes.
    */

    public class SimpleScreenManager {

    private GraphicsDevice device;

    /**
    * Creates a new SimpleScreenManager object.
    */
    public SimpleScreenManager(){
    GraphicsEnvironment environment =
    GraphicsEnvironment.getLocalGraphicsEnvironment();
    device = environment.getDefaultScreenDevice();
    }


    /**
    * Enters full screen mode and changes the display mode.
    */
    public void setFullScreen(DisplayMode displayMode, JFrame window){
    window.setUndecorated(true);
    window.setResizable(false);

    device.setFullScreenWindow(window);
    if(displayMode != null && device.isDisplayChangeSupported())
    {
    try{
    device.setDisplayMode(displayMode);
    }
    catch (IllegalArgumentException ex){
    // ignore - illegal mode for this device
    }
    }
    }


    /**
    * Returns the window currently used in full screen mode
    */
    public Window getFullScreenWindow(){
    return device.getFullScreenWindow();
    }


    /**
    * Restores the screen's display mode.
    */
    public void restoreScreen(){
    Window window = device.getFullScreenWindow();
    if (window != null)
    window.dispose();
    device.setFullScreenWindow(null);
    }

    }


    FullScreenTest.java

    import java.awt.*;

    import javax.swing.JFrame;

    public class FullScreenTest extends JFrame {

    private static final long DEMO_TIME = 3000;

    public static void main(String[] args){

    DisplayMode displayMode =
    new DisplayMode(1280, 1024, 32, 60);
    FullScreenTest test = new FullScreenTest();
    test.run(displayMode);
    }


    public void run(DisplayMode displayMode){
    setBackground(Color.black);
    setForeground(Color.red);
    setFont(new Font("Dialog", Font.PLAIN, 24));

    SimpleScreenManager screen = new SimpleScreenManager();
    try{
    screen.setFullScreen(displayMode, this);
    try{
    Thread.sleep(DEMO_TIME);
    }
    catch(InterruptedException ex){}
    }
    finally{
    screen.restoreScreen();
    }
    }

    public void paint(Graphics g){
    g.drawString("Godbye cruel World", 20, 50);
    }
    }
    Enjoy your milk!! :cool:

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    14,299
    Blog Entries
    7
    Rep Power
    24

    Default

    Drawing glyphs (for text drawing) only draws the glyphs in the forground colour; no background colour is involved; you have to set the rectangular area to the background yourself by filling the rectangle.

    kind regards,

    Jos
    The only person who got everything done by Friday was Robinson Crusoe.

  3. #3
    Join Date
    May 2011
    Location
    Herentals, Belgium
    Posts
    14
    Rep Power
    0

    Default

    Ok that was kind of easy...

    Dank u Jos!!
    Enjoy your milk!! :cool:

Similar Threads

  1. How to Run a .exe in background???
    By jazz2k8 in forum New To Java
    Replies: 9
    Last Post: 01-21-2011, 12:27 PM
  2. Question abt background.
    By [RaIdEn] in forum New To Java
    Replies: 2
    Last Post: 12-05-2010, 03:40 AM
  3. Replies: 4
    Last Post: 11-12-2010, 10:31 AM
  4. Background in JFrame ( GUI).
    By Twister03 in forum AWT / Swing
    Replies: 2
    Last Post: 03-12-2009, 04:24 AM
  5. Background image
    By leiferouis in forum New To Java
    Replies: 9
    Last Post: 03-08-2009, 06:49 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •