graphical user interfaces in java -...

51
Graphical User Interfaces in Java - SWING

Upload: others

Post on 24-Sep-2020

2 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Graphical User Interfaces in Java - SWINGhome.iscte-iul.pt/~somoa/pcd/PCD/Avisos_files/PCD_slides2_swing... · The AWT library • The first library for implementing GUIs in Java

Graphical User Interfaces in Java - SWING

Page 2: Graphical User Interfaces in Java - SWINGhome.iscte-iul.pt/~somoa/pcd/PCD/Avisos_files/PCD_slides2_swing... · The AWT library • The first library for implementing GUIs in Java

Graphical User Interfaces (GUI)

•Each graphical component that the user can see on the screen corresponds to an object of a class Component:

• Window

• Button

• Menu

• ...

Class:• JFrame

• JButton

• JMenu

• ...

import javax.swing.Componente;

Page 3: Graphical User Interfaces in Java - SWINGhome.iscte-iul.pt/~somoa/pcd/PCD/Avisos_files/PCD_slides2_swing... · The AWT library • The first library for implementing GUIs in Java

Example

JFrame

JButton

JMenu

JLabel

JTextField

Page 4: Graphical User Interfaces in Java - SWINGhome.iscte-iul.pt/~somoa/pcd/PCD/Avisos_files/PCD_slides2_swing... · The AWT library • The first library for implementing GUIs in Java

Graphical User Interfaces in Java (I)

There are more than 250 classes for graphical user interface components and logic

• The goal is to create intuitive and usable GUIs. Programming these interfaces may not always be intuitive and the code can sometimes be difficult to read. For that reason, some IDEs include tools for graphically designing GUIs and automatic code generation (we will not use those in the course).

Page 5: Graphical User Interfaces in Java - SWINGhome.iscte-iul.pt/~somoa/pcd/PCD/Avisos_files/PCD_slides2_swing... · The AWT library • The first library for implementing GUIs in Java

The AWT library • The first library for implementing GUIs in

Java.

• For performance reasons, the AWT components used the underlying components on the execution platform (Solaris, Windows, Linux, …):

Version J2SE 1.2 and onwards include the Swing framework.

Graphical User Interfaces in Java (II)

Page 6: Graphical User Interfaces in Java - SWINGhome.iscte-iul.pt/~somoa/pcd/PCD/Avisos_files/PCD_slides2_swing... · The AWT library • The first library for implementing GUIs in Java

Swing’s Architecture

Swing is a framework for implementation of GUIs that allows for separation of interface and data.

Swing uses one thread (eventdispatch thread).

Swing allows for the implementation of platform independent GUIs.

Page 7: Graphical User Interfaces in Java - SWINGhome.iscte-iul.pt/~somoa/pcd/PCD/Avisos_files/PCD_slides2_swing... · The AWT library • The first library for implementing GUIs in Java

A Visual Index to the Swing Components (I)

http://java.sun.com/docs/books/tutorial/uiswing/components/components.html

Page 8: Graphical User Interfaces in Java - SWINGhome.iscte-iul.pt/~somoa/pcd/PCD/Avisos_files/PCD_slides2_swing... · The AWT library • The first library for implementing GUIs in Java

A Visual Index to the Swing Components (II)

http://java.sun.com/docs/books/tutorial/uiswing/components/components.html

Page 9: Graphical User Interfaces in Java - SWINGhome.iscte-iul.pt/~somoa/pcd/PCD/Avisos_files/PCD_slides2_swing... · The AWT library • The first library for implementing GUIs in Java

A Visual Index to the Swing Components (III)

http://java.sun.com/docs/books/tutorial/uiswing/components/components.html

Page 10: Graphical User Interfaces in Java - SWINGhome.iscte-iul.pt/~somoa/pcd/PCD/Avisos_files/PCD_slides2_swing... · The AWT library • The first library for implementing GUIs in Java

Window based GUIs

Creating and displaying a window:

import javax.swing.JFrame;

public class MáquinaDeCalcular {

public static void main(String[] argumentos) {

JFrame janela = new JFrame("Calculadora");

janela.setVisible(true);

}

}The application does not terminate

Page 11: Graphical User Interfaces in Java - SWINGhome.iscte-iul.pt/~somoa/pcd/PCD/Avisos_files/PCD_slides2_swing... · The AWT library • The first library for implementing GUIs in Java

JFrame:

import javax.swing.JFrame;

public class MáquinaDeCalcular { public static void main(String[] argumentos) {

Jframe janela = new JFrame("Calculadora");

// Estabelece o tamanho da janela em pixeis (largura, altura)janela.setSize(300, 200);// Estabelece a localizaçãodajanela: distância do canto superior// esquerdodajanelaao canto superior esquerdo do ecrãjanela.setLocation(200, 100);// A janelanão é redimensionáveljanela.setResizable(false);// Quando a janela é fechada a aplicaçãoterminajanela.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

janela.setVisible(true); }}

Very important!

Page 12: Graphical User Interfaces in Java - SWINGhome.iscte-iul.pt/~somoa/pcd/PCD/Avisos_files/PCD_slides2_swing... · The AWT library • The first library for implementing GUIs in Java

A JFrame on the desktop

200

100

300

200

Page 13: Graphical User Interfaces in Java - SWINGhome.iscte-iul.pt/~somoa/pcd/PCD/Avisos_files/PCD_slides2_swing... · The AWT library • The first library for implementing GUIs in Java

Adding components to the window

Add a button:

import javax.swing.JFrame;import javax.swing.JButton;

public class MáquinaDeCalcular { public static void main(String[] argumentos) { JFrame janela = new JFrame("Calculadora");

janela.getContentPane().add(new JButton("="));

janela.setSize(300, 200); janela.setLocation(200, 100); janela.setResizable(false); janela.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); janela.setVisible(true); }}

Page 14: Graphical User Interfaces in Java - SWINGhome.iscte-iul.pt/~somoa/pcd/PCD/Avisos_files/PCD_slides2_swing... · The AWT library • The first library for implementing GUIs in Java

A window with a button (”=”)

The button occupies the entire window

Page 15: Graphical User Interfaces in Java - SWINGhome.iscte-iul.pt/~somoa/pcd/PCD/Avisos_files/PCD_slides2_swing... · The AWT library • The first library for implementing GUIs in Java

Container:Access content in the

window The content of a window:

JFrame janela = new JFrame("Calculadora");

Container contentor = janela.getContentPane();

contentor.setBackground(Color.WHITE)

contentor.add(new JButton("="));

To use Containerand Color:

import java.awt.Container;import java.awt.Color;

Set the background color of the window

Page 16: Graphical User Interfaces in Java - SWINGhome.iscte-iul.pt/~somoa/pcd/PCD/Avisos_files/PCD_slides2_swing... · The AWT library • The first library for implementing GUIs in Java

Layout of components

There are different layout managers implemented in Swing:

• FlowLayout

• GridLayout

• BorderLayout

• ...

The components added to another component (such as a container) will be laid out according to the layout manager set on that component.

import java.awt.LayoutEspecífico;

Page 17: Graphical User Interfaces in Java - SWINGhome.iscte-iul.pt/~somoa/pcd/PCD/Avisos_files/PCD_slides2_swing... · The AWT library • The first library for implementing GUIs in Java

Layout Managers

LayoutManagers do the following:• Compute the minimum, preferred and

maximum size of a container.

• Layouts the components added to the container (its children)

The layout is done using the characteristics of the manager and the minimum, preferred, and maximum size of its children.

Page 18: Graphical User Interfaces in Java - SWINGhome.iscte-iul.pt/~somoa/pcd/PCD/Avisos_files/PCD_slides2_swing... · The AWT library • The first library for implementing GUIs in Java

FlowLayout

import java.awt.Container;import java.awt.FlowLayout;import javax.swing.JFrame;import javax.swing.JButton;

public class MáquinaDeCalcular { public static void main(String[] argumentos) { JFrame janela = new JFrame("Calculadora");

Container contentor = janela.getContentPane();contentor.setLayout(new FlowLayout());contentor.add(new JButton("1"));contentor.add(new JButton("2"));contentor.add(new JButton("3"));

janela.setSize(300, 200); janela.setLocation(200, 100); janela.setResizable(false); janela.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); janela.setVisible(true); }}

Page 19: Graphical User Interfaces in Java - SWINGhome.iscte-iul.pt/~somoa/pcd/PCD/Avisos_files/PCD_slides2_swing... · The AWT library • The first library for implementing GUIs in Java

FlowLayout

Page 20: Graphical User Interfaces in Java - SWINGhome.iscte-iul.pt/~somoa/pcd/PCD/Avisos_files/PCD_slides2_swing... · The AWT library • The first library for implementing GUIs in Java

GridLayout

import java.awt.Container;import java.awt.GridLayout;import javax.swing.JFrame;import javax.swing.JButton;

public class MáquinaDeCalcular { public static void main(String[] argumentos) { JFrame janela = new JFrame("Calculadora");

Container contentor = janela.getContentPane();contentor.setLayout(new GridLayout(3,1));contentor.add(new JButton("1"));contentor.add(new JButton("2"));contentor.add(new JButton("3"));

janela.setSize(300, 200); janela.setLocation(200, 100); janela.setResizable(false); janela.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); janela.setVisible(true); }}

3 rows and 1 column

Page 21: Graphical User Interfaces in Java - SWINGhome.iscte-iul.pt/~somoa/pcd/PCD/Avisos_files/PCD_slides2_swing... · The AWT library • The first library for implementing GUIs in Java

GridLayout

Page 22: Graphical User Interfaces in Java - SWINGhome.iscte-iul.pt/~somoa/pcd/PCD/Avisos_files/PCD_slides2_swing... · The AWT library • The first library for implementing GUIs in Java

BorderLayout

import java.awt.Container;import java.awt.BorderLayout;import javax.swing.JFrame;import javax.swing.JButton;

public class MáquinaDeCalcular { public static void main(String[] argumentos) { JFrame janela = new JFrame("Calculadora");

Container contentor = janela.getContentPane();contentor.setLayout(new BorderLayout());contentor.add(new JButton("1"), BorderLayout.NORTH);contentor.add(new JButton("2"), BorderLayout.WEST);contentor.add(new JButton("3"), BorderLayout.EAST);

janela.setSize(300, 200); janela.setLocation(200, 100); janela.setResizable(false); janela.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); janela.setVisible(true); }}

Page 23: Graphical User Interfaces in Java - SWINGhome.iscte-iul.pt/~somoa/pcd/PCD/Avisos_files/PCD_slides2_swing... · The AWT library • The first library for implementing GUIs in Java

BorderLayout

NORTH

EASTWEST

CENTERSOUTH

Page 24: Graphical User Interfaces in Java - SWINGhome.iscte-iul.pt/~somoa/pcd/PCD/Avisos_files/PCD_slides2_swing... · The AWT library • The first library for implementing GUIs in Java

Other Layout Managers

There are other LayoutManagers:• BoxLayout like FlowLayout, but with more options. • CardLayout allows for several components to occupy the

same space. Allows for creation of taps and tabbed panes.• GridBagLayout is very flexible (and complex). Defines a

grid, but allows fine control over how components are placed in the grid .

• GroupLayout was developed for IDE frameworks for GUI builders but can be used by hand as well. Uses two independent layouts (vertical and horizontal).

• SpringLayout is very flexible and very low-level. Only for GUI builders.

• You can even create your own

Page 25: Graphical User Interfaces in Java - SWINGhome.iscte-iul.pt/~somoa/pcd/PCD/Avisos_files/PCD_slides2_swing... · The AWT library • The first library for implementing GUIs in Java

Combining different layouts using JPanel

Container contentor = janela.getContentPane();contentor.setLayout(new BorderLayout());

JPanel painel = new JPanel();

final String caracteresDosBotões= "789+456-123*0.^/";JPanel painelDosBotões= new JPanel();painelDosBotões.setLayout(new GridLayout(4, 4));

for(inti = 0; i != caracteresDosBotões.length(); ++i)painelDosBotões.add(new JButton("" +

caracteresDosBotões.charAt(i)));

painel.add(painelDosBotões);

JPanel painelDasAcções= new JPanel();painelDasAcções.setLayout(new GridLayout(2, 1));painelDasAcções.add(new JButton("C"));painelDasAcções.add(new JButton("="));

painel.add(painelDasAcções);

contentor.add(painel, BorderLayout.CENTER);

If no layout is given, FlowLayout is used in JPanels

Page 26: Graphical User Interfaces in Java - SWINGhome.iscte-iul.pt/~somoa/pcd/PCD/Avisos_files/PCD_slides2_swing... · The AWT library • The first library for implementing GUIs in Java

JPanels

painelDasAcções

painelDosBotões

painel

Page 27: Graphical User Interfaces in Java - SWINGhome.iscte-iul.pt/~somoa/pcd/PCD/Avisos_files/PCD_slides2_swing... · The AWT library • The first library for implementing GUIs in Java

JTextField

Create and add to a Containeror to a JPanel:

JTextField mostrador = new JTextField();contentor.add(mostrador, BorderLayout.NORTH);

Some operations:

// Make the background whitemostrador.setBackground(Color.WHITE);// Use a specific font“Arial, regular, tamanho 14”mostrador.setFont(new Font("Arial", Font.PLAIN, 14));// Right-align text mostrador.setHorizontalAlignment(JTextField.RIGHT);// Disable editingmostrador.setEditable(false);

In order to use Font, doimport java.awt.Font;

Page 28: Graphical User Interfaces in Java - SWINGhome.iscte-iul.pt/~somoa/pcd/PCD/Avisos_files/PCD_slides2_swing... · The AWT library • The first library for implementing GUIs in Java

JTextField

mostrador

Page 29: Graphical User Interfaces in Java - SWINGhome.iscte-iul.pt/~somoa/pcd/PCD/Avisos_files/PCD_slides2_swing... · The AWT library • The first library for implementing GUIs in Java

JTextField

Getting the text in a text field:

String texto = mostrador.getText();

Setting the text in a text field

mostrador.setText(“1 + 3 * 4”);

Page 30: Graphical User Interfaces in Java - SWINGhome.iscte-iul.pt/~somoa/pcd/PCD/Avisos_files/PCD_slides2_swing... · The AWT library • The first library for implementing GUIs in Java

How do we make an application react when a

button is pressed? Event-based programming

• Whenever an event occurs, a specific piece of code is execute

Events:• Mouse button pressed• Mouse is moved• Key is pressed• Timers• …

Fonte: Programação Concorrente e Distribuída DCTI

Page 31: Graphical User Interfaces in Java - SWINGhome.iscte-iul.pt/~somoa/pcd/PCD/Avisos_files/PCD_slides2_swing... · The AWT library • The first library for implementing GUIs in Java

Events

A signal sent to a program• A program can choose to react or ignore

All events inherit from EventObject

Events have a source – the object that generated the event. The source of an event can be determined by calling the following method on the event:

Object getSource()

Fonte: Programação Concorrente e Distribuída DCTI

Page 32: Graphical User Interfaces in Java - SWINGhome.iscte-iul.pt/~somoa/pcd/PCD/Avisos_files/PCD_slides2_swing... · The AWT library • The first library for implementing GUIs in Java

Actions, objects and events…

TextEventJTextComponentEdit text

WindowEventWindowManipulate a window

ActionEventJMenuItemSelect an item

ListSelectionEventJListSelect an item

ItemEvent, ActionEvent

JComboBoxSelect an item

ActionEventJTextFieldPress ENTER in a text field

ActionEventJButtonPress a button

EventObjectAction

Fonte: Programação Concorrente e Distribuída DCTI

Page 33: Graphical User Interfaces in Java - SWINGhome.iscte-iul.pt/~somoa/pcd/PCD/Avisos_files/PCD_slides2_swing... · The AWT library • The first library for implementing GUIs in Java

Subscription, listening and handling

An external action causes an event to be generated• Example: a button is pressed

Objects that have subscribed to the event receive the event• We say that objects are listening for events

Objects that can generate events maintain a list of event subscribers• Whenever an event occurs, the event generating

object goes through the list of subscribers and calls a method on each subscriber that allows the subscriber to handle the event.

Fonte: Programação Concorrente e Distribuída DCTI

Page 34: Graphical User Interfaces in Java - SWINGhome.iscte-iul.pt/~somoa/pcd/PCD/Avisos_files/PCD_slides2_swing... · The AWT library • The first library for implementing GUIs in Java

Events and listeners

valueChanged()ListSelectionListenerListSelectionEvent

textValueChanged()TextListenerTextEvent

windowClosing()windowOpened()windowIconified()windowDeiconified()windowClosed()…

WindowListenerWindowEvent

itemStateChanged()ItemListenerItemEvent

actionPerformed()ActionListenerActionEvent

Method calledListenerEvent

Listener: an object that can subscribe to events.

Fonte: Programação Concorrente e Distribuída DCTI

Page 35: Graphical User Interfaces in Java - SWINGhome.iscte-iul.pt/~somoa/pcd/PCD/Avisos_files/PCD_slides2_swing... · The AWT library • The first library for implementing GUIs in Java

Libraries

Events and Listeners are defined in the AWT library in the event package:• import java.awt.event.ActionEvent;

• import java.awt.event.ActionListener;

• …

Except:• javax.swing.event.ListSelectionEvent

• javax.swing.event.ListSelectionListener

Fonte: Programação Concorrente e Distribuída DCTI

Page 36: Graphical User Interfaces in Java - SWINGhome.iscte-iul.pt/~somoa/pcd/PCD/Avisos_files/PCD_slides2_swing... · The AWT library • The first library for implementing GUIs in Java

Defining a listener

private class SentinelaParaAcções implements ActionListener {

public void actionPerformed(ActionEvent e) {

if(e.getSource() == botãoOK) {

System.out.println(“Carregou no botão OK.”);

}

else if(e.getSource() == botãoCancel) {

System.out.println(“Carregou no botão Cancel.”);

}

}

}

The listener is an interface!

getSource() returns a reference to the object that sent the event.

Listener: possibly an internal class.

Handler: method that handles an event.

Fonte: Programação Concorrente e Distribuída DCTI

Page 37: Graphical User Interfaces in Java - SWINGhome.iscte-iul.pt/~somoa/pcd/PCD/Avisos_files/PCD_slides2_swing... · The AWT library • The first library for implementing GUIs in Java

Subscribing to events

public class Botões { public Botões() { Container contentor = janela.getContentPane(); contentor.setLayout(new FlowLayout());

contentor.add(botãoOK); contentor.add(botãoCancel);

// Regista sentinelas: botãoOK.addActionListener(sentinela); botãoCancel.addActionListener(sentinela);

janela.setSize(100, 100); janela.setLocation(200, 100); janela.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); }

(continues)

Fonte: Programação Concorrente e Distribuída DCTI

Page 38: Graphical User Interfaces in Java - SWINGhome.iscte-iul.pt/~somoa/pcd/PCD/Avisos_files/PCD_slides2_swing... · The AWT library • The first library for implementing GUIs in Java

The listener

(continuação)

public void executa() { janela.setVisible(true); }

private JFrame janela = new JFrame("Eventos"); private JButton botãoOK = new JButton("OK"); private JButton botãoCancel = new JButton("Cancel"); private SentinelaParaAcções sentinela = new SentinelaParaAcções();

private class SentinelaParaAcções implements ActionListener { public void actionPerformed(ActionEvent e) {

JButton botão=(JButton)e.getSource();if (botão==botãoOK ) { ...}else {...}

}

public static void main(String[] argumentos) { Botões b = new Botões(); b.executa(); }}

Should be private in most cases

Fonte: Programação Concorrente e Distribuída DCTI

Page 39: Graphical User Interfaces in Java - SWINGhome.iscte-iul.pt/~somoa/pcd/PCD/Avisos_files/PCD_slides2_swing... · The AWT library • The first library for implementing GUIs in Java

Fonte: Programação Concorrente e Distribuída DCTI

Example

Page 40: Graphical User Interfaces in Java - SWINGhome.iscte-iul.pt/~somoa/pcd/PCD/Avisos_files/PCD_slides2_swing... · The AWT library • The first library for implementing GUIs in Java

Example

Carregou no botão OK.

Fonte: Programação Concorrente e Distribuída DCTI

The method actionPerformed() was called on the listener

Page 41: Graphical User Interfaces in Java - SWINGhome.iscte-iul.pt/~somoa/pcd/PCD/Avisos_files/PCD_slides2_swing... · The AWT library • The first library for implementing GUIs in Java

Carregou no botão OK.Carregou no botão OK.Carregou no botão Cancel.

Fonte: Programação Concorrente e Distribuída DCTI

Example

The method actionPerformed() was called on the listener

Page 42: Graphical User Interfaces in Java - SWINGhome.iscte-iul.pt/~somoa/pcd/PCD/Avisos_files/PCD_slides2_swing... · The AWT library • The first library for implementing GUIs in Java

An example with lists…

javax.swing.JList

javax.swing.JScrollPane

javax.swing.ListSelectionModel

javax.swing.event.ListSelectionEvent

javax.swing.event.ListSelectionListener

Fonte: Programação Concorrente e Distribuída DCTI

Page 43: Graphical User Interfaces in Java - SWINGhome.iscte-iul.pt/~somoa/pcd/PCD/Avisos_files/PCD_slides2_swing... · The AWT library • The first library for implementing GUIs in Java

Adding the list and setting up the window

public class Listador {public Listador() {

janela.getContentPane().add(new JScrollPane(lista));lista.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);

lista.setSelectedIndex(0);lista.addListSelectionListener(sentinela);

janela.setSize(100, 200); janela.setLocation(200, 100); janela.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

}

public void executa() {janela.setVisible(true);

}

(continues)

Fonte: Programação Concorrente e Distribuída DCTI

Page 44: Graphical User Interfaces in Java - SWINGhome.iscte-iul.pt/~somoa/pcd/PCD/Avisos_files/PCD_slides2_swing... · The AWT library • The first library for implementing GUIs in Java

List, items and the listener

(continuation)

private static final String[] nomesDoItens = {"zero","um","dois","três","quatro"

};

private int índiceDoItemSeleccionado = 0;private JFrame janela = new JFrame("Listas");

private JList lista = new JList(nomesDoItens);private SentilenaParaALista sentinela = new SentilenaParaALista();

(continues)

Fonte: Programação Concorrente e Distribuída DCTI

Page 45: Graphical User Interfaces in Java - SWINGhome.iscte-iul.pt/~somoa/pcd/PCD/Avisos_files/PCD_slides2_swing... · The AWT library • The first library for implementing GUIs in Java

Handling events

(continued)

private class SentilenaParaALista implements ListSelectionListener { public void valueChanged(ListSelectionEvent e) { if(índiceDoItemSeleccionado != lista.getSelectedIndex()) {

System.out.println(lista.getSelectedIndex() + " --> " + lista.getSelectedValue());

índiceDoItemSeleccionado = lista.getSelectedIndex(); } } }

(continues)

Fonte: Programação Concorrente e Distribuída DCTI

Page 46: Graphical User Interfaces in Java - SWINGhome.iscte-iul.pt/~somoa/pcd/PCD/Avisos_files/PCD_slides2_swing... · The AWT library • The first library for implementing GUIs in Java

The main

(continuation)

public static void main(String[] argumentos) { Listador l = new Listador(); l.executa(); }}

Fonte: Programação Concorrente e Distribuída DCTI

Page 47: Graphical User Interfaces in Java - SWINGhome.iscte-iul.pt/~somoa/pcd/PCD/Avisos_files/PCD_slides2_swing... · The AWT library • The first library for implementing GUIs in Java

Example

1 --> um

Fonte: Programação Concorrente e Distribuída DCTI

Page 48: Graphical User Interfaces in Java - SWINGhome.iscte-iul.pt/~somoa/pcd/PCD/Avisos_files/PCD_slides2_swing... · The AWT library • The first library for implementing GUIs in Java

Example

1 --> um2 --> dois

Fonte: Programação Concorrente e Distribuída DCTI

Page 49: Graphical User Interfaces in Java - SWINGhome.iscte-iul.pt/~somoa/pcd/PCD/Avisos_files/PCD_slides2_swing... · The AWT library • The first library for implementing GUIs in Java

Example

1 --> um2 --> dois4 --> quatro

Page 50: Graphical User Interfaces in Java - SWINGhome.iscte-iul.pt/~somoa/pcd/PCD/Avisos_files/PCD_slides2_swing... · The AWT library • The first library for implementing GUIs in Java

Notes

For more on creating user interfaces with Swing, see:

http://java.sun.com/docs/books/tutorial/uiswing/index.html

There are more than 250 classes…:

• It is impossible to remember all of them, so it is essential that you understand the basic principles and then learn to find the specific information you need in order to create the GUI.

Page 51: Graphical User Interfaces in Java - SWINGhome.iscte-iul.pt/~somoa/pcd/PCD/Avisos_files/PCD_slides2_swing... · The AWT library • The first library for implementing GUIs in Java

Summary

GUIs Event-based programming

• Events• Actions• Source objects• Different types of events• Subscription, listening and handling events

Listeners Methods for handing events Examples