• Post Reply Bookmark Topic Watch Topic
  • New Topic

please help its urgent

 
vikas de
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi friends,
i have problems with the following code..the b1 button in class wind1 is unpressable..if i include a ckeckbox..this is also unpressable...please let me know how to make this pressable...
please see the code...
import java.awt.*;
import java.awt.event.*;
class X1 extends Frame implements ActionListener
{
X1()
{
setSize(200,200);
Button b=new Button("new");
add(b,BorderLayout.NORTH);
b.addActionListener(this);
show();
}
public void actionPerformed(ActionEvent e)
{
Wind1 ob=new Wind1(new Frame("frame"),"Dialog");
ob.setVisible(true);
}
class Wind1 extends Dialog
{
Button b1;
Wind1(Frame parent,String str)
{
super(parent,str);
setSize (200,200);
b1=new Button("1");
add(b1);
show();
b1.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent ae)
{
System.out.println("3");
}
});
addFocusListener(new FocusAdapter()
{
public void focusLost(FocusEvent f)
{
requestFocus();
}
});
}
}
public static void main(String arg[])
{
new X1();
}
}
thanx
sonu
 
nitin sharma
Ranch Hand
Posts: 290
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
If u remove your code starting from line addfocuslistener then your code run's perfectly fine.
 
Ana Mihailescu
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, Nitin is right...
Now, you add the focus listener to the dialog, and when you press the button and loose the focus on the dialog, it is received back immediately.
But what I don't understand in your code , is why the parent frame of your dialog is a new Frame("frame");
It could be "this", because also "this" is a frame. Why it is the need to create a new frame... ?
Ana
 
linda wessels
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
One thing also to remember...If you have a hierarchy of
inheritance you should only initialize variables in a
constructor because if you put alot of function calls
in a constructor and some data will only have "default values" at this time and will be initialized "after" the function has
already run. Very difficult problem to detect later.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!