Eclipsing Your IDE. Figure 1 The first Eclipse screen.

Similar documents
I VE GOT A LITTLE LIST

KF5008 Program Design & Development. Lecture 1 Usability GUI Design and Implementation

Building a GUI in Java with Swing. CITS1001 extension notes Rachel Cardell-Oliver

Swing from A to Z Some Simple Components. Preface

Part 3: Graphical User Interface (GUI) & Java Applets

Graphical User Interface (GUI)

Window Interfaces Using Swing Objects

Frames, GUI and events. Introduction to Swing Structure of Frame based applications Graphical User Interface (GUI) Events and event handling

Window Interfaces Using Swing Objects

Introduction to GUIs. Principles of Software Construction: Objects, Design, and Concurrency. Jonathan Aldrich and Charlie Garrod Fall 2014

An array is a type of variable that is able to hold more than one piece of information under a single variable name.

Control Flow: Overview CSE3461. An Example of Sequential Control. Control Flow: Revisited. Control Flow Paradigms: Reacting to the User

ITEC 120 4/14/11. Review. Need. Objectives. GUI basics JFrame JPanel JLabel, JButton, JTextField Layout managers. Lecture 38 GUI Interactivity

Programming Languages and Techniques (CIS120e)

Graphical User Interface (Part-1) Supplementary Material for CPSC 233

Command-Line Applications. GUI Libraries GUI-related classes are defined primarily in the java.awt and the javax.swing packages.

AP CS Unit 11: Graphics and Events

Graphic User Interfaces. - GUI concepts - Swing - AWT

Proctors are unable to respond to queries about the interpretation of exam questions. Do your best to answer exam questions as written.

Topic 9: Swing. Swing is a BIG library Goal: cover basics give you concepts & tools for learning more

Topic 9: Swing. Why are we studying Swing? GUIs Up to now: line-by-line programs: computer displays text user types text. Outline. 1. Useful & fun!

Lab 4. D0010E Object-Oriented Programming and Design. Today s lecture. GUI programming in

Midterm assessment - MAKEUP Fall 2010

CSEN401 Computer Programming Lab. Topics: Graphical User Interface Window Interfaces using Swing

Proctors are unable to respond to queries about the interpretation of exam questions. Do your best to answer exam questions as written.

Outline. Topic 9: Swing. GUIs Up to now: line-by-line programs: computer displays text user types text AWT. A. Basics

PIC 20A GUI with swing

COMP-202 Unit 10: Basics of GUI Programming (Non examinable) (Caveat: Dan is not an expert in GUI programming, so don't take this for gospel :) )

This chapter is intended to take you through the basic steps of using the Visual Basic

Java Graphical User Interfaces AWT (Abstract Window Toolkit) & Swing

Strategy Pattern. What is it?

GUI and its COmponent Textfield, Button & Label. By Iqtidar Ali

CS Exam 1 Review Suggestions

Introduction to Graphical Interface Programming in Java. Introduction to AWT and Swing

Java Programming Lecture 6

Example 3-1. Password Validation

Example Programs. COSC 3461 User Interfaces. GUI Program Organization. Outline. DemoHelloWorld.java DemoHelloWorld2.java DemoSwing.

CS 2113 Software Engineering

GUI Program Organization. Sequential vs. Event-driven Programming. Sequential Programming. Outline

JAVA NOTES GRAPHICAL USER INTERFACES

CS11 Java. Fall Lecture 4

DM503 Programming B. Peter Schneider-Kamp.

MIT AITI Swing Event Model Lecture 17

Getting Started with Java Development and Testing: Netbeans IDE, Ant & JUnit

Java Swing. based on slides by: Walter Milner. Java Swing Walter Milner 2005: Slide 1

Class 16: The Swing Event Model

DCS235 Software Engineering Exercise Sheet 2: Introducing GUI Programming

(Incomplete) History of GUIs

DEMYSTIFYING PROGRAMMING: CHAPTER SIX METHODS (TOC DETAILED) CHAPTER SIX: METHODS 1

Window Interfaces Using Swing. Chapter 12

Educational Fusion. Implementing a Production Quality User Interface With JFC

Chapter 14. More Swing

Proctors are unable to respond to queries about the interpretation of exam questions. Do your best to answer exam questions as written.

GUI Forms and Events, Part II

Starting Out with Java: From Control Structures Through Objects Sixth Edition

1005ICT Object Oriented Programming Lecture Notes

Java Swing Introduction

Introduction to Graphical User Interfaces (GUIs) Lecture 10 CS2110 Fall 2008

Systems Programming Graphical User Interfaces

Graphics programming. COM6516 Object Oriented Programming and Design Adam Funk (originally Kirill Bogdanov & Mark Stevenson)

GUI Applications. Let s start with a simple Swing application in Java, and then we will look at the same application in Jython. See Listing 16-1.

G52PGP. Lecture oo3 Java (A real object oriented language)

All the Swing components start with J. The hierarchy diagram is shown below. JComponent is the base class.

Stating Your Preferences

Java. GUI building with the AWT

Eclipse Tutorial. For Introduction to Java Programming By Y. Daniel Liang

BASICS OF GRAPHICAL APPS

CS11 Java. Fall Lecture 3

CS415 Human Computer Interaction

CSC207 Week 4. Larry Zhang

Datenbank-Praktikum. Universität zu Lübeck Sommersemester 2006 Lecture: Swing. Ho Ngoc Duc 1

SINGLE EVENT HANDLING

Week Chapter Assignment SD Technology Standards. 1,2, Review Knowledge Check JP3.1. Program 5.1. Program 5.1. Program 5.2. Program 5.2. Program 5.

Widgets. Overview. Widget. Widgets Widget toolkits Lightweight vs. heavyweight widgets Swing Widget Demo

Graphical User Interfaces in Java Part 2

Page 1. Human-computer interaction. Lecture 2: Design & Implementation. Building user interfaces. Users and limitations

Graphical User Interfaces (GUIs)

To gain experience using GUI components and listeners.

News and info. Array. Feedback. Lab 4 is due this week. It should be easy to change the size of the game grid.

G51PGP Programming Paradigms. Lecture 009 Concurrency, exceptions

Final Exam CS 251, Intermediate Programming December 13, 2017

Chapter 13. Applets and HTML. HTML Applets. Chapter 13 Java: an Introduction to Computer Science & Programming - Walter Savitch 1

Handout 14 Graphical User Interface (GUI) with Swing, Event Handling

CMP 326 Midterm Fall 2015

CS 201 Software Development Methods Spring Tutorial #1. Eclipse

Java IDE Programming-I

Graphical User Interface (GUI)

CS 1316 Exam 3 Fall 2009

CPS122 Lecture: Graphical User Interfaces and Event-Driven Programming

Heavyweight with platform-specific widgets. AWT applications were limited to commonfunctionality that existed on all platforms.

Agenda. Container and Component

Overview. Lecture 7: Inheritance and GUIs. Inheritance. Example 9/30/2008

Outline. Introduction to Java. What Is Java? History. Java 2 Platform. Java 2 Platform Standard Edition. Introduction Java 2 Platform

Graphical User Interfaces. Comp 152

SE1021 Exam 2. When returning your exam, place your note-sheet on top. Page 1: This cover. Page 2 (Multiple choice): 10pts

CS 251 Intermediate Programming GUIs: Components and Layout

Lecture 3: Java Graphics & Events

1.00/1.001 Introduction to Computers and Engineering Problem Solving. Quiz 2: April 16, 2004

The NetBeans IDE is a big file --- a minimum of around 30 MB. After you have downloaded the file, simply execute the file to install the software.

Module Road Map. 7. Version Control with Subversion Introduction Terminology

Transcription:

Eclipsing Your IDE James W. Cooper I have been hearing about the Eclipse project for some months, and decided I had to take some time to play around with it. Eclipse is a development project (www.eclipse.org) for building development environments. And much of Eclipse is itself written in Java. Developers make specific development environments by writing specific modules called Eclipse plug-ins. And while, not surprisingly, Eclipse has been used to build a Java development environment, you could build HTML, JSP, XML or other language development systems just as well. In fact, a C/C++ development system has just been released. But the most surprising thing about Eclipse is that it is Open Source! You can get all the source code of the system and change or add anything you want. How does this work? Well, the license terms are pretty broad, but you can get the source code and change it, and make a new product and distribute it under your own license. If you distribute the source code, you have to distribute all of it under that license. And this is what IBM has done. Its Websphere Development Studio product is based on Eclipse, but is a product IBM sells in object code form. Needless to say, IBM is a major supporter of the Eclipse project, but so are a lot of other big players. Figure 1 The first Eclipse screen.

Eclipse is primarily a Java product, but as you can see in Figure 1, it looks pretty professional. One of the reasons for this is that Eclipse uses neither the AWT nor Swing. Instead, Eclipse uses its on GUI widget set called the SWT. The SWT is a graphics library and widget set that is integrated with the native windows system but which provides an OS-independent API. This means that Eclipse only runs on platforms where the underlying Jini code has been written to implement the SWT functions. However, since these platforms include Win32, and Linux a preponderance of today s workstation systems will run Eclipse. Actually, I find the features in this free development system pretty amazing. While it doesn t yet have a GUI designer, it does have a very nice debugger and class hierarchy viewer. Writing Code Using Eclipse The Eclipse Workbench IDE is quite sophisticated. It features syntax highlighting and keyword completion. In addition, if you right-click on the code window, you can select Format from the pop-up menu, allowing the system to align and prettify your code. Some people would probably prefer that it do this automatically and others prefer that it never do it, so this is a nice compromise. Eclipse actually compiles the code immediately each time you save it, so there is no real compile-edit cycle. If there is a syntax error, it will be marked each time you save the code. Let s consider the really simple visual Swing Hello program in Figure 2. When you click on the Click button it copies the text in the text field to the JLabel widget. Figure 2 A simple Swing Hello program. As you are no doubt aware, this is a really easy program to write, even without a GUI designer. It amounts to the following simple main program. public class TempCalc extends JxFrame implements ActionListener { private JTextField jtext; private JButton but; private JLabel lb; public TempCalc() { super("hi window"); //set up a 3 line grid layout

setlayout(new GridLayout(3, 1)); //create text field with default contents jtext = new JTextField("Hi there", 20); add(jtext); //create empty label lb = new JLabel(" "); lb.setfont(new Font("Arial", Font.BOLD, 14)); add(lb); //create a button but = new JButton("Click"); add(but); //call this action listener on click but.addactionlistener(this); this.setsize(300, 200); this.setvisible(true); //copy text field into label public void actionperformed(actionevent e) { lb.settext(jtext.gettext()); static public void main(string argv[]) { new TempCalc(); However, it is only that simple because we created a JxFrame class that buries some of Swing s complexities. In this class we set the Close window box to work, set the look and feel and create a top-level Jpanel that all controls are added to: public class JxFrame extends JFrame { private JPanel jp; public JxFrame(String title) { super(title); setcloseclick(); //make close box exit setlf(); //set look and feel jp = new JPanel(); //put JPanel inside layout getcontentpane().add(jp); //------ private void setcloseclick() { //create window listener to respond to window close click addwindowlistener(new WindowAdapter() { public void windowclosing(windowevent e) { System.exit(0); ); //------ private void setlf() { // Force SwingApp to come up in the System L&F String laf = UIManager.getSystemLookAndFeelClassName(); try { UIManager.setLookAndFeel(laf); catch (UnsupportedLookAndFeelException exc) { System.err.println("No LookAndFeel: " + laf);

catch (Exception exc) { System.err.println("Error" + laf + ": " + exc); We also created setlayout and add methods that under the covers operate on the panel we have added to the frame: //puts added components inside jpanel public void add(jcomponent c) { JPanel p = new JPanel(); jp.add(p); p.add(c); //------ //sets the layout of the JPanel public void setlayout(layoutmanager lay) { if (jp!= null) jp.setlayout(lay); else super.setlayout(lay); You can see how this program looks in the Eclipse environment in Figure 3 The Eclipse coding environment, showing the syntax-highlighted Java pane and the class outline. It also represents it as an outline as you see in Figure 4.

Figure 4 The Eclips e Java outline of our simple program. The Eclipse IDE also provides keyword completion. For any class instance, type the dot and, if you want, one or two characters of the beginning of the method name, and press Ctrl/Space. This is illustrated in Figure 5. Figure 5 Keyword completion in the Eclipse IDE. Debugging Now, I have a pretty good simplistic development environment using just Visual SlickEdit. It provides projects, make facilities and the ability to run programs form within the IDE. However, it does not provide any way to debug, and while using System.out.println stands many of us in good stead, having a real debugger with breakpoints can be very valuable. For instance, when I began writing the JxFrame class I show above, the program kept crashing in the setlayout method with a null reference exception. By putting a breakpoint in the setlayout method and in the constructor, I found that the setlayout method was called from the super method before the JPanel was instantiated.

//sets the layout of the JPanel public void setlayout(layoutmanager lay) { if (jp!= null) jp.setlayout(lay); else super.setlayout(lay); Thus, by providing a test for null, I was able to provide for both cases. Of course, you can also examine all the variables during debugging. When I put a breakpoint in the actionperfomed method, the variables window showed the data in Figure 6. Figure 6 Debugger variable display when breakpoint in actionperformed event is encountered. You can also right-click on any variable and select Display from the pop-up menu, and see that current value of that variable. Ah, Sweet History of Life Now, if like most programmers, you occasionally find that you have taken a turn down the wrong pathway and ended up in a programming cul-de-sac, where nothing works anymore, you probably say things like If only I could go back to the last version that worked and start over. You probably say a lot of other things, too, but I don t think Eclipse deals any better with expletives than do other development systems. But as far as history goes, Eclipse has a stunning, if slightly hidden feature. If you right click in the package list on any filename, and then select Replace with Local History, you get the stunning display shown in Figure 7.

Figure 7 The recent history of a class. You can select any earlier version and see the changes between it (on the left) and the current version (on the right). You can see the changes between any earlier version and the current version, and replace it. I found this feature invaluable as I tried to create the simplest possible graphical example. I also found that this local history difference record extends across invocations of Eclipse. You can always find the earlier versions. Refactoring We discussed the general idea of refactoring in the August, 2000 column. Refactoring just means rearranging your code to make it more efficient. The Eclipse workbench supports at least two kinds of refactoring: class renaming and method extraction. For example, we might decide that the class JxFrame could be named to something more evocative. So, we just select that class from the package list, and right-click and select rename. The system renames the class and all references to it in the project automatically as you see in Figure 8. Figure 8 Renaming a class using Eclipse s refactoring system.

Finally, you can select code from a method and move it to a new method to simplify your code. Just select the code and select Extract Method from the right click menu as shown in Figure 9. Figure 9 Extracting a method using Eclipse s refactoring system. Summary I think Eclipse is pretty powerful. It runs on two major platforms, and is certainly as powerful as any Linux tool you ll find. Certainly on Win32, there are a lot of nice commercial products, but this one is extremely impressive. And further, there is a lot of synergy in open source development projects, as Lawrence Lessig persuasively describes in his book, The History of Ideas. Open source tools develop faster and frequently contain fewer errors because there are so many people contributing to their success. I m certainly going to keep Eclipse on my workstations and keep up with its growth and development. References 1. Fowler, Martin, Refactoring, Addison-Wesley, 1999. 2. Lessig, Lawrence, The Future of Ideas: The Fate of Commons in a Connected World. Random House, 2001.