Skip to main content

Create java AWT GUI Program to Swap strings

· One min read
Kaustubh Kulkarni
  
import java.awt.*;
import java.awt.event.*;




public class me {

public static void main(String[] args) {

Frame f=new Frame("Swap");

Label l=new Label("Enter First Number");
Label l1=new Label("Enter Second Number");

TextField t1=new TextField(10);
TextField t2=new TextField(10);

Button b=new Button("Swap");


b.addActionListener(new ActionListener()
{


public void actionPerformed(ActionEvent ae)
{
String tmp=t1.getText();
t1.setText(t2.getText());
t2.setText(tmp);


}

} );


f.add(l);
f.add(l1);

f.add(t2);
f.add(t1);

f.add(b);


f.setLayout(new FlowLayout());
f.setSize(300,300);
f.setVisible(true);





}
}



Output: