Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // AutoJava: AutoIt-like Scripting in Java
- // http://pastebin.com/u/ChristophX86
- //
- import javax.swing.*;
- import java.awt.*;
- import java.awt.event.*;
- import java.lang.reflect.Method;
- public abstract class AutoIt
- {
- public static class GUI extends JFrame
- {
- public GUI(String title)
- {
- super(title);
- }
- }
- public static class Button extends JButton
- {
- public Object __obj;
- public String __method;
- public Button(String text)
- {
- super(text);
- }
- }
- public static class Input extends JTextField
- {
- public Input(String text)
- {
- super(text);
- }
- }
- public static class Edit extends JTextArea
- {
- public Edit(String text)
- {
- super(text);
- }
- }
- public static class Label extends JLabel
- {
- public Label(String text)
- {
- super(text);
- }
- }
- public static class Progress extends JProgressBar
- {
- public Progress()
- {
- super(0, 100);
- }
- }
- /** Create a GUI window. */
- public static GUI GUICreate(String title, int width, int height)
- {
- GUI GUI = new GUI(title);
- GUI.getContentPane().setLayout(null);
- GUI.setSize(width, height);
- GUI.setResizable(false);
- GUI.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- return GUI;
- }
- /** Create a GUI window. */
- public static GUI GUICreate(String title, int width, int height, int left, int top)
- {
- GUI GUI = new GUI(title);
- GUI.getContentPane().setLayout(null);
- GUI.setSize(width, height);
- GUI.setResizable(false);
- GUI.setLocation(left, top);
- GUI.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- return GUI;
- }
- /** Creates a Button control for the GUI. */
- public static Button GUICtrlCreateButton(String text, int left, int top, int width, int height, GUI GUI)
- {
- Button Button = new Button(text);
- Button.setBounds(left, top, width, height);
- GUI.getContentPane().add(Button);
- return Button;
- }
- /** Creates an Input control for the GUI. */
- public static Input GUICtrlCreateInput(String text, int left, int top, int width, int height, GUI GUI)
- {
- Input Input = new Input(text);
- Input.setBounds(left, top, width, height);
- GUI.getContentPane().add(Input);
- return Input;
- }
- /** Creates an Edit control for the GUI. */
- public static Edit GUICtrlCreateEdit(String text, int left, int top, int width, int height, GUI GUI)
- {
- Edit Edit = new Edit(text);
- Edit.setBounds(left, top, width, height);
- GUI.getContentPane().add(Edit);
- return Edit;
- }
- /** Creates a static Label control for the GUI. */
- public static Label GUICtrlCreateLabel(String text, int left, int top, int width, int height, GUI GUI)
- {
- Label Label = new Label(text);
- Label.setBounds(left, top, width, height);
- GUI.getContentPane().add(Label);
- return Label;
- }
- /** Creates a Progress control for the GUI. */
- public static Progress GUICtrlCreateProgress(int left, int top, int width, int height, GUI GUI)
- {
- Progress Progress = new Progress();
- Progress.setBounds(left, top, width, height);
- GUI.getContentPane().add(Progress);
- return Progress;
- }
- public static void GUISetState(boolean visible, GUI GUI)
- {
- GUI.setVisible(visible);
- }
- /**
- * Ruft eine bestimmte Methode eines Objekts anhand ihres Namens ohne Parameter auf.
- * @author Carsten S.
- * @param obj das Objekt, dessen Methode aufgerufen werden soll
- * @param methodName der Name der Methode
- * @return true bei Erfolg, sonst false.
- */
- private static boolean callNamedMethod(Object obj, String methodName)
- {
- try {
- Method method = obj.getClass().getDeclaredMethod(methodName, (Class<?>[]) null);
- method.setAccessible(true);
- method.invoke(obj, (Object[]) null);
- } catch (Exception e) { return false; }
- return true;
- }
- /** Defines a user-defined function to be called when a control is clicked. */
- public static void GUICtrlSetOnEvent(final Button controlID, Object obj, String method)
- {
- controlID.__obj = obj;
- controlID.__method = method;
- controlID.addActionListener(
- new ActionListener()
- {
- public void actionPerformed(ActionEvent arg0)
- {
- callNamedMethod(controlID.__obj, controlID.__method);
- }
- }
- );
- }
- /** Read state or data of a control. */
- public static String GUICtrlRead(Button controlID)
- {
- return controlID.getText();
- }
- public static String GUICtrlRead(Input controlID)
- {
- return controlID.getText();
- }
- public static String GUICtrlRead(Edit controlID)
- {
- return controlID.getText();
- }
- public static String GUICtrlRead(Label controlID)
- {
- return controlID.getText();
- }
- public static int GUICtrlRead(Progress controlID)
- {
- return controlID.getValue();
- }
- /** Modifies the data for a control. */
- public static void GUICtrlSetData(Button controlID, String data)
- {
- controlID.setText(data);
- }
- public static void GUICtrlSetData(Input controlID, String data)
- {
- controlID.setText(data);
- }
- public static void GUICtrlSetData(Edit controlID, String data)
- {
- controlID.setText(data);
- }
- public static void GUICtrlSetData(Label controlID, String data)
- {
- controlID.setText(data);
- }
- public static void GUICtrlSetData(Progress controlID, int data)
- {
- controlID.setValue(data);
- }
- /** Sets the text color of a control. */
- // GUICtrlSetColor()
- /** Writes data to the STDOUT stream. Some text editors can read this stream as can other programs which may be expecting data on this stream. */
- public static void ConsoleWrite(String data)
- {
- System.out.print(data);
- }
- /** Returns a handle that can be passed to TimerDiff() to calculate the difference in milliseconds. */
- public static long TimerInit()
- {
- return System.currentTimeMillis();
- }
- /** Returns the difference in time from a previous call to TimerInit(). */
- public static long TimerDiff(long handle)
- {
- return System.currentTimeMillis()-handle;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement