/*
13. Write a program(preferably UI) to demonstrate the operations(at least 4) on array list/ hash
list/set/sorted set.
*/
import java.util.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
import java.awt.*;
class Program13 extends JFrame {
static JFrame frame;
static JLabel l1;
static JButton removebutton,addbutton,sortbutton,revbutton ;
static JTextArea area;
static JTextField t1;
static ArrayList< String > list;
public static void main(String[] args)
{
list = new ArrayList< String>();
list.add("India");
list.add("Pakistan");
list.add("Srilanka");
// Printing the unsorted ArrayList
System.out.println("Before Sorting : " + list);
// Sorting ArrayList in ascending Order
Collections.sort(list);
// printing the sorted ArrayList
System.out.println("After Sorting : " + list);
frame = new JFrame();
removebutton = new JButton("remove");
addbutton = new JButton("add");
sortbutton = new JButton("sort");
revbutton = new JButton("reverse");
area = new JTextArea("Welcome to javatpoint");
removebutton.setBounds(80, 260, 100, 40);
addbutton.setBounds(180, 260, 100, 40);
sortbutton.setBounds(280, 260, 100, 40);
revbutton.setBounds(380, 260, 100, 40);
l1 = new JLabel("country name");
l1.setBounds(50, 50, 250, 30);
t1 = new JTextField();
t1.setBounds(250, 50, 250, 30);
area = new JTextArea();
area.setBounds(250, 100, 250, 90);
frame. add(l1);
frame. add(t1);
frame. add(removebutton);
frame. add(addbutton);
frame. add(sortbutton);
frame. add(revbutton);
frame. add(area);
area.setText(list.toString());
removebutton.addActionListener( new ActionListener() {
public void actionPerformed(ActionEvent e)
{
String name=t1.getText().toString();
list.remove(name);
}
});
addbutton.addActionListener( new ActionListener() {
public void actionPerformed(ActionEvent e)
{
String name=t1.getText().toString();
list.add(name);
area.setText(list.toString());
}
});
sortbutton.addActionListener( new ActionListener() {
public void actionPerformed(ActionEvent e)
{
Collections.sort(list);
area.setText(list.toString());
}
});
revbutton.addActionListener( new ActionListener() {
public void actionPerformed(ActionEvent e)
{
Collections.sort(list, Collections.reverseOrder());
area.setText(list.toString());
}
});
frame.setSize(400, 400);
frame.setLayout(null);
frame.setVisible(true);
}
}