soz bout all this posting :S

i know this is a really n00b question but how do i add a black background to this prog?

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

public class CMP extends JFrame {

    public void myframe() {

        JFrame frm = new JFrame();

        frm.setBounds(0,0,800,400);
        frm.setVisible(true);

            frm.addWindowListener(new WindowAdapter() {
            public void windowClosing(WindowEvent e) {
                System.exit(0);
            }
        });

    }



    public static void main(String[] args) {

        CMP pt = new CMP();
        pt.myframe();

    }
}

setBackground(Color.black);

ive tried that several times... :S in different places but it always comes up grey :(

Have you tried:

fm.setBackground(Color.black);

yes i have tried that but nothing nappened, except you see a black flick just as the app is loading, but thats it :(

i figured it out :( all i forgot to do was this

JPanel panel = (JPanel)frm.getContentPane();

panel.setBounds(0,0,800,400);
panel.setBackground(Color.black);

thanks for the try though :)

hehe. A JPanel was my next suggestion.

lol :)

heres my next problem :S

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

public class CPB extends JFrame {

	public void myframe() {

		JFrame frm = new JFrame();
		JPanel panel = (JPanel)frm.getContentPane();

		panel.setBackground(Color.black);
		
		frm.setBounds(0,0,800,400);
		frm.setVisible(true);

				
			frm.addWindowListener(new WindowAdapter() {
			public void windowClosing(WindowEvent e) {
				System.exit(0);
			}
		});
		frm.setResizable(false);
	}

	public void paint(Graphics g) {

                         g.setColor(color.white");
		g.drawString("Text should be here :S",100,100);
	}


	public static void main(String[] args) {

		CPB cmp = new CPB();
		cmp.myframe();
	}
}

for sum reason it doesnt display the text :S n e one know...lol

This works. It's a little bit different than yours though.

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

public class CPB extends JFrame {

	public CPB() {

	Container content = getContentPane();
	setContentPane(content);
	setBackground(Color.black);
	setSize(300,300);
	setLayout(new FlowLayout());
	setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	setVisible(true);
	}

	public void paint(Graphics g) {

                g.setColor(Color.white);
		g.drawString("Text should be here :S",100,100);
	}


	public static void main(String[] args) {

		CPB cmp = new CPB();
	}
}

thanks crash ... but it is slightly different lol

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.