Heres my code

import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Order extends Applet implements ActionListener
{
	String password = "pword";
	TextField txt1 = new TextField(10);
	TextField txt2 = new TextField(10);
	Button btn1 = new Button("Ok");
	Button btn2 = new Button("Ok");
	Label lbl1 = new Label("Choose Your Order");
	Checkbox chk1 = new Checkbox("Value Meal #1: P25.00");

	public void init()
	{
		add(new Label("Username: ",Label.LEFT));
		add(txt1);
		addNewLine();
		add(new Label("Password: ",Label.LEFT));
		add(txt2);
		txt2.setEchoChar('*');
		addNewLine();
		add(btn1);
		add(lbl1);
		lbl1.setVisible(false);
		add(chk1);
		chk1.setVisible(false);
		btn1.addActionListener(this);

	}

	public void actionPerformed(ActionEvent e)
	{
		if(e.getSource() == btn1)
			{
				process();
			}
	}

	public void process()
	{
		if(txt2.getText().equals(password))
			{
				lbl1.setVisible(true);
				chk1.setVisible(true);
			}
		else
			{
				JOptionPane.showMessageDialog(null,"Invalid Password","Message",JOptionPane.INFORMATION_MESSAGE);
			}

	}

	public void addHorizontalLine(Color c)
		   {
		      Canvas line = new Canvas( );
		      line.setSize(10000,1);
		      line.setBackground(c);
		      add(line);
		   }

	public void addNewLine( )
		   {
		      addHorizontalLine(getBackground( ));
		   }
}

the problem is when I run the program and enter the password, lbl1 and chk1 should be visible but it stays invisible.

Recommended Answers

All 6 Replies

call validate and/or repaint on the container that contains those components.

how should I do that? I'm a newbie in Java

anybody?

Well, look at the API docs. All components have a getParent method, what do you think that does? Could that possibly return the container in which that component resides? Well, yes, I believe it does.

Write " lbl1.getParent().validate(); " before following statements
lbl1.setVisible(true);

and lablel will be visible.

Hi hrbswat
Welcome to DaniWeb.
Your contiributions will be warmly received, but please take a moment to check the dates on threads - thos one was solved (and marked as such) two years ago, so its unlikely that anyone is still waiting to have the answer repeated! Please also respect the way we try to give the OP enough info to learn how to solve the problem themselves; posts like "do this ... and it will work" do little to teach the OP, they just encourage copy/paste/cheat without understanding.
;)
J

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.