import java.awt.*;
import java.awt.event.*;
class component extends Frame
{
TextField tx;
Button b1,b2;
String s=" ";
int x=70;
component()
{
super("demo");
setLayout(null);
tx=new TextField(15);
b1=new Button("click");
b2=new Button("move");
add(b1);
add(b2);
b1.setBounds(30,50,100,70);
b2.setBounds(120,50,160,70);
tx.setBounds(70,120,160,150);
b1.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent ob)
{
add(tx);
}
});
b2.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent ob)
{
x=x+10;
tx.setLocation(x,100);
}
});
tx.addComponentListener(new ComponentAdapter()
{
public void componentMoved(ComponentEvent ob)
{
tx.setBackground(new Color(x+10,x+1,x+2));
}
});
addContainerListener(new ContainerAdapter()
{
public void componentAdded(ContainerEvent ob)
{
s="Component is added";
repaint();
}
});
}
public void paint(Graphics g)
{
g.drawString(s,200,300);
}
public static void main(String args[])
{
component c=new component();
c.setVisible(true);
c.setSize(200,200);
}
}
import java.awt.event.*;
class component extends Frame
{
TextField tx;
Button b1,b2;
String s=" ";
int x=70;
component()
{
super("demo");
setLayout(null);
tx=new TextField(15);
b1=new Button("click");
b2=new Button("move");
add(b1);
add(b2);
b1.setBounds(30,50,100,70);
b2.setBounds(120,50,160,70);
tx.setBounds(70,120,160,150);
b1.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent ob)
{
add(tx);
}
});
b2.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent ob)
{
x=x+10;
tx.setLocation(x,100);
}
});
tx.addComponentListener(new ComponentAdapter()
{
public void componentMoved(ComponentEvent ob)
{
tx.setBackground(new Color(x+10,x+1,x+2));
}
});
addContainerListener(new ContainerAdapter()
{
public void componentAdded(ContainerEvent ob)
{
s="Component is added";
repaint();
}
});
}
public void paint(Graphics g)
{
g.drawString(s,200,300);
}
public static void main(String args[])
{
component c=new component();
c.setVisible(true);
c.setSize(200,200);
}
}
No comments:
Post a Comment