Results 1 to 7 of 7

Thread: Color problem

  1. #1
    dewitrydan is offline Member
    Join Date
    Aug 2010
    Posts
    67
    Rep Power
    0

    Default Color problem

    Hey there
    I am following a tutorial and have written the following code.
    My problem:
    Background is supposed to be Pink, but its white when I run it.
    So how do I get it pink?

    bucky class, (contains main method)
    Java Code:
    import java.awt.Color;
    import java.awt.DisplayMode;
    import java.awt.Font;
    import java.awt.Graphics;
    import javax.swing.JFrame;
    
    public class bucky extends JFrame {
    
        public static void main(String[] args) {
            DisplayMode dm = new DisplayMode(800, 600, 16, DisplayMode.REFRESH_RATE_UNKNOWN);
            bucky b = new bucky();
            b.run(dm);
        }
    
        public void run(DisplayMode dm) {
            setBackground(Color.PINK);
            setForeground(Color.WHITE);
            setFont(new Font("Arial", Font.PLAIN, 24));
    
            Screen s = new Screen();
            try {
                s.setFullScreen(dm, this);
                try {
                    Thread.sleep(5000);
                } catch (Exception ex) {
                }
            } finally {
                s.restoreScreen();
            }
        }
    
        public void paint(Graphics g) {
            g.drawString("This is gonna be awesome", 200, 200);
        }
    }

    Screen class
    Java Code:
    import java.awt.*;
    import javax.swing.JFrame;
    
    public class Screen {
    
        private GraphicsDevice vc;
    
        public Screen() {
            GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment();
            vc = env.getDefaultScreenDevice();
        }
    
        public void setFullScreen(DisplayMode dm, JFrame window) {
            window.setUndecorated(true);
            window.setResizable(false);
            vc.setFullScreenWindow(window);
    
            if (dm != null && vc.isDisplayChangeSupported()) {
                try {
                    vc.setDisplayMode(dm);
                } catch (Exception e) {
                }
            }
        }
    
        public Window getFullScreenWindow() {
            return vc.getFullScreenWindow();
        }
    
        public void restoreScreen() {
            Window w = vc.getFullScreenWindow();
            if (w != null) {
                w.dispose();
            }
            vc.setFullScreenWindow(null);
        }
    }
    I would greatly appreciate it if you could help me :D

  2. #2
    alacn's Avatar
    alacn is offline Senior Member
    Join Date
    Jun 2010
    Location
    UK. near London
    Posts
    118
    Rep Power
    0

    Default

    prolly problem is gotta set your jframe to opaque setOpaque(true);
    Teaching myself java so that i can eventually join the industry! Started in June 2010

  3. #3
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

  5. #5
    dewitrydan is offline Member
    Join Date
    Aug 2010
    Posts
    67
    Rep Power
    0

    Default

    I ran it on my desktop rather than my laptop and it works now :S
    thanks anwayz!

  6. #6
    DarrylBurke's Avatar
    DarrylBurke is online now Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,236
    Rep Power
    19

    Default

    That must be one museum piece of a laptop

  7. #7
    alacn's Avatar
    alacn is offline Senior Member
    Join Date
    Jun 2010
    Location
    UK. near London
    Posts
    118
    Rep Power
    0

    Default

    doesnt work with my laptop either although i have the screen transfered over to a big tv and dont use the main monitor
    Teaching myself java so that i can eventually join the industry! Started in June 2010

Similar Threads

  1. if (...) ... won't set color
    By livingdog in forum New To Java
    Replies: 6
    Last Post: 04-11-2010, 03:59 PM
  2. RGB from Color Name
    By winklerd in forum Advanced Java
    Replies: 5
    Last Post: 03-26-2010, 05:16 PM
  3. [COLOR="Navy"]execute .bat file in mysql [/COLOR]
    By msankar.ravi in forum Networking
    Replies: 0
    Last Post: 02-24-2010, 04:27 AM
  4. Color gradient
    By Java Tip in forum java.awt
    Replies: 0
    Last Post: 06-21-2008, 08:50 PM
  5. A bit of color!
    By tim in forum Java 2D
    Replies: 8
    Last Post: 02-11-2008, 11:57 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
  •