0% found this document useful (0 votes)
21 views2 pages

Anonymous

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views2 pages

Anonymous

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

import java.awt.

FlowLayout;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import javax.swing.JButton;

import javax.swing.JFrame;

import javax.swing.JTextField;

class GUI {

JFrame frame;

JTextField text1, text2;

JButton clear, swipe, exit; // Added "exit" button

String str1, str2;

public GUI() {

frame = new JFrame("EXAMPLE");

text1 = new JTextField(10);

text2 = new JTextField(10);

clear = new JButton("Clear");

swipe = new JButton("Swipe");

exit = new JButton("Exit"); // Added "Exit" button

frame.setLayout(new FlowLayout());

frame.setSize(300,400);

frame.setVisible(true);

frame.add(text1);

frame.add(text2);

frame.add(clear);

frame.add(swipe);

frame.add(exit); // Added "Exit" button

frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

clear.addActionListener(new ActionListener() {
@Override

public void actionPerformed(ActionEvent e) {

text1.setText(" ");

text2.setText(" ");

});

swipe.addActionListener(new ActionListener() {

@Override

public void actionPerformed(ActionEvent e) {

str1 = text1.getText();

str2 = text2.getText();

text1.setText(str2);

text2.setText(str1);

});

exit.addActionListener(new ActionListener() {

@Override

public void actionPerformed(ActionEvent e) {

System.exit(0);

});

public class Test {

public static void main(String[] args) {

GUI g = new GUI();

You might also like