import java.awt.*; import java.awt.event.*; import javax.swing.*; import java.util.Random; // swing at // http://java.sun.com/docs/books/tutorial/uiswing/components/components.html public class SortList extends JApplet implements ActionListener, MouseListener { // Variables declaration. For this applet, not all // declared labels and textfields are used private boolean isSorted=false; private int sortSrc=0; private boolean hasClicked=false; private int nCount=5; private int [] nums; private JPanel [] pNums; private JLabel [] lNums; private JPanel pMain; private int lang=0; private JTextField tCount; private JButton bMelange; private Container appletPanel; private JPanel progPanel; private Color bgColor; private JTextArea tLog; public void init() { setSize(nCount*40,120); bgColor=new Color(254,220,40); JFrame.setDefaultLookAndFeelDecorated(true); appletPanel = getContentPane(); appletPanel = getContentPane(); appletPanel.setLayout(new BorderLayout()); progPanel = new JPanel(); progPanel.setLayout(new BorderLayout()); tLog = new JTextArea("Applet Started"); tLog.setEditable(false); tLog.setRows(2); JScrollPane scrollPane = new JScrollPane(tLog, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); // add program panel appletPanel.add(progPanel, BorderLayout.CENTER); // add log panel appletPanel.add(scrollPane, BorderLayout.SOUTH); //panels pMain=new JPanel(); pMain.setLayout(new GridLayout(1,nCount)); pMain.setBackground(bgColor); progPanel.add(pMain,BorderLayout.CENTER); progPanel.setBackground(bgColor); pNums = new JPanel[nCount]; lNums = new JLabel[nCount]; for (int i=0;i=pVal) { pVal=nums[i]; } else { isSorted=false; return; } } appendLog("We have a sort!"); isSorted=true; } public void appendLog(String text) { tLog.append("\n" + text); tLog.setCaretPosition(tLog.getDocument().getLength()); } //ActionListener interface public void actionPerformed(ActionEvent e) { if (e.getSource()==bMelange) { melanger(); } } //MouseListener interface public void mousePressed(MouseEvent e) { if (isSorted) return; for (int i=0;i