Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

cannot we add one more component on another by calling a method  RSS feed

 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
import java.awt.*;
import java.awt.event.*;
public class trial extends Frame implements ActionListener
{
Container cc;
TextField ff;
Panel pp;
trial(String ss)
{
super(ss);
setSize(20,50);
setVisible(true);
pp=new Panel();
Button bb = new Button("press");
bb.addActionListener(this);
pp.add(bb);
//cc=getContentPane();
add(pp);
}
public void shows()
{
ff=new TextField(10,10);
pp.add(ff);
}

public void actionPerformed(ActionEvent e)
{

String ss;
ss= e.getActionCommand();
if(ss.equals("press"))
{
System.out.println("hello");
shows();
}
}
public static void main(String args[])
{
trial tt = new trial("srijan");
}
}
here on pressing the button" press" i get hello but not the textfield dispalyed on my panel which is on frame.pl guide
regards srijan
 
deekasha gunwant
Ranch Hand
Posts: 396
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi srijan,
try using pp.validate()in the actionPerformed code after u add the textfield to the panel.
in case validate does not work try using pp.updateUI() instead.
let me know if it solved ur problem or not.
regards
deekasha
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi deeksha,

thanks for that. i am making editor using java swing. so i will be asking
u few more like that. hope u will see them.
should i buy a java swing book seperately or java2 book will do as i could not find the methods told by u anywhere in book
regards again
srijan
 
Pomchi Bedi
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Srijan,
The best,easiest and the fastest way to get any information about java classes is to refer to sun's API specification online.
http://java.sun.com/products/jdk/1.2/docs/api/index.html
-Pomchi
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!