22
Sun, Dec
3 New Articles

GUI Builder Makes Java GUI Development Easy

Java
Typography
  • Smaller Small Medium Big Bigger
  • Default Helvetica Segoe Georgia Times

If you’ve ever written an interactive Java program, then you know that designing the GUI is not exactly a straightforward process. Basically, you have two choices. You can code each component of the interface in a Java source file piece by piece, or you can use one of the visual development tools. No matter which technique you use, there’s a trade-off. Using the traditional method of coding every component means you need to have a thorough understanding of layout managers, containers, and action listeners, to name a few things. The traditional method is not easy. On the other hand, if you use an integrated development environment (IDE) such as VisualAge for Java, designing the GUI is very easy. But tying all the GUI components together into a working application is a lot more difficult. To successfully use one of these IDEs, you first need to have a thorough understanding of Java. If you ever have to go back and modify one of the Java source files generated by an IDE and you don’t have the IDE available, then you’ll quickly discover that IDEs are nothing more than code generators, and the code they generate is unduly complex and nearly incomprehensible. Manual modifications are a nightmare. There needs to be a way to combine the flexibility of coding the pieces you want to code by hand with a simple GUI designer that lets you quickly create a Java GUI. If the IDE could make the generated code easy to understand and modify, two-thirds of the battle for programming in Java would be over.

Evidently, IBM also felt that something like this was needed. It created a new Java GUI design tool, GUI Builder, which lets you very rapidly build reusable Java GUI panels. However, before you can appreciate the ease GUI Builder will bring to your programming life, you must first understand why writing interactive Java programs the conventional way is so tedious. Since developing Java apps with an IDE is a monumental undertaking in and of itself, I’ll skip any comparisons between that and the new GUI development tool. I’ll leave it to you to try the IDEs for yourself.

Traditional GUI Design

I’ll do something very simple. I’ll create the Java GUI panel shown in Figure 1. This is a simple application that can be called from any DOS command line. As you can see, the only components on this panel are a label, a text box, and a button. Pretty basic, huh? At least it seems that way until you start digging into the code that makes it work. I’ll show you what I mean. Figure 2 contains the code that displays the panel shown in Figure 1.


The Pieces

In Figure 2 (page 90), at Label A, I’ve told Java to define a new Canvas object named GUICanvas. GUICanvas is a separate Java class and does nothing more than extend the Java Canvas class interface. It is the area where the GUI components will be displayed, inside a standard Windows frame. Label B tells Java that I want to use the Gridbag layout manager to define how components will be displayed in the GUI panel. It’s up to you to decide which layout manager you’ll need to use. The C labels are used, in conjunction with the statement at Label B, to instantiate the Gridbag layout manager. Label D is used to instantiate the new canvas. The statements marked with Label E are used to define the GUI components, which, for this example, include a label, text field, and button. Each of these groups of instructions calls the addComponent method defined at Label H to actually add the components to the canvas. Because you have to specify the exact grid coordinates of each component in relation to all the other components, it’s easier to create one method to handle the placement and adding of the components to the canvas. Label F registers an actionListener to the button. This tells Java that some activity will be occurring with this GUI component and it should “listen” for this activity and take appropriate action. In this case, the action to be performed is to close the GUI panel. After all that, you’re finally ready to display the GUI panel, which is what happens at Label G.

Piece of cake, right? Probably not, unless you’ve been programming in Java for quite some time and are used to it. And this is a really simple Java GUI! Imagine if you had a complex GUI to design and had to lay it out manually on your canvas. Yeesh! This is one of the reasons Java is still on the back burner of acceptance by traditional AS/400 green- screen programmers. After all, once you’ve used a tool like Screen Design Aid on the AS/400 to create display files, you’re not going to be very accepting of something that makes you go back to graph paper and coordinate marking. Besides the drudgery of having to add all these components manually and defining the layout manager and canvas and on and on and on, all this stuff makes your code unnecessarily confusing. Instead of using this method, I will show you a tool that removes most of this complexity.

GUI Builder

GUI Builder is a Java-based WYSIWYG GUI design tool that was introduced with Modification 2 of the AS/400 Toolbox for Java. If you have Version 4, Release 4 of OS/400 or higher on your AS/400, then the Mod 2 version of the tool box resides there. I suggest, however, that you download the latest version of the AS/400 Toolbox for Java from the JTOpen site. (Go to www.as400.ibm.com/toolbox and follow the JTOpen links.)

GUI Builder is a visual design tool that lets you very rapidly and easily build Java GUI panels from scratch. It also lets you convert existing Windows Resource files (file type of RC) into an Extensible Markup Language (XML) representation that can be understood by GUI Builder. This lets you very quickly turn your existing Windows GUI definitions, those you created in C++ for example, into a format that can be understood by Java. In other words, in just a few minutes you can take a library of C++ GUI definitions you designed for Windows machines and make them completely platform-independent.

GUI Builder is able to accomplish all this by using a new technology developed by IBM called Panel Definition Markup Language (PDML). PDML is based on XML and is a way of describing GUI interfaces that are platform-independent. PDML, like XML or HTML, is a tag-based language. That is, each component of a GUI panel is defined with appropriate tags such as

PANEL1.LABEL1
22,60
101,15
PANEL1.LABEL1

PANEL1.TEXTFIELD1
138,61
94,22
SimpleGUI2Src SimpleGUI2Bean


Figure 4: The PDML file generated by GUI Builder is easy to understand for the example.

*


import com.ibm.as400.ui.framework.java.*;
import java.awt.Frame;
public class SimpleGUI2Src
{ public static void main(String[] args)

{

PanelManager pm = null;

try { pm = new PanelManager("SimpleGUI2", "PANEL1", null, new

Frame()); }

catch (DisplayManagerException e)

{

// Something didn't work, so display a message and exit

e.displayUserMessage(null);

System.exit(1);

}

// Display the panel

pm.setVisible(true);

// Exit the application

System.exit(0);

}

}

Figure 5: Contrast this Java code to that shown in Figure 1. Both display the same GUI.


BLOG COMMENTS POWERED BY DISQUS

LATEST COMMENTS

Support MC Press Online

$

Book Reviews

Resource Center

  • SB Profound WC 5536 Have you been wondering about Node.js? Our free Node.js Webinar Series takes you from total beginner to creating a fully-functional IBM i Node.js business application. You can find Part 1 here. In Part 2 of our free Node.js Webinar Series, Brian May teaches you the different tooling options available for writing code, debugging, and using Git for version control. Brian will briefly discuss the different tools available, and demonstrate his preferred setup for Node development on IBM i or any platform. Attend this webinar to learn:

  • SB Profound WP 5539More than ever, there is a demand for IT to deliver innovation. Your IBM i has been an essential part of your business operations for years. However, your organization may struggle to maintain the current system and implement new projects. The thousands of customers we've worked with and surveyed state that expectations regarding the digital footprint and vision of the company are not aligned with the current IT environment.

  • SB HelpSystems ROBOT Generic IBM announced the E1080 servers using the latest Power10 processor in September 2021. The most powerful processor from IBM to date, Power10 is designed to handle the demands of doing business in today’s high-tech atmosphere, including running cloud applications, supporting big data, and managing AI workloads. But what does Power10 mean for your data center? In this recorded webinar, IBMers Dan Sundt and Dylan Boday join IBM Power Champion Tom Huntington for a discussion on why Power10 technology is the right strategic investment if you run IBM i, AIX, or Linux. In this action-packed hour, Tom will share trends from the IBM i and AIX user communities while Dan and Dylan dive into the tech specs for key hardware, including:

  • Magic MarkTRY the one package that solves all your document design and printing challenges on all your platforms. Produce bar code labels, electronic forms, ad hoc reports, and RFID tags – without programming! MarkMagic is the only document design and print solution that combines report writing, WYSIWYG label and forms design, and conditional printing in one integrated product. Make sure your data survives when catastrophe hits. Request your trial now!  Request Now.

  • SB HelpSystems ROBOT GenericForms of ransomware has been around for over 30 years, and with more and more organizations suffering attacks each year, it continues to endure. What has made ransomware such a durable threat and what is the best way to combat it? In order to prevent ransomware, organizations must first understand how it works.

  • SB HelpSystems ROBOT GenericIT security is a top priority for businesses around the world, but most IBM i pros don’t know where to begin—and most cybersecurity experts don’t know IBM i. In this session, Robin Tatam explores the business impact of lax IBM i security, the top vulnerabilities putting IBM i at risk, and the steps you can take to protect your organization. If you’re looking to avoid unexpected downtime or corrupted data, you don’t want to miss this session.

  • SB HelpSystems ROBOT GenericCan you trust all of your users all of the time? A typical end user receives 16 malicious emails each month, but only 17 percent of these phishing campaigns are reported to IT. Once an attack is underway, most organizations won’t discover the breach until six months later. A staggering amount of damage can occur in that time. Despite these risks, 93 percent of organizations are leaving their IBM i systems vulnerable to cybercrime. In this on-demand webinar, IBM i security experts Robin Tatam and Sandi Moore will reveal:

  • FORTRA Disaster protection is vital to every business. Yet, it often consists of patched together procedures that are prone to error. From automatic backups to data encryption to media management, Robot automates the routine (yet often complex) tasks of iSeries backup and recovery, saving you time and money and making the process safer and more reliable. Automate your backups with the Robot Backup and Recovery Solution. Key features include:

  • FORTRAManaging messages on your IBM i can be more than a full-time job if you have to do it manually. Messages need a response and resources must be monitored—often over multiple systems and across platforms. How can you be sure you won’t miss important system events? Automate your message center with the Robot Message Management Solution. Key features include:

  • FORTRAThe thought of printing, distributing, and storing iSeries reports manually may reduce you to tears. Paper and labor costs associated with report generation can spiral out of control. Mountains of paper threaten to swamp your files. Robot automates report bursting, distribution, bundling, and archiving, and offers secure, selective online report viewing. Manage your reports with the Robot Report Management Solution. Key features include:

  • FORTRAFor over 30 years, Robot has been a leader in systems management for IBM i. With batch job creation and scheduling at its core, the Robot Job Scheduling Solution reduces the opportunity for human error and helps you maintain service levels, automating even the biggest, most complex runbooks. Manage your job schedule with the Robot Job Scheduling Solution. Key features include:

  • LANSA Business users want new applications now. Market and regulatory pressures require faster application updates and delivery into production. Your IBM i developers may be approaching retirement, and you see no sure way to fill their positions with experienced developers. In addition, you may be caught between maintaining your existing applications and the uncertainty of moving to something new.

  • LANSAWhen it comes to creating your business applications, there are hundreds of coding platforms and programming languages to choose from. These options range from very complex traditional programming languages to Low-Code platforms where sometimes no traditional coding experience is needed. Download our whitepaper, The Power of Writing Code in a Low-Code Solution, and:

  • LANSASupply Chain is becoming increasingly complex and unpredictable. From raw materials for manufacturing to food supply chains, the journey from source to production to delivery to consumers is marred with inefficiencies, manual processes, shortages, recalls, counterfeits, and scandals. In this webinar, we discuss how:

  • The MC Resource Centers bring you the widest selection of white papers, trial software, and on-demand webcasts for you to choose from. >> Review the list of White Papers, Trial Software or On-Demand Webcast at the MC Press Resource Center. >> Add the items to yru Cart and complet he checkout process and submit

  • Profound Logic Have you been wondering about Node.js? Our free Node.js Webinar Series takes you from total beginner to creating a fully-functional IBM i Node.js business application.

  • SB Profound WC 5536Join us for this hour-long webcast that will explore:

  • Fortra IT managers hoping to find new IBM i talent are discovering that the pool of experienced RPG programmers and operators or administrators with intimate knowledge of the operating system and the applications that run on it is small. This begs the question: How will you manage the platform that supports such a big part of your business? This guide offers strategies and software suggestions to help you plan IT staffing and resources and smooth the transition after your AS/400 talent retires. Read on to learn: