954,518 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

n00b problem

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();

}
}

bob901
Newbie Poster
16 posts since Apr 2005
Reputation Points: 10
Solved Threads: 0
 

setBackground(Color.black);

server_crash
Postaholic
2,111 posts since Jun 2004
Reputation Points: 113
Solved Threads: 20
 

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

bob901
Newbie Poster
16 posts since Apr 2005
Reputation Points: 10
Solved Threads: 0
 

Have you tried:

fm.setBackground(Color.black);
server_crash
Postaholic
2,111 posts since Jun 2004
Reputation Points: 113
Solved Threads: 20
 

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

bob901
Newbie Poster
16 posts since Apr 2005
Reputation Points: 10
Solved Threads: 0
 

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 :)

bob901
Newbie Poster
16 posts since Apr 2005
Reputation Points: 10
Solved Threads: 0
 

hehe. A JPanel was my next suggestion.

server_crash
Postaholic
2,111 posts since Jun 2004
Reputation Points: 113
Solved Threads: 20
 

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

bob901
Newbie Poster
16 posts since Apr 2005
Reputation Points: 10
Solved Threads: 0
 

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();
	}
}
server_crash
Postaholic
2,111 posts since Jun 2004
Reputation Points: 113
Solved Threads: 20
 

thanks crash ... but it is slightly different lol

bob901
Newbie Poster
16 posts since Apr 2005
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You