1. Swing Note: Most of the stuff stolen from or from the jdk documentation. Most programs are modified or written by me. This section explains the

Size: px
Start display at page:

Download "1. Swing Note: Most of the stuff stolen from or from the jdk documentation. Most programs are modified or written by me. This section explains the"

Transcription

1 1. Swing Note: Most of the stuff stolen from or from the jdk documentation. Most programs are modified or written by me. This section explains the various elements of the graphical user interface, i.e., most of the classes of the Swing using a set of very primitive applications. The classes are part of the package. Note: "Swing" was the codename of the project that developed the new components. Although it s an unofficial name, it s frequently used to refer to the new components and related API. It s immortalized in the package names for the Swing API, which begin with javax.swing.

2 JFC JFC stands for Java Foundation Classes, which encompass a group of features to help people build graphical user interfaces (GUIs). The JFC was first announced at the 1997 JavaOne developer conference and is defined as containing the following features: The Swing Components Include everything from buttons to split panes to tables. You can see mugshots of all the components in A Visual Index tothe Swing Components. Pluggable Look & Feel Support Gives any program that uses Swing components a choice of look and feel. For example, the same program can use either the Java Look & Feel or the Windows Look & Feel. We expect many more look-and-feel packages -- including some that use sound instead of a visual "look" -- to become available from various sources. Accessibility API Enables assistive technologies such as screen readers and Braille displays to get information from the user interface. Java 2D API (JDK 1.{234} only) Enables developers to easily incorporate high-quality 2D graphics, text, and images in applications and in applets. Drag and Drop Support (JDK 1.{234} only) Provides the ability to drag and drop between a Java application and a native application. The first three JFC features were implemented without any native code, relying only on the API defined in JDK 1.1. As a result, they could and did become available as an extension to JDK 1.1. This extension was released as JFC 1.1, which is sometimes called "the Swing release." The API in JFC 1.1 is often called the Swing API. Please see also

3 SwingSet 3 Download it from % cd /usr/local/jdk/demo/jfc/swingset3 && java -jar SwingSet2.jar % appletviewer SwingSet2.html SwingSet.html: <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN"> <html> <head> <title>swingset demo</title> </head> <body> <h1>swingset demo</h1> <applet code=swingset2applet codebase="." archive="swingset3.jar" width=695 height=525> </applet> </body> </html> 1.3. Top-Level Containers The components at the top of any Swing containment hierarchy. It exists mainly to provide a place for other Swing components to paint themselves. The commonly used top-level containers are frames (JFrame), dialogs (JDialog), and applets (JApplet). The following statement can be found here: but it does not work in MacOS 10/Sun OS 5.9. To view the containment hierarchy for any frame or dialog, click its border to select it, and then press Control-Shift-F1. A list of the containment hierarchy will be written to the standard output stream. Avisual index tothe swing components can be found at: 1.4. General-Purpose Containers Intermediate containers that can be used under many different circumstances.

4 Special-Purpose Containers Intermediate containers that play specific roles in the UI.

5 Basic Controls Atomic components that exist primarily to get input from the user; they generally also display some simple state.

6 Uneditable Information Displays Atomic components that exist solely to give the user information.

7 Editable Displays of Formatted Information Atomic components that display highly formatted information that (if you choose) can be edited by the user.

8 Swing versus AWT The AWT components are those provided by the JDK 1.0 and 1.1 platforms. Although JDK 1.3 still supports the AWT components, SUN strongly encourages to use Swing components instead. You can identify Swing components because their names start with J. The AWT button class, for example, is named Button, while the Swing button class is named JButton. Additionally, the AWT components are in the java/awt package, while the Swing components are in the javax.swing package. The biggest difference between the AWT components and Swing components is that the Swing components are implemented with absolutely no native code. Since Swing components aren t restricted to the least common denominator the features that are present on every platform they can have more functionality than AWT components. Because the Swing components have no native code, they can be be shipped as an add-on to JDK 1.1, in addition to being part of JDK 1.3.

9 -9- Even the simplest Swing components have capabilities far beyond what the AWT components offer: Swing buttons and labels can display images instead of, or in addition to, text. You can easily add or change the borders drawn around most Swing components. For example, it s easy to put a box around the outside of a container or label. You can easily change the behavior or appearance of a Swing component by either invoking methods on it or creating a subclass of it. Swing components don t have to be rectangular. Buttons, for example, can be round. Assistive technologies such as screen readers can easily get information from Swing components. For example, a tool can easily get the text that s displayed on a button or label.

10 -10- Swing lets you specify which look and feel your program s GUI uses. By contrast, AWT components always have the look and feel of the native platform. CDE: Java:

11 -11- Windows: Another interesting feature is that Swing components with state use models to keep the state. AJSlider, for instance, uses a BoundedRangeModel object to hold its current value and range of legal values. Models are set up automatically, so you don t have to deal with them unless you want to take advantage of the power they can give you. Swing components aren t thread safe. If you modify a visible Swing component -- invoking its settext method, for example -- from anywhere but an event handler, then you need to take special steps to make the modification execute on the event-dispatching thread. This isn t an issue for many Swing programs, since component-modifying code is typically in event handlers. The containment hierarchy for any window or applet that contains Swing components must have a Swing top-level container at the root of the hierarchy. For example, a main window should be implemented as a JFrame instance rather than as a Frame instance. You don t add components directly to a top-level container such as a JFrame. Instead, you add components to a container (called the content pane) that is itself contained by the JFrame.

12 The First Swing Program 1 import javax.swing.*; //This is the final package name. 2 import java.awt.*; 3 import java.awt.event.*; 4 5 public class SwingApplication { 6 private static String labelprefix = "So many clicks: "; 7 private int numclicks = 0; 8 9 public Component createcomponents() { 10 final JLabel label = new JLabel(labelPrefix + "0 "); JButton button = new JButton("Swing button!"); button.addactionlistener( 15 new ActionListener() { 16 public void actionperformed(actionevent e) { 17 numclicks++; 18 label.settext(labelprefix + numclicks); 19 System.out.println("getActionCommand: " + 20 e.getactioncommand()); 21 System.out.println("getModifiers: " + 22 e.getmodifiers()); 23 System.out.println("paramString: " + 24 e.paramstring()); 25 } 26 } 27 ); 28 label.setlabelfor(button); /* 31 * An easy way to put space between a top-level container 32 * and its contents is to put the contents in a JPanel 33 * that has an "empty" border. 34 */ 35 JPanel pane = new JPanel(); 36 pane.setborder(borderfactory.createemptyborder( 37 30, //top 38 30, //left 39 10, //bottom 40 30) //right 41 ); 42 // rows column 43 // pane.setlayout(new GridLayout(4, 1)); 44 pane.setlayout(new FlowLayout()); 45 pane.add(button); 46 pane.add( new JFileChooser()) ; 47 pane.add(new JCheckBox("not me", true) ); 48 pane.add(label); return pane; 51 }

13 public static void main(string[] args) { 54 String lookandfeel; lookandfeel=uimanager.getcrossplatformlookandfeelclassname(); 57 if ( args.length == 1 ) 58 { 59 if ( args[0].equals("motif") ) 60 lookandfeel = 61 "com.sun.java.swing.plaf.motif.motiflookandfeel"; 62 if ( args[0].equals("metal") ) 63 lookandfeel = 64 "javax.swing.plaf.metal.metallookandfeel"; 65 else if ( args[0].equals("system") ) 66 lookandfeel= 67 UIManager.getSystemLookAndFeelClassName() ; 68 } 69 try { 70 UIManager.setLookAndFeel( lookandfeel); 71 } catch (Exception e) { } //Create the top-level container and add contents to it. 74 JFrame frame = new JFrame("SwingApplication"); 75 SwingApplication app = new SwingApplication(); 76 Component contents = app.createcomponents(); 77 frame.getcontentpane().add(contents); //Finish setting up the frame, and show it. 80 frame.addwindowlistener(new WindowAdapter() { 81 public void windowclosing(windowevent e) { 82 System.exit(0); 83 } 84 }); 85 frame.pack(); 86 frame.setvisible(true); 87 } 88 } Source Code: Src/12/SwingApplication.java Output: getactioncommand: Swing button! getmodifiers: 0 paramstring: ACTION_PERFORMED,cmd=Swing button! getactioncommand: Swing button! getmodifiers: 0 paramstring: ACTION_PERFORMED,cmd=Swing button! getactioncommand: Swing button! getmodifiers: 0... Default:

14 Motif: -14-

15 Layout Management Layout management is the process of determining the size and position of components. By default, each container has a layout manager -- an object that performs layout management for the components within the container. Components can provide size and alignment hints to layout managers, but layout managers have the final say on the size and position of those components. The Java platform supplies five commonly used layout managers: BorderLayout, BoxLayout, FlowLayout, GridBagLayout, and GridLayout. These layout managers are designed for displaying multiple components at once. A sixth provided class, CardLayout, is a special-purpose layout manager used in combination with other layout managers. Whenever you use the add method to put a component in a container, you must take the container s layout manager into account. Some layout managers, such as BorderLayout, require you to specify the component s relative position in the container, using an additional argument with the add method. Occasionally, a layout manager such as GridBagLayout requires elaborate setup procedures. Many layout managers, however, simply place components based on the order they were added to their container Layout Manager See also GridLayout Manager The GridLayout class is a layout manager that lays out a container s components in a rectangular grid. The container is divided into equal-sized rectangles, and one component is placed in each rectangle GridBagLayout Manager GridBagLayout is the most sophisticated, flexible layout manager the Java platform provides. It aligns components by placing them within a grid of cells, allowing some components to span more than one cell. The rows in the grid aren t necessarily all the same height; similarly, grid columns can have different widths FlowLayout Manager A flow layout arranges components in a left-to-right flow, much like lines of text in a paragraph. Flow layouts are typically used to arrange buttons in a panel. It will arrange buttons left to right until no more buttons fit on the same line. Each line is centered Viewport Manager The default layout manager for JViewport. JViewportLayout defines a policy for layout that should be useful for most applications. The viewport makes its view the same size as the viewport, however it will not make the view smaller than its minimum size. As the viewport grows the view is kept bottom justified until the entire view isvisible, subsequently the view iskept top justified.

16 ScrollPaneLayout Manager The layout manager used by JScrollPane. JScrollPaneLayout is responsible for nine components: a viewport, two scrollbars, a row header, acolumn header, and four "corner" components.

17 A Calculator Layout 1 import javax.swing.*; //This is the final package name. 2 import java.awt.*; 3 import java.awt.event.*; 4 5 public class Calculator { 6 private JLabel label = null; 7 private int numclicks = 0; 8 9 public Component createlabel() { 10 final JLabel label = new JLabel("0"); 11 label.settext("0"); 12 label.sethorizontalalignment(jlabel.right); 13 this.label = label; 14 return label; 15 } public Component createbuttons() { 18 JPanel pane = new JPanel(); 19 pane.setborder(borderfactory.createloweredbevelborder()); 20 // 5 rows 2 collums // 21 pane.setlayout(new GridLayout(5, 2)); 22 for ( int index = 0; index < 10; index ++ ) { 23 JButton button = new JButton(new Integer(index).toString()); 24 button.addactionlistener( 25 new ActionListener() { 26 public void actionperformed(actionevent e) { 27 label.settext(e.getactioncommand()); 28 } 29 } 30 ); 31 pane.add(button); 32 } return pane; 35 } 36 public Component createops() { 37 JPanel pane = new JPanel(); 38 pane.setborder(borderfactory.createloweredbevelborder()); pane.setlayout(new GridLayout(2, 2)); 41 pane.add(new Button("+")); 42 pane.add(new Button("-")); 43 pane.add(new Button("*")); 44 pane.add(new Button("/")); return pane; 47 } 48 public Component createcomponents() { 49 JPanel pane = new JPanel(); 50 pane.setborder(borderfactory.createloweredbevelborder()); 51

18 pane.setlayout(new FlowLayout( FlowLayout.CENTER, 5, 5) ); 53 pane.add(createlabel()); 54 pane.add(createbuttons()); 55 pane.add(createops()); return pane; 58 } public static void main(string[] args) { 61 String lookandfeel; lookandfeel=uimanager.getcrossplatformlookandfeelclassname(); 64 if ( args.length == 1 ) 65 { 66 if ( args[0].equals("motif") ) 67 lookandfeel = 68 "com.sun.java.swing.plaf.motif.motiflookandfeel"; 69 if ( args[0].equals("metal") ) 70 lookandfeel = 71 "javax.swing.plaf.metal.metallookandfeel"; 72 else if ( args[0].equals("system") ) 73 lookandfeel= 74 UIManager.getSystemLookAndFeelClassName() ; 75 } 76 try { 77 UIManager.setLookAndFeel( lookandfeel); 78 } catch (Exception e) { } //Create the top-level container and add contents to it. 81 JFrame frame = new JFrame("Calculator"); 82 Calculator app = new Calculator(); 83 Component contents = app.createcomponents(); frame.getcontentpane().add(contents); //Finish setting up the frame, and show it. 88 frame.addwindowlistener(new WindowAdapter() { 89 public void windowclosing(windowevent e) { 90 System.exit(0); 91 } 92 }); 93 frame.pack(); 94 frame.setvisible(true); 95 } 96 } Source Code: Src/12/Calculator.java GridBagLayout Essentially, GridBagLayout places components in rectangles (cells) in a grid, and then uses the components preferred sizes to determine how big the cells should be.

19 -19- Source Code: 1 2 import javax.swing.*; //This is the final package name. 3 import java.awt.*; 4 import java.awt.event.*; 5 6 public class GB { 7 8 public Component createcomponents() { 9 JButton button; 10 JPanel contentpane = new JPanel(); 11 GridBagLayout gridbag = new GridBagLayout(); 12 GridBagConstraints c = new GridBagConstraints(); 13 contentpane.setlayout(gridbag); 14 c.fill = GridBagConstraints.HORIZONTAL; button = new JButton("Button 1"); 17 c.weightx = 0.5; 18 c.gridx = 0; 19 c.gridy = 0; 20 gridbag.setconstraints(button, c); 21 contentpane.add(button); button = new JButton("2"); 24 c.weightx = 4; 25 c.gridx = 1; 26 c.gridy = 0; 27 gridbag.setconstraints(button, c); 28 contentpane.add(button); button = new JButton("Button 3"); 31 c.weightx = 8; 32 c.gridx = 2; 33 c.gridy = 0; 34 gridbag.setconstraints(button, c); 35 contentpane.add(button); button = new JButton("Long-Named Button 4"); 38 c.ipady = 40; //make this component tall 39 c.weightx = 0.0; 40 c.insets = new Insets(20,0,0,0); //top padding 41 c.gridwidth = 3; 42 c.gridx = 0; 43 c.gridy = 1; 44 gridbag.setconstraints(button, c); 45 contentpane.add(button); button = new JButton("Button 5"); 48 c.ipady = 0; //reset to default 49 c.weighty = 1.0; //request any extra vertical space 50 c.anchor = GridBagConstraints.SOUTH; //bottom of space 51 c.insets = new Insets(10,0,0,0); //top padding

20 c.gridx = 1; //aligned with button 2 53 c.gridwidth = 2; //2 columns wide 54 c.gridy = 2; //third row 55 gridbag.setconstraints(button, c); 56 contentpane.add(button); 57 return contentpane; 58 } public static void main(string[] args) { String lookandfeel = UIManager.getCrossPlatformLookAndFeelClassName(); try { 65 UIManager.setLookAndFeel( lookandfeel); 66 } catch (Exception e) { } JFrame frame = new JFrame("GB"); 69 GB app = new GB(); 70 Component contents = app.createcomponents(); frame.getcontentpane().add(contents); //Finish setting up the frame, and show it. 75 frame.addwindowlistener(new WindowAdapter() { 76 public void windowclosing(windowevent e) { 77 System.exit(0); 78 } 79 }); 80 frame.pack(); 81 frame.setvisible(true); 82 } 83 } Source Code: Src/12/GB.java When you enlarge the window the program brings up, the columns grow proportionately. This is because each component in the first row, where each component is one column wide, has weightx = 1.0. The actual value of these components weightx is unimportant. What matters is that all the components, and consequently, all the columns, have an equal weight that is greater than 0. If no component managed by the GridBagLayout had weightx set, then when the components container was made wider, the components would stay clumped together in the center of the container.

21 1.20. A Second Try -21-

22 import javax.swing.*; //This is the final package name. 3 import java.awt.*; 4 import java.awt.event.*; 5 6 public class Lotto { 7 8 public void createbuttons( GridBagLayout gridbag, 9 JPanel contentpane, 10 int gridy) { 11 int number = 1; GridBagConstraints c = new GridBagConstraints(); 14 c.gridwidth = 1; 15 c.weightx = 1.0; 16 c.insets = new Insets(5,3,3,5); 17 c.fill = GridBagConstraints.BOTH; 18 JButton button ; 19 JButton o ; for ( int col = 1; col <= 7; col ++ ) { 23 for ( int row = 1; row <= 7; row ++ ) { 24 button = new JButton( 25 new Integer(number++).toString() ); 26 button.setbackground(color.yellow); 27 button.setminimumsize( 28 button.getsize() ); 29 button.addactionlistener( 30 new ActionListener() { 31 public void actionperformed(actionevent e) { 32 o = (JButton)e.getSource(); // will this compile 33 System.out.println("getText = " + 34 o.gettext()); 35 if ( o.getbackground() == Color.red) 36 o.setbackground(color.yellow); 37 else 38 o.setbackground(color.red); 39 } 40 } 41 ); 42 c.gridx = row ; 43 c.gridy = col + gridy; 44 gridbag.setconstraints(button, c); 45 contentpane.add(button); 46 } 47 } 48 } public void createseparator( GridBagLayout gridbag, 51 JPanel contentpane, 52 int gridy) { 53 GridBagConstraints c = new GridBagConstraints();

23 JSeparator sep = new JSeparator(SwingConstants.HORIZONTAL); c.fill = GridBagConstraints.BOTH; 57 c.gridx = 0; 58 c.gridy = gridy; 59 c.gridwidth = 8; 60 c.insets = new Insets(5,3,3,5); 61 gridbag.setconstraints(sep, c); 62 contentpane.add(sep); 63 } public Component createcomponents() { 66 JSeparator sep; 67 JButton button; 68 JLabel label; 69 JPanel contentpane = new JPanel(); 70 GridBagLayout gridbag = new GridBagLayout(); 71 GridBagConstraints c = new GridBagConstraints(); 72 contentpane.setlayout(gridbag); label = new JLabel("0"); 75 c.weightx = 0.5; 76 c.gridx = 0; 77 c.gridy = 0; 78 c.gridwidth = 8; 79 c.ipady = 10; 80 gridbag.setconstraints(label, c); 81 contentpane.add(label); createseparator(gridbag, contentpane, 1); 84 createbuttons(gridbag, contentpane, 3); 85 createseparator(gridbag, contentpane, 11); JLabel label_1 = new JLabel("0 correct"); 88 c.weightx = 0.5; 89 c.gridx = 0; 90 c.gridy = 12; 91 c.gridwidth = 4; 92 c.ipady = 10; 93 gridbag.setconstraints(label_1, c); 94 contentpane.add(label_1); JTextField tfield = new JTextField("0", 5); 97 tfield.sethorizontalalignment(jtextfield.right); 98 tfield.seteditable(false); 99 c.weightx = 0.5; 00 c.gridx = 4; 01 c.gridy = 12; 02 c.gridwidth = 4; 03 c.ipady = 10; 04 gridbag.setconstraints(tfield, c); 05 contentpane.add(tfield); createseparator(gridbag, contentpane, 13);

24 return contentpane; } public static void main(string[] args) { String lookandfeel = UIManager.getCrossPlatformLookAndFeelClassName(); try { 18 UIManager.setLookAndFeel( lookandfeel); 19 } catch (Exception e) { } JFrame frame = new JFrame("Lotto"); 22 Lotto app = new Lotto(); 23 Component contents = app.createcomponents(); frame.getcontentpane().add(contents); //Finish setting up the frame, and show it. 28 frame.addwindowlistener(new WindowAdapter() { 29 public void windowclosing(windowevent e) { 30 System.exit(0); 31 } 32 }); 33 frame.pack(); 34 frame.setvisible(true); 35 } 36 } Source Code: Src/12/Lotto.java General Ideas for Selecting a Layout Manager Divide the area in logical pieces Dothe objecs form a regular/grid pattern? What should happen if there is a change in size? How tochoose a Layout Manager Stolen from Youneed to display a component in as much space as it can get. Consider using BorderLayout or GridBagLayout. If you use BorderLayout, you ll need to put the space-hungry component in the center. With GridBagLayout, you ll need to set the constraints for the component so that fill=gridbagconstraints.both. Another possibility is to use BoxLayout, making the space-hungry component specify very large preferred and maximum sizes. Youneed to display a few components in a compact row attheir natural size. Consider using a JPanel to group the components and using either the JPanel s default FlowLayout manager or the BoxLayout manager.

25 -25- Youneed to display a few components of the same size in rows and columns. GridLayout is perfect for this. You need to display a few components in a row or column, possibly with varying amounts of space between them, custom alignment, or custom component sizes. BoxLayout is perfect for this. You have a complex layout with many components. Consider either using GridBagLayout or grouping the components into one or more JPanels to simplify layout. Each JPanel might use a different layout manager Creating a Custom Layout Manager Instead of using one of the Java platform s layout managers, you can write your own. Layout managers must implement the LayoutManager interface, which specifies the five methods every layout manager must define. Optionally, layout managers can implement LayoutManager2, which is a subinterface of Layout- Manager.

26 -26-

Introduction to the JAVA UI classes Advanced HCI IAT351

Introduction to the JAVA UI classes Advanced HCI IAT351 Introduction to the JAVA UI classes Advanced HCI IAT351 Week 3 Lecture 1 17.09.2012 Lyn Bartram lyn@sfu.ca About JFC and Swing JFC Java TM Foundation Classes Encompass a group of features for constructing

More information

(Incomplete) History of GUIs

(Incomplete) History of GUIs CMSC 433 Programming Language Technologies and Paradigms Spring 2004 Graphical User Interfaces April 20, 2004 (Incomplete) History of GUIs 1973: Xerox Alto 3-button mouse, bit-mapped display, windows 1981:

More information

encompass a group of features for building Graphical User Interfaces (GUI).

encompass a group of features for building Graphical User Interfaces (GUI). Java GUI (intro) JFC Java Foundation Classes encompass a group of features for building Graphical User Interfaces (GUI). javax.swing.* used for building GUIs. Some basic functionality is already there

More information

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

Introduction to Graphical Interface Programming in Java. Introduction to AWT and Swing Introduction to Graphical Interface Programming in Java Introduction to AWT and Swing GUI versus Graphics Programming Graphical User Interface (GUI) Graphics Programming Purpose is to display info and

More information

Graphic User Interfaces. - GUI concepts - Swing - AWT

Graphic User Interfaces. - GUI concepts - Swing - AWT Graphic User Interfaces - GUI concepts - Swing - AWT 1 What is GUI Graphic User Interfaces are used in programs to communicate more efficiently with computer users MacOS MS Windows X Windows etc 2 Considerations

More information

Window Interfaces Using Swing Objects

Window Interfaces Using Swing Objects Chapter 12 Window Interfaces Using Swing Objects Event-Driven Programming and GUIs Swing Basics and a Simple Demo Program Layout Managers Buttons and Action Listeners Container Classes Text I/O for GUIs

More information

Window Interfaces Using Swing Objects

Window Interfaces Using Swing Objects Chapter 12 Window Interfaces Using Swing Objects Event-Driven Programming and GUIs Swing Basics and a Simple Demo Program Layout Managers Buttons and Action Listeners Container Classes Text I/O for GUIs

More information

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

All the Swing components start with J. The hierarchy diagram is shown below. JComponent is the base class. Q1. If you add a component to the CENTER of a border layout, which directions will the component stretch? A1. The component will stretch both horizontally and vertically. It will occupy the whole space

More information

CS 251 Intermediate Programming GUIs: Components and Layout

CS 251 Intermediate Programming GUIs: Components and Layout CS 251 Intermediate Programming GUIs: Components and Layout Brooke Chenoweth University of New Mexico Fall 2017 import javax. swing.*; Hello GUI public class HelloGUI extends JFrame { public HelloGUI ()

More information

China Jiliang University Java. Programming in Java. Java Swing Programming. Java Web Applications, Helmut Dispert

China Jiliang University Java. Programming in Java. Java Swing Programming. Java Web Applications, Helmut Dispert Java Programming in Java Java Swing Programming Java Swing Design Goals The overall goal for the Swing project was: To build a set of extensible GUI components to enable developers to more rapidly develop

More information

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

Graphics programming. COM6516 Object Oriented Programming and Design Adam Funk (originally Kirill Bogdanov & Mark Stevenson) Graphics programming COM6516 Object Oriented Programming and Design Adam Funk (originally Kirill Bogdanov & Mark Stevenson) Overview Aims To provide an overview of Swing and the AWT To show how to build

More information

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

Introduction to Graphical User Interfaces (GUIs) Lecture 10 CS2110 Fall 2008 Introduction to Graphical User Interfaces (GUIs) Lecture 10 CS2110 Fall 2008 Announcements A3 is up, due Friday, Oct 10 Prelim 1 scheduled for Oct 16 if you have a conflict, let us know now 2 Interactive

More information

Graphical User Interface (GUI)

Graphical User Interface (GUI) Graphical User Interface (GUI) Layout Managment 1 Hello World Often have a static method: createandshowgui() Invoked by main calling invokelater private static void createandshowgui() { } JFrame frame

More information

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

Part 3: Graphical User Interface (GUI) & Java Applets 1,QWURGXFWLRQWR-DYD3URJUDPPLQJ (( Part 3: Graphical User Interface (GUI) & Java Applets EE905-GUI 7RSLFV Creating a Window Panels Event Handling Swing GUI Components ƒ Layout Management ƒ Text Field ƒ

More information

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

Control Flow: Overview CSE3461. An Example of Sequential Control. Control Flow: Revisited. Control Flow Paradigms: Reacting to the User CSE3461 Control Flow Paradigms: Reacting to the User Control Flow: Overview Definition of control flow: The sequence of execution of instructions in a program. Control flow is determined at run time by

More information

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

Lab 4. D0010E Object-Oriented Programming and Design. Today s lecture. GUI programming in Lab 4 D0010E Object-Oriented Programming and Design Lecture 9 Lab 4: You will implement a game that can be played over the Internet. The networking part has already been written. Among other things, the

More information

Java Graphical User Interfaces

Java Graphical User Interfaces Java Graphical User Interfaces 1 The Abstract Windowing Toolkit (AWT) Since Java was first released, its user interface facilities have been a significant weakness The Abstract Windowing Toolkit (AWT)

More information

Graphical User Interfaces (GUIs)

Graphical User Interfaces (GUIs) CMSC 132: Object-Oriented Programming II Graphical User Interfaces (GUIs) Department of Computer Science University of Maryland, College Park Model-View-Controller (MVC) Model for GUI programming (Xerox

More information

What is Widget Layout? Laying Out Components. Resizing a Window. Hierarchical Widget Layout. Interior Design for GUIs

What is Widget Layout? Laying Out Components. Resizing a Window. Hierarchical Widget Layout. Interior Design for GUIs What is Widget Layout? Laying Out Components Positioning widgets in their container (typically a JPanel or a JFrame s content pane) Basic idea: each widget has a size and position Main problem: what if

More information

CSE 143. Event-driven Programming and Graphical User Interfaces (GUIs) with Swing/AWT

CSE 143. Event-driven Programming and Graphical User Interfaces (GUIs) with Swing/AWT CSE 143 Event-driven Programming and Graphical User Interfaces (GUIs) with Swing/AWT slides created by Marty Stepp based on materials by M. Ernst, S. Reges, D. Notkin, R. Mercer, Wikipedia http://www.cs.washington.edu/331/

More information

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

Java Swing. based on slides by: Walter Milner. Java Swing Walter Milner 2005: Slide 1 Java Swing based on slides by: Walter Milner Java Swing Walter Milner 2005: Slide 1 What is Swing? A group of 14 packages to do with the UI 451 classes as at 1.4 (!) Part of JFC Java Foundation Classes

More information

Building Graphical User Interfaces. Overview

Building Graphical User Interfaces. Overview Building Graphical User Interfaces 4.1 Overview Constructing GUIs Interface components GUI layout Event handling 2 1 GUI Principles Components: GUI building blocks. Buttons, menus, sliders, etc. Layout:

More information

Java: Graphical User Interfaces (GUI)

Java: Graphical User Interfaces (GUI) Chair of Software Engineering Carlo A. Furia, Marco Piccioni, and Bertrand Meyer Java: Graphical User Interfaces (GUI) With material from Christoph Angerer The essence of the Java Graphics API Application

More information

Laying Out Components. What is Widget Layout?

Laying Out Components. What is Widget Layout? Laying Out Components Interior Design for GUIs What is Widget Layout? Positioning widgets in their container (typically a JPanel or a JFrame s content pane) Basic idea: each widget has a size and position

More information

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

CSEN401 Computer Programming Lab. Topics: Graphical User Interface Window Interfaces using Swing CSEN401 Computer Programming Lab Topics: Graphical User Interface Window Interfaces using Swing Prof. Dr. Slim Abdennadher 22.3.2015 c S. Abdennadher 1 Swing c S. Abdennadher 2 AWT versus Swing Two basic

More information

Building Graphical User Interfaces. GUI Principles

Building Graphical User Interfaces. GUI Principles Building Graphical User Interfaces 4.1 GUI Principles Components: GUI building blocks Buttons, menus, sliders, etc. Layout: arranging components to form a usable GUI Using layout managers. Events: reacting

More information

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

Command-Line Applications. GUI Libraries GUI-related classes are defined primarily in the java.awt and the javax.swing packages. 1 CS257 Computer Science I Kevin Sahr, PhD Lecture 14: Graphical User Interfaces Command-Line Applications 2 The programs we've explored thus far have been text-based applications A Java application is

More information

Overview. Building Graphical User Interfaces. GUI Principles. AWT and Swing. Constructing GUIs Interface components GUI layout Event handling

Overview. Building Graphical User Interfaces. GUI Principles. AWT and Swing. Constructing GUIs Interface components GUI layout Event handling Overview Building Graphical User Interfaces Constructing GUIs Interface components GUI layout Event handling 4.1 GUI Principles AWT and Swing Components: GUI building blocks. Buttons, menus, sliders, etc.

More information

Swing UI. Powered by Pentalog. by Vlad Costel Ungureanu for Learn Stuff

Swing UI. Powered by Pentalog. by Vlad Costel Ungureanu for Learn Stuff Swing UI by Vlad Costel Ungureanu for Learn Stuff User Interface Command Line Graphical User Interface (GUI) Tactile User Interface (TUI) Multimedia (voice) Intelligent (gesture recognition) 2 Making the

More information

Advanced Java Programming. Swing. Introduction to Swing. Swing libraries. Eran Werner, Tel-Aviv University Summer, 2005

Advanced Java Programming. Swing. Introduction to Swing. Swing libraries. Eran Werner, Tel-Aviv University Summer, 2005 Advanced Java Programming Swing Eran Werner, Tel-Aviv University Summer, 2005 19 May 2005 Advanced Java Programming, Summer 2005 1 Introduction to Swing The Swing package is part of the Java Foundation

More information

11/6/15. Objec&ves. RouleQe. Assign 8: Understanding Code. Assign 8: Bug. Assignment 8 Ques&ons? PROGRAMMING PARADIGMS

11/6/15. Objec&ves. RouleQe. Assign 8: Understanding Code. Assign 8: Bug. Assignment 8 Ques&ons? PROGRAMMING PARADIGMS Objec&ves RouleQe Assign 8: Refactoring for Extensibility Programming Paradigms Introduc&on to GUIs in Java Ø Event handling Nov 6, 2015 Sprenkle - CSCI209 1 Nov 6, 2015 Sprenkle - CSCI209 2 Assign 8:

More information

Graphical User Interface (GUI) components in Java Applets. With Abstract Window Toolkit (AWT) we can build an applet that has the basic GUI

Graphical User Interface (GUI) components in Java Applets. With Abstract Window Toolkit (AWT) we can build an applet that has the basic GUI CBOP3203 Graphical User Interface (GUI) components in Java Applets. With Abstract Window Toolkit (AWT) we can build an applet that has the basic GUI components like button, text input, scroll bar and others.

More information

Java Swing. Lists Trees Tables Styled Text Components Progress Indicators Component Organizers

Java Swing. Lists Trees Tables Styled Text Components Progress Indicators Component Organizers Course Name: Advanced Java Lecture 19 Topics to be covered Java Swing Lists Trees Tables Styled Text Components Progress Indicators Component Organizers AWT to Swing AWT: Abstract Windowing Toolkit import

More information

GUI Basics. Object Orientated Programming in Java. Benjamin Kenwright

GUI Basics. Object Orientated Programming in Java. Benjamin Kenwright GUI Basics Object Orientated Programming in Java Benjamin Kenwright Outline Essential Graphical User Interface (GUI) Concepts Libraries, Implementation, Mechanics,.. Abstract Windowing Toolkit (AWT) Java

More information

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

Topic 9: Swing. Swing is a BIG library Goal: cover basics give you concepts & tools for learning more Swing = Java's GUI library Topic 9: Swing Swing is a BIG library Goal: cover basics give you concepts & tools for learning more Assignment 5: Will be an open-ended Swing project. "Programming Contest"

More information

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!

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! Swing = Java's GUI library Topic 9: Swing Swing is a BIG library Goal: cover basics give you concepts & tools for learning more Why are we studying Swing? 1. Useful & fun! 2. Good application of OOP techniques

More information

Graphical User Interface (GUI)

Graphical User Interface (GUI) Graphical User Interface (GUI) Layout Managment 1 Hello World Often have a run method to create and show a GUI Invoked by main calling invokelater private void run() { } JFrame frame = new JFrame("HelloWorldSwing");

More information

Graphical User Interfaces. Comp 152

Graphical User Interfaces. Comp 152 Graphical User Interfaces Comp 152 Procedural programming Execute line of code at a time Allowing for selection and repetition Call one function and then another. Can trace program execution on paper from

More information

Eclipsing Your IDE. Figure 1 The first Eclipse screen.

Eclipsing Your IDE. Figure 1 The first Eclipse screen. 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)

More information

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

Frames, GUI and events. Introduction to Swing Structure of Frame based applications Graphical User Interface (GUI) Events and event handling Frames, GUI and events Introduction to Swing Structure of Frame based applications Graphical User Interface (GUI) Events and event handling Introduction to Swing The Java AWT (Abstract Window Toolkit)

More information

Packages: Putting Classes Together

Packages: Putting Classes Together Packages: Putting Classes Together 1 Introduction 2 The main feature of OOP is its ability to support the reuse of code: Extending the classes (via inheritance) Extending interfaces The features in basic

More information

Using Several Components

Using Several Components Ch. 16 pt 2 GUIs Using Several Components How do we arrange the GUI components? Using layout managers. How do we respond to event from several sources? Create separate listeners, or determine the source

More information

User interfaces and Swing

User interfaces and Swing User interfaces and Swing Overview, applets, drawing, action listening, layout managers. APIs: java.awt.*, javax.swing.*, classes names start with a J. Java Lectures 1 2 Applets public class Simple extends

More information

PROGRAMMING DESIGN USING JAVA (ITT 303) Unit 7

PROGRAMMING DESIGN USING JAVA (ITT 303) Unit 7 PROGRAMMING DESIGN USING JAVA (ITT 303) Graphical User Interface Unit 7 Learning Objectives At the end of this unit students should be able to: Build graphical user interfaces Create and manipulate buttons,

More information

Graphical User Interface (GUI)

Graphical User Interface (GUI) Graphical User Interface (GUI) An example of Inheritance and Sub-Typing 1 Java GUI Portability Problem Java loves the idea that your code produces the same results on any machine The underlying hardware

More information

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

Outline. Topic 9: Swing. GUIs Up to now: line-by-line programs: computer displays text user types text AWT. A. Basics Topic 9: Swing Outline Swing = Java's GUI library Swing is a BIG library Goal: cover basics give you concepts & tools for learning more Assignment 7: Expand moving shapes from Assignment 4 into game. "Programming

More information

Systems Programming Graphical User Interfaces

Systems Programming Graphical User Interfaces Systems Programming Graphical User Interfaces Julio Villena Román (LECTURER) CONTENTS ARE MOSTLY BASED ON THE WORK BY: José Jesús García Rueda Systems Programming GUIs based on Java

More information

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

Starting Out with Java: From Control Structures Through Objects Sixth Edition Starting Out with Java: From Control Structures Through Objects Sixth Edition Chapter 12 A First Look at GUI Applications Chapter Topics 12.1 Introduction 12.2 Creating Windows 12.3 Equipping GUI Classes

More information

CSE 331. Event-driven Programming and Graphical User Interfaces (GUIs) with Swing/AWT

CSE 331. Event-driven Programming and Graphical User Interfaces (GUIs) with Swing/AWT CSE 331 Event-driven Programming and Graphical User Interfaces (GUIs) with Swing/AWT slides created by Marty Stepp based on materials by M. Ernst, S. Reges, D. Notkin, R. Mercer, Wikipedia http://www.cs.washington.edu/331/

More information

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

GUI and its COmponent Textfield, Button & Label. By Iqtidar Ali GUI and its COmponent Textfield, Button & Label By Iqtidar Ali GUI (Graphical User Interface) GUI is a visual interface to a program. GUI are built from GUI components. A GUI component is an object with

More information

Goals. Lecture 7 More GUI programming. The application. The application D&D 12. CompSci 230: Semester JFrame subclass: ListOWords

Goals. Lecture 7 More GUI programming. The application. The application D&D 12. CompSci 230: Semester JFrame subclass: ListOWords Goals By the end of this lesson, you should: Lecture 7 More GUI programming 1. Be able to write Java s with JTextField, JList, JCheckBox and JRadioButton components 2. Be able to implement a ButtonGroup

More information

Chapter 8. Java continued. CS Hugh Anderson s notes. Page number: 264 ALERT. MCQ test next week. This time. This place.

Chapter 8. Java continued. CS Hugh Anderson s notes. Page number: 264 ALERT. MCQ test next week. This time. This place. Chapter 8 Java continued CS3283 - Hugh Anderson s notes. Page number: 263 ALERT MCQ test next week This time This place Closed book CS3283 - Hugh Anderson s notes. Page number: 264 ALERT Assignment #2

More information

Java continued. Chapter 8 ALERT ALERT. Last week. MCQ test next week. This time. This place. Closed book. Assignment #2 is for groups of 3

Java continued. Chapter 8 ALERT ALERT. Last week. MCQ test next week. This time. This place. Closed book. Assignment #2 is for groups of 3 Chapter 8 Java continued MCQ test next week This time This place Closed book ALERT CS3283 - Hugh Anderson s notes. Page number: 263 CS3283 - Hugh Anderson s notes. Page number: 264 ALERT Last week Assignment

More information

INTRODUCTION TO (GUIS)

INTRODUCTION TO (GUIS) INTRODUCTION TO GRAPHICAL USER INTERFACES (GUIS) Lecture 10 CS2110 Fall 2009 Announcements 2 A3 will be posted shortly, please start early Prelim 1: Thursday October 14, Uris Hall G01 We do NOT have any

More information

Java Swing Introduction

Java Swing Introduction Course Name: Advanced Java Lecture 18 Topics to be covered Java Swing Introduction What is Java Swing? Part of the Java Foundation Classes (JFC) Provides a rich set of GUI components Used to create a Java

More information

Swing. By Iqtidar Ali

Swing. By Iqtidar Ali Swing By Iqtidar Ali Background of Swing We have been looking at AWT (Abstract Window ToolKit) components up till now. Programmers were not comfortable when doing programming with AWT. Bcoz AWT is limited

More information

Basicsof. JavaGUI and SWING

Basicsof. JavaGUI and SWING Basicsof programming3 JavaGUI and SWING GUI basics Basics of programming 3 BME IIT, Goldschmidt Balázs 2 GUI basics Mostly window-based applications Typically based on widgets small parts (buttons, scrollbars,

More information

Top-Level Containers

Top-Level Containers 1. Swing Containers Swing containers can be classified into three main categories: Top-level containers: JFrame, JWindow, and JDialog General-purpose containers: JPanel, JScrollPane,JToolBar,JSplitPane,

More information

Example 3-1. Password Validation

Example 3-1. Password Validation Java Swing Controls 3-33 Example 3-1 Password Validation Start a new empty project in JCreator. Name the project PasswordProject. Add a blank Java file named Password. The idea of this project is to ask

More information

Chapter 13 Lab Advanced GUI Applications Lab Objectives. Introduction. Task #1 Creating a Menu with Submenus

Chapter 13 Lab Advanced GUI Applications Lab Objectives. Introduction. Task #1 Creating a Menu with Submenus Chapter 13 Lab Advanced GUI Applications Lab Objectives Be able to add a menu to the menu bar Be able to use nested menus Be able to add scroll bars, giving the user the option of when they will be seen.

More information

Programming Mobile Devices J2SE GUI

Programming Mobile Devices J2SE GUI Programming Mobile Devices J2SE GUI University of Innsbruck WS 2009/2010 thomas.strang@sti2.at Graphical User Interface (GUI) Why is there more than one Java GUI toolkit? AWT write once, test everywhere

More information

Java. GUI building with the AWT

Java. GUI building with the AWT Java GUI building with the AWT AWT (Abstract Window Toolkit) Present in all Java implementations Described in most Java textbooks Adequate for many applications Uses the controls defined by your OS therefore

More information

Swing from A to Z Some Simple Components. Preface

Swing from A to Z Some Simple Components. Preface By Richard G. Baldwin baldwin.richard@iname.com Java Programming, Lecture Notes # 1005 July 31, 2000 Swing from A to Z Some Simple Components Preface Introduction Sample Program Interesting Code Fragments

More information

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

Handout 14 Graphical User Interface (GUI) with Swing, Event Handling Handout 12 CS603 Object-Oriented Programming Fall 15 Page 1 of 12 Handout 14 Graphical User Interface (GUI) with Swing, Event Handling The Swing library (javax.swing.*) Contains classes that implement

More information

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

Building a GUI in Java with Swing. CITS1001 extension notes Rachel Cardell-Oliver Building a GUI in Java with Swing CITS1001 extension notes Rachel Cardell-Oliver Lecture Outline 1. Swing components 2. Building a GUI 3. Animating the GUI 2 Swing A collection of classes of GUI components

More information

Sri Vidya College of Engineering & Technology

Sri Vidya College of Engineering & Technology UNIT-V TWO MARKS QUESTION & ANSWER 1. What is the difference between the Font and FontMetrics class? Font class is used to set or retrieve the screen fonts.the Font class maps the characters of the language

More information

Creating Rich GUIs in Java. Amy Fowler Staff Engineer JavaSoft

Creating Rich GUIs in Java. Amy Fowler Staff Engineer JavaSoft 1 Creating Rich GUIs in Java Amy Fowler Staff Engineer JavaSoft 2 Tutorial Overview Toolkit principles & architecture GUI layout management Building custom components AWT futures 3 Toolkit Principles &

More information

Agenda. Container and Component

Agenda. Container and Component Agenda Types of GUI classes/objects Step-by-step guide to create a graphic user interface Step-by-step guide to event-handling PS5 Problem 1 PS5 Problem 2 Container and Component There are two types of

More information

Java IDE Programming-I

Java IDE Programming-I Java IDE Programming-I Graphical User Interface : is an interface that uses pictures and other graphic entities along with text, to interact with user. User can interact with GUI using mouse click/ or

More information

CSC 1214: Object-Oriented Programming

CSC 1214: Object-Oriented Programming CSC 1214: Object-Oriented Programming J. Kizito Makerere University e-mail: jkizito@cis.mak.ac.ug www: http://serval.ug/~jona materials: http://serval.ug/~jona/materials/csc1214 e-learning environment:

More information

Java Programming Lecture 6

Java Programming Lecture 6 Java Programming Lecture 6 Alice E. Fischer Feb 15, 2013 Java Programming - L6... 1/32 Dialog Boxes Class Derivation The First Swing Programs: Snow and Moving The Second Swing Program: Smile Swing Components

More information

Window Interfaces Using Swing. Chapter 12

Window Interfaces Using Swing. Chapter 12 Window Interfaces Using Swing 1 Reminders Project 7 due Nov 17 @ 10:30 pm Project 6 grades released: regrades due by next Friday (11-18-2005) at midnight 2 GUIs - Graphical User Interfaces Windowing systems

More information

G51PGP Programming Paradigms. Lecture 008 Inner classes, anonymous classes, Swing worker thread

G51PGP Programming Paradigms. Lecture 008 Inner classes, anonymous classes, Swing worker thread G51PGP Programming Paradigms Lecture 008 Inner classes, anonymous classes, Swing worker thread 1 Reminder subtype polymorphism public class TestAnimals public static void main(string[] args) Animal[] animals

More information

Java Swing. Recitation 11/(20,21)/2008. CS 180 Department of Computer Science, Purdue University

Java Swing. Recitation 11/(20,21)/2008. CS 180 Department of Computer Science, Purdue University Java Swing Recitation 11/(20,21)/2008 CS 180 Department of Computer Science, Purdue University Announcements Project 8 is out Milestone due on Dec 3rd, 10:00 pm Final due on Dec 10th, 10:00 pm No classes,

More information

1005ICT Object Oriented Programming Lecture Notes

1005ICT Object Oriented Programming Lecture Notes 1005ICT Object Oriented Programming Lecture Notes School of Information and Communication Technology Griffith University Semester 2, 2015 1 20 GUI Components and Events This section develops a program

More information

The Abstract Windowing Toolkit. Java Foundation Classes. Swing. In April 1997, JavaSoft announced the Java Foundation Classes (JFC).

The Abstract Windowing Toolkit. Java Foundation Classes. Swing. In April 1997, JavaSoft announced the Java Foundation Classes (JFC). The Abstract Windowing Toolkit Since Java was first released, its user interface facilities have been a significant weakness The Abstract Windowing Toolkit (AWT) was part of the JDK form the beginning,

More information

Graphical User Interfaces. Swing. Jose Jesus García Rueda

Graphical User Interfaces. Swing. Jose Jesus García Rueda Graphical User Interfaces. Swing Jose Jesus García Rueda Introduction What are the GUIs? Well known examples Basic concepts Graphical application. Containers. Actions. Events. Graphical elements: Menu

More information

Part I: Learn Common Graphics Components

Part I: Learn Common Graphics Components OOP GUI Components and Event Handling Page 1 Objectives 1. Practice creating and using graphical components. 2. Practice adding Event Listeners to handle the events and do something. 3. Learn how to connect

More information

Dr. Hikmat A. M. AbdelJaber

Dr. Hikmat A. M. AbdelJaber Dr. Hikmat A. M. AbdelJaber JWindow: is a window without a title bar or move controls. The program can move and resize it, but the user cannot. It has no border at all. It optionally has a parent JFrame.

More information

First Name: AITI 2004: Exam 2 July 19, 2004

First Name: AITI 2004: Exam 2 July 19, 2004 First Name: AITI 2004: Exam 2 July 19, 2004 Last Name: Standard Track Read Instructions Carefully! This is a 3 hour closed book exam. No calculators are allowed. Please write clearly if we cannot understand

More information

Layout. Dynamic layout, Swing and general layout strategies

Layout. Dynamic layout, Swing and general layout strategies Layout Dynamic layout, Swing and general layout strategies Two Interface Layout Tasks Designing a spatial layout of widgets in a container Adjusting that spatial layout when container is resized Both

More information

The AWT Package, An Overview

The AWT Package, An Overview Richard G Baldwin (512) 223-4758, baldwin@austin.cc.tx.us, http://www2.austin.cc.tx.us/baldwin/ The AWT Package, An Overview Java Programming, Lecture Notes # 110, Revised 02/21/98. Preface Introduction

More information

JAVA NOTES GRAPHICAL USER INTERFACES

JAVA NOTES GRAPHICAL USER INTERFACES 1 JAVA NOTES GRAPHICAL USER INTERFACES Terry Marris 24 June 2001 5 TEXT AREAS 5.1 LEARNING OUTCOMES By the end of this lesson the student should be able to understand how to get multi-line input from the

More information

Resizing a Window. COSC 3461: Module 5B. What is Widget Layout? Size State Transitions. What is Widget Layout? Hierarchical Widget Layout.

Resizing a Window. COSC 3461: Module 5B. What is Widget Layout? Size State Transitions. What is Widget Layout? Hierarchical Widget Layout. COSC 3461: Module 5B Resizing a Window Widgets II What has changed? scrollbar added menu has wrapped toolbar modified (buttons lost) 2 What is Widget Layout? Size State Transitions Recall: each widget

More information

1. What is Jav a? simple

1. What is Jav a? simple 1. What is Jav a? Thanks to Java is a new programming language developed at Sun under the direction of James Gosling. As far as possible it is based on concepts from C, Objective C and C++. Java is interpreted

More information

TTTK Program Design and Problem Solving Tutorial 3 (GUI & Event Handlings)

TTTK Program Design and Problem Solving Tutorial 3 (GUI & Event Handlings) TTTK1143 - Program Design and Problem Solving Tutorial 3 (GUI & Event Handlings) Topic: JApplet and ContentPane. 1. Complete the following class to create a Java Applet whose pane s background color is

More information

CPS122 Lecture: Graphical User Interfaces and Event-Driven Programming

CPS122 Lecture: Graphical User Interfaces and Event-Driven Programming CPS122 Lecture: Graphical User Interfaces and Event-Driven Programming Objectives: Last revised March 2, 2017 1. To introduce the notion of a component and some basic Swing components (JLabel, JTextField,

More information

Graphical User Interface (GUI)

Graphical User Interface (GUI) Graphical User Interface (GUI) An example of Inheritance and Sub-Typing 1 Java GUI Portability Problem Java loves the idea that your code produces the same results on any machine The underlying hardware

More information

Virtualians.ning.pk. 2 - Java program code is compiled into form called 1. Machine code 2. native Code 3. Byte Code (From Lectuer # 2) 4.

Virtualians.ning.pk. 2 - Java program code is compiled into form called 1. Machine code 2. native Code 3. Byte Code (From Lectuer # 2) 4. 1 - What if the main method is declared as private? 1. The program does not compile 2. The program compiles but does not run 3. The program compiles and runs properly ( From Lectuer # 2) 4. The program

More information

What is Widget Layout? COSC 3461 User Interfaces. Hierarchical Widget Layout. Resizing a Window. Module 5 Laying Out Components

What is Widget Layout? COSC 3461 User Interfaces. Hierarchical Widget Layout. Resizing a Window. Module 5 Laying Out Components COSC User Interfaces Module 5 Laying Out Components What is Widget Layout? Positioning widgets in their container (typically a JPanel or a JFrame s content pane) Basic idea: each widget has a size and

More information

Lecture 5: Java Graphics

Lecture 5: Java Graphics Lecture 5: Java Graphics CS 62 Spring 2019 William Devanny & Alexandra Papoutsaki 1 New Unit Overview Graphical User Interfaces (GUI) Components, e.g., JButton, JTextField, JSlider, JChooser, Containers,

More information

Programming graphics

Programming graphics Programming graphics Need a window javax.swing.jframe Several essential steps to use (necessary plumbing ): Set the size width and height in pixels Set a title (optional), and a close operation Make it

More information

Chapter 13 Lab Advanced GUI Applications

Chapter 13 Lab Advanced GUI Applications Gaddis_516907_Java 4/10/07 2:10 PM Page 113 Chapter 13 Lab Advanced GUI Applications Objectives Be able to add a menu to the menu bar Be able to use nested menus Be able to add scroll bars, giving the

More information

CS11 Java. Fall Lecture 4

CS11 Java. Fall Lecture 4 CS11 Java Fall 2006-2007 Lecture 4 Today s Topics Interfaces The Swing API Event Handlers Inner Classes Arrays Java Interfaces Classes can only have one parent class No multiple inheritance in Java! By

More information

AP CS Unit 11: Graphics and Events

AP CS Unit 11: Graphics and Events AP CS Unit 11: Graphics and Events This packet shows how to create programs with a graphical interface in a way that is consistent with the approach used in the Elevens program. Copy the following two

More information

Introduction. Introduction

Introduction. Introduction Introduction Many Java application use a graphical user interface or GUI (pronounced gooey ). A GUI is a graphical window or windows that provide interaction with the user. GUI s accept input from: the

More information

First Name: AITI 2004: Exam 2 July 19, 2004

First Name: AITI 2004: Exam 2 July 19, 2004 First Name: AITI 2004: Exam 2 July 19, 2004 Last Name: JSP Track Read Instructions Carefully! This is a 3 hour closed book exam. No calculators are allowed. Please write clearly if we cannot understand

More information

CSSE 220 Day 19. Object-Oriented Design Files & Exceptions. Check out FilesAndExceptions from SVN

CSSE 220 Day 19. Object-Oriented Design Files & Exceptions. Check out FilesAndExceptions from SVN CSSE 220 Day 19 Object-Oriented Design Files & Exceptions Check out FilesAndExceptions from SVN A practical technique OBJECT-ORIENTED DESIGN Object-Oriented Design We won t use full-scale, formal methodologies

More information

SINGLE EVENT HANDLING

SINGLE EVENT HANDLING SINGLE EVENT HANDLING Event handling is the process of responding to asynchronous events as they occur during the program run. An event is an action that occurs externally to your program and to which

More information

Java Application Development

Java Application Development A Absolute Size and Position - Specifying... 10:18 Abstract Class... 5:15 Accessor Methods...4:3-4:4 Adding Borders Around Components... 10:7 Adding Components to Containers... 10:6 Adding a Non-Editable

More information