Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #37955
| Newsgroups | comp.lang.java.programmer |
|---|---|
| Date | 2018-01-17 13:47 -0800 |
| References | <6aa5f167-870c-4084-bfb2-e5cf03a0dbd6@googlegroups.com> <p3o3f6$1h52$1@gioia.aioe.org> |
| Message-ID | <e8f02854-0430-4c95-a254-9309196360dc@googlegroups.com> (permalink) |
| Subject | Re: Can you execute a command in Eclipse? |
| From | Eric Douglas <e.d.programmer@gmail.com> |
On Wednesday, January 17, 2018 at 1:09:02 PM UTC-5, Arne Vajhøj wrote:
> On 1/17/2018 10:13 AM, Eric Douglas wrote:
> > Is there a place to execute a command, like say I'm running a Java
> > test with a JFrame can I just manually set the title of it without
> > ending the JVM and starting over?
>
> I think this will be difficult as Eclipse and your application
> are running in two different JVM's.
>
> Alternative approach:
>
> import java.awt.BorderLayout;
> import java.awt.Dimension;
> import java.awt.event.ActionEvent;
> import java.awt.event.ActionListener;
> import java.io.ByteArrayOutputStream;
> import java.io.PrintStream;
> import java.io.StringReader;
>
> import javax.swing.JButton;
> import javax.swing.JFrame;
> import javax.swing.JLabel;
> import javax.swing.JOptionPane;
> import javax.swing.JTextField;
> import javax.swing.SwingUtilities;
>
> import bsh.EvalError;
> import bsh.Interpreter;
>
> public class GUIUtil {
> public static void hack(JFrame origframe) {
> SwingUtilities.invokeLater(new Runnable() {
> public void run() {
> try {
> JFrame newframe = new JFrame() {
> private static final long serialVersionUID = 1L;
> private JTextField cmd;
> private JButton btn;
> {
> setTitle("Execute commands");
> this.setPreferredSize(new Dimension(600, 75));
> getContentPane().setLayout(new BorderLayout());
> getContentPane().add(new
> JLabel("Command:"), BorderLayout.WEST);
> cmd = new JTextField();
> getContentPane().add(cmd, BorderLayout.CENTER);
> btn = new JButton("Execute");
> btn.addActionListener(new ActionListener() {
> @Override
> public void actionPerformed(ActionEvent
> e) {
> try {
> ByteArrayOutputStream baos =
> new ByteArrayOutputStream();
> PrintStream ps = new
> PrintStream(baos);
> Interpreter i = new
> Interpreter(new StringReader(""), ps, ps, false);
> i.set("f", origframe);
> i.eval(cmd.getText());
> i.run();
> byte[] msgbuf =
> baos.toByteArray();
> if(msgbuf.length > 0) {
>
> JOptionPane.showMessageDialog(null, new String(msgbuf));
> }
> } catch (EvalError e1) {
> e1.printStackTrace();
> }
> }
> });
> getContentPane().add(btn, BorderLayout.EAST);
> pack();
> }
> };
> newframe.setVisible(true);
> } catch(Exception ex) {
> ex.printStackTrace();
> }
> }
> });
> }
> }
>
> and in your application:
>
> GUIUtil.hack(yourjframeinstance);
>
> and then in the extra windows simply enter:
>
> f.setTitle("Bla");
>
> and click execute.
>
> Requires BeanShell present.
>
> Arne
For that to simply execute anything you could in the application you would have to call that method for every object and somehow assign the same object name, but that is pretty cool.
I'm used to our other language. This language started as BASIC which was a single window executing code in line so you could break at any point and execute a command. The current generation is called BBj (Business BASIC on Java) which gives us a console window and a Java API. Somehow their console window interacts with the GUI objects through their API so when it's running normally it's sitting on one command that runs like an infinite loop (http://documentation.basis.com/BASISHelp/WebHelp/commands2/process_events_verb.htm) and we can break out any time and manually execute code to manipulate the GUI.
http://www.basis.com/bbj
Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Can you execute a command in Eclipse? Eric Douglas <e.d.programmer@gmail.com> - 2018-01-17 07:13 -0800
Re: Can you execute a command in Eclipse? Arne Vajhøj <arne@vajhoej.dk> - 2018-01-17 13:08 -0500
Re: Can you execute a command in Eclipse? Eric Douglas <e.d.programmer@gmail.com> - 2018-01-17 13:47 -0800
Re: Can you execute a command in Eclipse? Arne Vajhøj <arne@vajhoej.dk> - 2018-01-17 19:18 -0500
csiph-web