Enter your search query in the box above ^, or use the forum search tool.

You are not logged in.

#1 2012-10-15 17:00:05

#! Die Hard
From: New England
Registered: 2011-11-28
Posts: 931

Quick Java Debugging (BeanShell)

Both Eclipse and Netbeans have good debuggers.
However there are times when you just want to test a snippet of code outside of your project.
Two methods come to mind the Eclipse's Jpage format and BeanShell the app.

With Eclipse you can File > New > Other > Startpage to create an Independent Scrapbook Jpage..

BeanShell is installed via Synaptics or apt-get as bsh Java scripting environment (BeanShell) Version 2

Why I have become a fan of testing snippets with BeanShell is that it is just easier..
The below JButton code example ran instantly in BeanShell

While with Eclipse Scapbook.jpage there was

Highlighting of code.
Designating Imports JButton, JFrame, Java.util (Which must be established in each Scrap Jpage.)
Designate Source
Right Click to Exec or Inspect.
If any errors appear in Editor ..Highlight and delete before next try..
Lastly, make certain to Kill the Execution before trying Again.

With BeanShell
Type in or Paste the Code and Hit your Enter Key.... That's It!

If errors appear they are displayed but not as part of the code.

The code examples below run instantly in BeanShell but require interface tweaking with Eclipse.
Give BeanShell a look.. A Handy Java Tool.

button = new JButton( "My Button" );
frame = new JFrame( "My Frame" );
frame.getContentPane().add( button, "Center" );

.....And a bit more Complicated....

class GraphicButton extends JButton {
    public void paintComponent(Graphics g) {
        //super.paintComponent(g);  // can't refer to super in scrapbook
        Graphics2D g2 = (Graphics2D) g;
        g2.fillRoundRect(10, 10, getWidth()-20, getHeight()-20, 14, 14);
        g2.drawRoundRect(10, 10, getWidth()-20, getHeight()-20, 14, 14);
        g2.drawString("Graphic Test", 40, 40);
    public Dimension getPreferredSize() {
        return new Dimension(200,100);

JFrame frame = new JFrame("JButton Demo");
Container cont = frame.getContentPane();

JButton hello = new GraphicButton();


OHCG #!, Jessie,, Siduction-13.1Slackware 14Bridge,, Sabayon 13.4,


Board footer

Powered by FluxBB

Copyright © 2012 CrunchBang Linux.
Proudly powered by Debian. Hosted by Linode.
Debian is a registered trademark of Software in the Public Interest, Inc.
Server: acrobat

Debian Logo