//These are some of the standard "imports" we'll be using, explained in class import java.awt.*; import java.awt.event.*; import javax.swing.*; import java.applet.*; public class MaxArray extends Applet implements ActionListener { JTextArea output; JButton button; String[] names = { "Courtney" , "Rishi" , "Aarti" , "Emerald" , "Austin" , "Maulik" , "Karmela Marie" , "Andrew" , "Arvind" , "Preetam" , "Deepak" , "Curtis Maxwell" , "Vibhor" , "Harry" , "Nelson " , "Adam" , "Michelle" , "Ethan" , "Yasmine" , "Brianne" , "Kent" , "Alex" , "Cody" }; public void init() { setLayout(new BorderLayout()); // Create the text-area and button we'll use output = new JTextArea(); button = new JButton("Find Min & Max Names"); // Next we create a "panel" that we add button to JPanel p = new JPanel(); p.setLayout(new FlowLayout()); p.add(button); // Finally, to finish building the UI, we simply add the text and the panel // (which contains the button) to the applet add("Center", new JScrollPane(output)); add("South", p); // Lastly, we instruct the applet to "listen" for the button to be pressed button.addActionListener(this); // Display the current list of students output.append("The current list of students is:\n"); for (int index = 0; index < names.length; index++) { output.append(" " + (index+1) + "." + names[index] + "\n"); } } public void actionPerformed(ActionEvent evt) { String min = names[0]; String max = names[0]; for (int index = 1; index < names.length; index++) { if (min.compareTo(names[index]) > 0) min = names[index]; if (max.compareTo(names[index]) < 0) max = names[index]; } output.append("The student with the (alphabetically) first name is: " + min + "\n"); output.append("The student with the (alphabetically) last name is: " + max + "\n"); } }