import java.awt.*; import javax.swing.*; import java.awt.event.*; import java.util.*; /** * Test * * enable user to test implementations of SetInterface * @author rpj * @version 12ix08 */ public class Test extends JFrame { // instance variables private JTextArea input, otherinput; private JTextField output; private JLabel lab, otherlab, outputlab; private JButton create, removeRandom, remove, union; private SetInterface testMe; public Test() { /* You will need to insert a line testMe = new SetImplementation(); where SetImplementation is a class implementing SetInterface */ setSize(400,400); setTitle("testing set"); setVisible(true); setDefaultCloseOperation(EXIT_ON_CLOSE); Container pane = getContentPane(); lab = new JLabel("Input set"); input = new JTextArea(); input.setPreferredSize(new Dimension(300,100)); input.setLineWrap(true); input.setWrapStyleWord(true); otherlab = new JLabel("Operand(s)"); otherinput = new JTextArea(); otherinput.setPreferredSize(new Dimension(300,100)); otherinput.setLineWrap(true); otherinput.setWrapStyleWord(true); create = new JButton("create"); create.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { Scanner sc = new Scanner(input.getText()); sc.useDelimiter("\\s*[\\p{Punct}*\\s+]\\s*"); while (sc.hasNext()) testMe.add(sc.next().toLowerCase()); input.setText("The set is {"+testMe.toString()+"}"); output.setText("Set created"); } }); removeRandom = new JButton("remove random"); removeRandom.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { String result = ""; try { result = testMe.removeRandom(); } catch (EmptySetException ese) { result = "no can do"; } input.setText("The set is {"+testMe.toString()+"}"); otherinput.setText(""); output.setText("result is "+result); } }); remove = new JButton("remove "); remove.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { String result = ""; try { result = testMe.remove(otherinput.getText()); } catch (Exception ese) { result = ese.toString(); } input.setText("The set is {"+testMe.toString()+"}"); otherinput.setText(""); output.setText("Result is "+result); } }); union = new JButton("union "); union.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { SetInterface other = null; /* You will need to add a line other= new SetImplementation(); */ Scanner sc = new Scanner(otherinput.getText()); sc.useDelimiter("\\s*[\\p{Punct}*\\s+]\\s*"); while (sc.hasNext()) other.add(sc.next().toLowerCase()); testMe.union(other); input.setText("The set is {"+testMe.toString()+"}"); output.setText("union returns void"); otherinput.setText(""); } }); outputlab = new JLabel("result"); output = new JTextField(); output.setPreferredSize(new Dimension(300,20)); pane.setLayout(new FlowLayout()); pane.add(lab); pane.add(input); pane.add(otherlab); pane.add(otherinput); pane.add(create); pane.add(removeRandom); pane.add(remove); pane.add(union); pane.add(outputlab); pane.add(output); validate(); } /** * main * */ public static void main(String[] args) { new Test(); } }