943,985 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Unsolved
  • Views: 1691
  • Java RSS
May 7th, 2005
0

n00b problem

Expand Post »
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();

}
}
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
bob901 is offline Offline
16 posts
since Apr 2005
May 7th, 2005
0

Re: n00b problem

setBackground(Color.black);
Reputation Points: 113
Solved Threads: 19
Postaholic
server_crash is offline Offline
2,108 posts
since Jun 2004
May 7th, 2005
0

Re: n00b problem

ive tried that several times... in different places but it always comes up grey
Reputation Points: 10
Solved Threads: 0
Newbie Poster
bob901 is offline Offline
16 posts
since Apr 2005
May 7th, 2005
0

Re: n00b problem

Have you tried:

Java Syntax (Toggle Plain Text)
  1. fm.setBackground(Color.black);
Reputation Points: 113
Solved Threads: 19
Postaholic
server_crash is offline Offline
2,108 posts
since Jun 2004
May 8th, 2005
0

Re: n00b problem

yes i have tried that but nothing nappened, except you see a black flick just as the app is loading, but thats it
Reputation Points: 10
Solved Threads: 0
Newbie Poster
bob901 is offline Offline
16 posts
since Apr 2005
May 8th, 2005
0

Re: n00b problem

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
Reputation Points: 10
Solved Threads: 0
Newbie Poster
bob901 is offline Offline
16 posts
since Apr 2005
May 8th, 2005
0

Re: n00b problem

hehe. A JPanel was my next suggestion.
Reputation Points: 113
Solved Threads: 19
Postaholic
server_crash is offline Offline
2,108 posts
since Jun 2004
May 8th, 2005
0

Re: n00b problem

lol

heres my next problem

Java Syntax (Toggle Plain Text)
  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
Reputation Points: 10
Solved Threads: 0
Newbie Poster
bob901 is offline Offline
16 posts
since Apr 2005
May 8th, 2005
0

Re: n00b problem

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

Java Syntax (Toggle Plain Text)
  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. }
Reputation Points: 113
Solved Threads: 19
Postaholic
server_crash is offline Offline
2,108 posts
since Jun 2004
May 8th, 2005
0

Re: n00b problem

thanks crash ... but it is slightly different lol
Reputation Points: 10
Solved Threads: 0
Newbie Poster
bob901 is offline Offline
16 posts
since Apr 2005

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Java Forum Timeline: Importance of checking the current thread?
Next Thread in Java Forum Timeline: Please anyone help tweak my code





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC