problem in appearance of otherbuttons, the selected colour and label

hi guys

when I have runned this program in an applet application

only the last button which is appear as 9 appeared

only the standard colour has appeared for me

observeing I used these objects

pane.setBackground(java.awt.Color.red);

setBackground(Color.white);}

and the Label has not appeared in the application

I would be thankfull of anyone that help me

import java.awt.*;

import java.applet.*;

import java.awt.event.*;

import javax.swing.*;

public class Applet1 extends JApplet {

public void init() {

setBackground(Color.yellow);

JLabel hellolabel=new JLabel("google");

hellolabel.setToolTipText("is an engine search ");

java.awt.Container contentPane=getContentPane();

contentPane.setBackground(java.awt.Color.green);

contentPane.add(hellolabel);

contentPane.add(new Label("Text string"));

contentPane.add( hellolabel );

contentPane.add(new Label("\n"+"Text string "+"/t"));

contentPane.add(new Label("Text "+" /t "));

for(int i=0;i<10;i++){

JButton ok=new JButton( "" +i );

Container pane=getContentPane();

pane.add(ok);

pane.setBackground(java.awt.Color.red);

setBackground(Color.white);}

setVisible(true);}

public static void main (String [] args){

Applet1 van=new Applet1();

}}

[1401 byte] By [vanpersiea] at [2007-11-26 15:59:08]
# 1
KISS, or in other wordsWALK before you RUN1. try creating a JPanel, setting it's background and then putting it in a frame2. same as 1, but with a JLabel3. same as 1, but with a JButtonwhen you've done that, come back with more questions
tjacobs01a at 2007-7-8 22:20:20 > top of Java-index,Desktop,Core GUI APIs...
# 2

thank you for your help firstly

I have tried to do your first stepin the followingprogram:-

import java.awt.Color.*;

import java.awt .*;

import javax.swing.*;

public class sannaa extends JFrame {

publicsannaa() {

JFrame frame=new JFrame();

Container contentPane=getContentPane();

contentPane.setBackground( Color.magenta);

JPanel panel=new JPanel();

contentPane.add(panel);

setVisible(true);}

public static void main (String [] args){

sannaa van=new sannaa();}}

The normal question here:-

why the background color dissappeared after adding JPanel to the frame?

vanpersiea at 2007-7-8 22:20:20 > top of Java-index,Desktop,Core GUI APIs...
# 3
Because you added another component to the content pane and that component doesn't have the magenta background?
kirillga at 2007-7-8 22:20:20 > top of Java-index,Desktop,Core GUI APIs...
# 4

ok thanks

But whythe panel disappearing?

Ihave created the following programm and the background colour appearance problem is solved

import java.awt.Color.*;

import java.awt .*;

import javax.swing.*;

public class sannaa extends JFrame {

public sannaa() {

JFrame frame=new JFrame();

Container contentPane=getContentPane();

contentPane.setBackground( Color.magenta);

JPanel panel=new JPanel( );

contentPane.add(panel);

contentPane.setSize(200,200);

panel.setBackground( Color.magenta);

setVisible(true);}

public static void main (String [] args){

sannaa van=new sannaa();

}}

My new question is :-

Whythe panel disappearing?

vanpersiea at 2007-7-8 22:20:20 > top of Java-index,Desktop,Core GUI APIs...
# 5

What do you mean disappearing? When you add the panel to contentPane, it takes its entire span (covering it completely). This happens since the default layout is BorderLayout, and the added panel is added to the BorderLayout.CENTER location. For more information, read the layout manager tutorial.

kirillga at 2007-7-8 22:20:20 > top of Java-index,Desktop,Core GUI APIs...
# 6
thank you very muchyou have given me very usefull knowledges
vanpersiea at 2007-7-8 22:20:20 > top of Java-index,Desktop,Core GUI APIs...