Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #37953 > unrolled thread
| Started by | Eric Douglas <e.d.programmer@gmail.com> |
|---|---|
| First post | 2018-01-17 07:13 -0800 |
| Last post | 2018-01-17 19:18 -0500 |
| Articles | 4 — 2 participants |
Back to article view | Back to comp.lang.java.programmer
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
| From | Eric Douglas <e.d.programmer@gmail.com> |
|---|---|
| Date | 2018-01-17 07:13 -0800 |
| Subject | Can you execute a command in Eclipse? |
| Message-ID | <6aa5f167-870c-4084-bfb2-e5cf03a0dbd6@googlegroups.com> |
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?
[toc] | [next] | [standalone]
| From | Arne Vajhøj <arne@vajhoej.dk> |
|---|---|
| Date | 2018-01-17 13:08 -0500 |
| Message-ID | <p3o3f6$1h52$1@gioia.aioe.org> |
| In reply to | #37953 |
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
[toc] | [prev] | [next] | [standalone]
| From | Eric Douglas <e.d.programmer@gmail.com> |
|---|---|
| Date | 2018-01-17 13:47 -0800 |
| Message-ID | <e8f02854-0430-4c95-a254-9309196360dc@googlegroups.com> |
| In reply to | #37954 |
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
[toc] | [prev] | [next] | [standalone]
| From | Arne Vajhøj <arne@vajhoej.dk> |
|---|---|
| Date | 2018-01-17 19:18 -0500 |
| Message-ID | <p3op4u$igr$1@gioia.aioe.org> |
| In reply to | #37955 |
On 1/17/2018 4:47 PM, Eric Douglas wrote:
> 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:
[code omitted]
>> and in your application:
>>
>> GUIUtil.hack(yourjframeinstance);
>>
>> and then in the extra windows simply enter:
>>
>> f.setTitle("Bla");
>>
>> and click execute.
>>
>> Requires BeanShell present.
>
> 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.
Well - your JFrame sub class should have getters to give you everything
GUI related and if you just add one more super object with getters to
give you all the data model stuff, then you should be OK.
> 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.
If the IDE and the program run in same JVM, then it is easy.
I am not familiar with JPDA, but I assume that if the
application is run under debugger then it is also
easy.
Arne
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.java.programmer
csiph-web