n00b problem

Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Apr 2005
Posts: 16
Reputation: bob901 is an unknown quantity at this point 
Solved Threads: 0
bob901's Avatar
bob901 bob901 is offline Offline
Newbie Poster

n00b problem

 
0
  #1
May 7th, 2005
soz bout all this posting

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

}
}
Reply With Quote Quick reply to this message  
Join Date: Jun 2004
Posts: 2,108
Reputation: server_crash is on a distinguished road 
Solved Threads: 18
server_crash server_crash is offline Offline
Postaholic

Re: n00b problem

 
0
  #2
May 7th, 2005
setBackground(Color.black);
Reply With Quote Quick reply to this message  
Join Date: Apr 2005
Posts: 16
Reputation: bob901 is an unknown quantity at this point 
Solved Threads: 0
bob901's Avatar
bob901 bob901 is offline Offline
Newbie Poster

Re: n00b problem

 
0
  #3
May 7th, 2005
ive tried that several times... in different places but it always comes up grey
Reply With Quote Quick reply to this message  
Join Date: Jun 2004
Posts: 2,108
Reputation: server_crash is on a distinguished road 
Solved Threads: 18
server_crash server_crash is offline Offline
Postaholic

Re: n00b problem

 
0
  #4
May 7th, 2005
Have you tried:

  1. fm.setBackground(Color.black);
Reply With Quote Quick reply to this message  
Join Date: Apr 2005
Posts: 16
Reputation: bob901 is an unknown quantity at this point 
Solved Threads: 0
bob901's Avatar
bob901 bob901 is offline Offline
Newbie Poster

Re: n00b problem

 
0
  #5
May 8th, 2005
yes i have tried that but nothing nappened, except you see a black flick just as the app is loading, but thats it
Reply With Quote Quick reply to this message  
Join Date: Apr 2005
Posts: 16
Reputation: bob901 is an unknown quantity at this point 
Solved Threads: 0
bob901's Avatar
bob901 bob901 is offline Offline
Newbie Poster

Re: n00b problem

 
0
  #6
May 8th, 2005
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
Reply With Quote Quick reply to this message  
Join Date: Jun 2004
Posts: 2,108
Reputation: server_crash is on a distinguished road 
Solved Threads: 18
server_crash server_crash is offline Offline
Postaholic

Re: n00b problem

 
0
  #7
May 8th, 2005
hehe. A JPanel was my next suggestion.
Reply With Quote Quick reply to this message  
Join Date: Apr 2005
Posts: 16
Reputation: bob901 is an unknown quantity at this point 
Solved Threads: 0
bob901's Avatar
bob901 bob901 is offline Offline
Newbie Poster

Re: n00b problem

 
0
  #8
May 8th, 2005
lol

heres my next problem

  1. import java.awt.*;
  2. import java.awt.event.*;
  3. import javax.swing.*;
  4.  
  5. public class CPB extends JFrame {
  6.  
  7. public void myframe() {
  8.  
  9. JFrame frm = new JFrame();
  10. JPanel panel = (JPanel)frm.getContentPane();
  11.  
  12. panel.setBackground(Color.black);
  13.  
  14. frm.setBounds(0,0,800,400);
  15. frm.setVisible(true);
  16.  
  17.  
  18. frm.addWindowListener(new WindowAdapter() {
  19. public void windowClosing(WindowEvent e) {
  20. System.exit(0);
  21. }
  22. });
  23. frm.setResizable(false);
  24. }
  25.  
  26. public void paint(Graphics g) {
  27.  
  28. g.setColor(color.white");
  29. g.drawString("Text should be here :S",100,100);
  30. }
  31.  
  32.  
  33. public static void main(String[] args) {
  34.  
  35. CPB cmp = new CPB();
  36. cmp.myframe();
  37. }
  38. }
  39.  

for sum reason it doesnt display the text n e one know...lol
Reply With Quote Quick reply to this message  
Join Date: Jun 2004
Posts: 2,108
Reputation: server_crash is on a distinguished road 
Solved Threads: 18
server_crash server_crash is offline Offline
Postaholic

Re: n00b problem

 
0
  #9
May 8th, 2005
This works. It's a little bit different than yours though.

  1. import java.awt.*;
  2. import java.awt.event.*;
  3. import javax.swing.*;
  4.  
  5. public class CPB extends JFrame {
  6.  
  7. public CPB() {
  8.  
  9. Container content = getContentPane();
  10. setContentPane(content);
  11. setBackground(Color.black);
  12. setSize(300,300);
  13. setLayout(new FlowLayout());
  14. setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  15. setVisible(true);
  16. }
  17.  
  18. public void paint(Graphics g) {
  19.  
  20. g.setColor(Color.white);
  21. g.drawString("Text should be here :S",100,100);
  22. }
  23.  
  24.  
  25. public static void main(String[] args) {
  26.  
  27. CPB cmp = new CPB();
  28. }
  29. }
Reply With Quote Quick reply to this message  
Join Date: Apr 2005
Posts: 16
Reputation: bob901 is an unknown quantity at this point 
Solved Threads: 0
bob901's Avatar
bob901 bob901 is offline Offline
Newbie Poster

Re: n00b problem

 
0
  #10
May 8th, 2005
thanks crash ... but it is slightly different lol
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Java Forum


Views: 1587 | Replies: 9
Thread Tools Search this Thread



Tag cloud for Java
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC