|
import java.awt.*;
import java.awt.event.*;
public class MyjavaFrame extends WindowAdapter implements ActionListener{
Frame f;
Button bt1,bt2,bt3;
TextField tx1,tx2;
Label l1,l2;
int tag=0;
public static void main(String args[])
{
new MyjavaFrame().init();
}
public void init()
{
f=new Frame("My Frame");
bt1=new Button("Clear");
bt1.addActionListener(this);
bt2=new Button("Copy");
bt2.addActionListener(this);
bt3=new Button("Close");
bt3.addActionListener(this);
tx1=new TextField("",30);
tx2=new TextField("",30);
l1=new Label("Source");
l2=new Label("Target");
f.add(l1); f.add(tx1);
f.add(l2); f.add(tx2);
f.setLayout(new FlowLayout());
f.add(bt1);
f.add(bt2);
f.add(bt3);
f.addWindowListener(this);
f.setSize(300,300);
f.setVisible(true);
}
public void windowClosing(WindowEvent e){
System.exit(0);
}
public void actionPerformed(ActionEvent e)
{
String s1="";
String s2=tx1.getText();
if(e.getActionCommand()=="Clear")
{
tx1.setText(s1);
tx2.setText(s1);
}
else if(e.getActionCommand()=="Copy")
tx2.setText(s2);
else System.exit(0);
}
} |
|