import javax.imageio.*; import java.awt.image.*; import java.security.NoSuchAlgorithmException; import java.security.MessageDigest; import java.lang.reflect.*; import java.net.*; import java.io.*; import javax.swing.*; import java.util.regex.*; import java.util.zip.*; import java.util.*; import java.awt.*; import java.awt.event.*; import java.util.List; public class main { static JTextArea textArea; static JTextField tfCmd; static List history = new ArrayList(); static int historyIdx; public static void main(String[] args) throws Exception { JFrame frame = new JFrame("A JavaX Frame"); JPanel panel = new JPanel(new BorderLayout()); textArea = new JTextArea(); panel.add(BorderLayout.CENTER, new JScrollPane(textArea)); tfCmd = new JTextField(); panel.add(BorderLayout.SOUTH, tfCmd); tfCmd.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent _evt) { tfCmd.selectAll(); String cmd = tfCmd.getText(); runCmd(cmd); }}); frame.addWindowListener(new WindowAdapter() { public void windowOpened(WindowEvent e) { tfCmd.requestFocus(); } }); frame.add(panel); frame.setBounds(100, 100, 500, 400); frame.setVisible(true); exitOnFrameClose(frame); } static void setText(String text) { if (text.equals(textArea.getText())) return; history.add(historyIdx++, textArea.getText()); textArea.setText(text); } static void runCmd(String cmd) { if ("random chars".equals(cmd)) { String text = randomLetters(40); setText(text); } else if ("back".equals(cmd)) { if (historyIdx > 0) textArea.setText(history.get(--historyIdx)); } else if ("hello".equals(cmd)) { setText("hello!"); } else if ("java class".equals(cmd)) { setText("%636\n%modern\n\nmain {\n static O androidContext;\n static S programID;\n \n public static void main(String[] args) throws Exception {\n }\n}\n".replace("%", "!")); } } static String randomLetters(int n) { return makeRandomID(n); } static void exitOnFrameClose(JFrame frame) { frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } static String makeRandomID(int length) { Random random = new Random(); char[] id = new char[length]; for (int i = 0; i< id.length; i++) id[i] = (char) ((int) 'a' + random.nextInt(26)); return new String(id); } }