Win a copy of Rust Web Development this week in the Other Languages forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

please help its urgent

 
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 290
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi
If u remove your code starting from line addfocuslistener then your code run's perfectly fine.
 
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic