Curs 6. GUI Swing. POO - curs 6

Size: px
Start display at page:

Download "Curs 6. GUI Swing. POO - curs 6"

Transcription

1 Curs 6 GUI Swing 1

2 JFC si Swing JFC = Java TM Foundation Classes, un grup de clase care permit construirea interfetelor grafice (GUI). Caracteristici: The Swing Components Pluggable Look and Feel Support Se pot alege diferite looks and feels. Separare a datelor in modele... Pachete: javax.swing javax.swing.event... 2

3 Componente Swing si Componente AWT Componentele AWT au fost furnizate de platformele JDK 1.0 si 1.1 Componentele Swing sunt implementate fara a se folosi cod nativ. Deoarece componentele Swing nu sunt restrictionate la caracteristicile de baza existente pe fiecare platforma pot avea o functionalitate mai complexa decat componentele AWT. Avantaje ale componentelor Swing: Butoanele si etichetele pot avea nu numai text dar si imagini. Se pot adauga sau schimba usor margini in jurul componentelor Swing. Se poate schimba usor comportamentul si forma componentelor Swing prin apelarea unor metode sau prin constructia uor clase derivate. Ccomponentele Swing pot sa nu fie rectangulare. 3

4 Setarea Look and Feel Setting the Java Look&Feel public static void main(string[] args) { try { UIManager.setLookAndFeel( UIManager.getCrossPlatformLookAndFeelClassName()); catch (Exception e) { new SwingApplication(); //Create and show the GUI. Setting the Windows Look & Feel UIManager.setLookAndFeel( "com.sun.java.swing.plaf.windows.windowslookandfeel ) Setting the native Look&Feel for whatever platform UIManager.setLookAndFeel( UIManager.getSystemLookAndFeelClassName()); 4

5 Exemplu 5

6 Containeri Swing Top-level Cel putin unul pentru fiecare aplicatie care foloseste GUI. JFrame, JDialog, ori JApplet. JFrame object -> main window, JDialog object -> secondary window, JApplet object -> an applet's display area within a browser window. Furnizeaza suport pentru componentele Swing sa se afiseze si pentru tratarea evenimentelor. 6

7 Ierarhia containerilor Top-level container Intermediate container (panel): JPanel, JScrollPane, JTabbedPane) Atomic components Diagrama ierarhiei pentru exemplu (SwingApplication). 7

8 Exemplu - implementare import javax.swing.*; import java.awt.*; import java.awt.event.*; public class SwingApplication {... public static void main(string[] args) {... JFrame frame = new JFrame("SwingApplication"); //...create the components to go into the frame... //...stick them in a container named contents... frame.getcontentpane().add(contents, BorderLayout.CENTER); //Finish setting up the frame, and show it. frame.addwindowlistener(...); frame.pack(); frame.setvisible(true); 8

9 Crearea Butoanelor si etichetelor JButton button = new JButton("I'm a Swing button!"); button.addactionlistener(...create an action listener...);...//where instance variables are declared: private static String labelprefix = "Number of button clicks: "; private int numclicks = 0;...//in GUI initialization code: final JLabel label = new JLabel(labelPrefix + "0 ");...//in the event handler for button clicks: label.settext(labelprefix + numclicks); 9

10 Adaugarea componentelor in containeri JPanel pane = new JPanel(); pane.setborder( BorderFactory.createEmptyBorder( 30, 30, 10, 30)); pane.setlayout(new GridLayout(0, 1)); pane.add(button); pane.add(label); 10

11 Adaugarea marginilor pane.setborder( BorderFactory.createEmptyBorder( 30, //top 30, //left 10, //bottom 30) //right ); 11

12 Layout Management Layout management este procesul de determinare a marimii si pozitiei componentelor. Implicit fiecare container are un layout manager -- un obiect care realizeaza layout management pentru componentele din container. Trebuie sa se tina seama de layout manager atunci cand se adauga (add) o componenta intr-un container. 12

13 Setarea pentru Layout Manager JPanel pane = new JPanel(); pane.setlayout(new BorderLayout()); Caracteristicile unei componente Dimensiuni setminimumsize, setpreferredsize, setmaximumsize) sau se pot defini subclase care pot suprascrie metodele-- getminimumsize, getpreferredsize, getmaximumsize. Aliniamente setalignmentx setalignmenty getalignmentx getalignmenty Spatiu intre componente Trei factori:: Layout manager Componente invisibile Margini 13

14 BorderLayout BorderLayout implicit pentru <content pane. > Container contentpane = getcontentpane(); //contentpane.setlayout(new BorderLayout()); //unnecessary contentpane.add(new JButton("Button 1 (NORTH)"), BorderLayout.NORTH); contentpane.add(new JButton("2 (CENTER)"), BorderLayout.CENTER); contentpane.add(new JButton("Button 3 (WEST)"), BorderLayout.WEST); contentpane.add(new JButton("Long-Named Button 4 (SOUTH)"), BorderLayout.SOUTH); contentpane.add(new JButton("Button 5 (EAST)"), BorderLayout.EAST); 14

15 FlowLayout FlowLayout implicit pentru JPanel. Container contentpane = getcontentpane(); contentpane.setlayout(new FlowLayout()); contentpane.add(new JButton("Button 1")); contentpane.add(new JButton("2")); contentpane.add(new JButton("Button 3")); contentpane.add(new JButton("Long-Named Button 4")); contentpane.add(new JButton("Button 5")); 15

16 GridLayout. Container contentpane = getcontentpane(); contentpane.setlayout(new GridLayout(0,2)); contentpane.add(new JButton("Button 1")); contentpane.add(new JButton("2")); contentpane.add(new JButton("Button 3")); contentpane.add(new JButton("Long-Named Button 4")); contentpane.add(new JButton("Button 5")); 16

17 Event Handling Act that results in the event Listener type User clicks a button, presses Return while typing in a text field, or chooses a menu item User closes a frame (main window) User presses a mouse button while the cursor is over a component User moves the mouse over a component Component becomes visible Component gets the keyboard focus Table or list selection changes ActionListener WindowListener MouseListener MouseMotionListener ComponentListener FocusListener ListSelectionListener 17

18 Fiecare eveniment este reprezentat de un obiect care furnizeaza informatie despre eveniment si sursa acestuia. Sursele sunt in general componente. Fiecare sursa de evenimente poate avea inregistrati mai multi listeners. Un singur listener poate fi inregistrat pentru mai multe surse. 18

19 Implementarea unui Event Handler Exemplu : ActionListener public class MyClass implements ActionListener { public void actionperformed(actionevent e) {...//code that reacts to the action... Inregistrare: somecomponent.addactionlistener( instanceofmyclass) 19

20 Informatii despre eveniment EventObject. Object getsource() Returneaza obiectul sursa al evenimentului. Exemplu: MouseEvent furnizeaza informatii despre pozitia mouse-ului, numar de clickuri, etc. 20

21 Exemplu (ActionEvent) Object Δ java.util.eventobject Δ java.awt.awtevent Δ java.awt.event.actionevent ActionEvent +getactioncommand():string +setactioncommand(string) +getsource():object 21

22 Evenimente low-level si semantice Evenimente Low-level: window-system occurrences, low-level input, Semantice toate celelalte. Exemple: mouse, key, component, container, focus, and window events. action events, item events, list selection events. Recomandare!!!! Tratati evenimentele semantice daca e posibil nu ecele low-level! 22

23 Ascultatori suportati de toate componentele Swing Component listener Schimbari de marime, pozitie si vizibilitate Focus listener Key listener Mouse listener Mouse motion listener 23

24 Tratarea evenimentelor pentru SwingApplication button.addactionlistener(new ActionListener() { public void actionperformed(actionevent e) { numclicks++; label.settext(labelprefix + numclicks); );... frame.addwindowlistener(new WindowAdapter() { public void windowclosing(windowevent e) { System.exit(0); ); 24

25 Main Windows public static void main(string s[]) { JFrame frame = new JFrame("FrameDemo"); frame.addwindowlistener(new WindowAdapter() { public void windowclosing(windowevent e) {System.exit(0); ); //...create a blank label, set its preferred size... frame.getcontentpane().add( emptylabel,borderlayout.center); frame.pack(); frame.setvisible(true); 25

26 Window Listener public class WindowEventDemo... implements WindowListener {...//where initialization occurs: //Create but don't show window. window = new JFrame("Window Event Window"); window.addwindowlistener(this); window.getcontentpane().add( new JLabel("The frame listens to this window " + "for window events."), BorderLayout.CENTER); window.pack(); public void windowclosing(windowevent e) { window.setvisible(false); displaymessage("window closing", e); public void windowclosed(windowevent e) { displaymessage("window closed", e); 26

27 public void windowopened(windowevent e) { displaymessage("window opened", e); public void windowiconified(windowevent e) { displaymessage("window iconified", e); public void windowdeiconified(windowevent e) { displaymessage("window deiconified", e); public void windowactivated(windowevent e) { displaymessage("window activated", e); public void windowdeactivated(windowevent e) { displaymessage("window deactivated", e); void displaymessage(string prefix, WindowEvent e) { display.append(prefix + ": " + e.getwindow() + newline);... 27

28 Adaptori class WindowAdapter implements WindowListener{ public void windowclosing(windowevent e) { public void windowclosed(windowevent e) { public void windowopened(windowevent e) { public void windowiconified(windowevent e) { public void windowdeiconified(windowevent e) { public void windowactivated(windowevent e) { public void windowdeactivated(windowevent e) { Ex: frame.addwindowlistener(new WindowAdapter() { public void windowclosing(windowevent e) { System.exit(0); ); 28

29 SwingApplication-(1) import javax.swing.*; import java.awt.*; import java.awt.event.*; public class SwingApplication { private static String labelprefix = "Number of button clicks:"; private int numclicks = 0; private String s=""; public Component createcomponents() { final JLabel label = new JLabel(labelPrefix + "0 "); final JTextField text = new JTextField("cliks", 20); JButton button = new JButton("I'm a Swing button!"); button.setmnemonic('i'); 29

30 SwingApplication-(2) button.addactionlistener(new ActionListener() { public void actionperformed(actionevent e) { numclicks++; s=new String(text.getText()); label.settext(labelprefix + numclicks+ s ); ); label.setlabelfor(button); JPanel pane = new JPanel(); pane.setborder( BorderFactory.createEmptyBorder(20, 20, 50, 40) ); pane.setlayout(new GridLayout(3, 1)); pane.add(button); pane.add(label); pane.add(text); return pane; 30

31 SwingApplication-(3) public static void main(string[] args) { try { UIManager.setLookAndFeel( UIManager.getCrossPlatformLookAndFeelClassName()); catch (Exception e) { JFrame frame = new JFrame("SwingApplication"); SwingApplication app = new SwingApplication(); Component contents = app.createcomponents(); frame.getcontentpane().add(contents, BorderLayout.CENTER); frame.addwindowlistener(new WindowAdapter() { public void windowclosing(windowevent e) { System.exit(0); ); frame.pack(); frame.setvisible(true); 31

32 Clasa AbstractButton Subclase: JButton, JMenuItem, JToggleButton JToggleButton Implementare a unui buton cu 2 stari. Subclase:» JCheckBox, JRadioButton 32

33 Constructori: JButton(Icon icon) JButton(String text) Clasa JButton JButton(String text, Icon icon) class ImageIcon implements Icon { Constructori: ImageIcon(Image image) ImageIcon(Image image, String description) ImageIcon(String filename) ImageIcon(String filename, String description) 33

34 Class JTextField JTextField (Extinde JTextComponent) Constructori: JTextField(int columns). JTextField(String text) JTextField(String text, int columns) Metode: public String gettext() public String getselectedtext() public void settext(string t) public void seteditable(boolean b) 34

35 Clasa JTextArea JTextArea. (Extinde JTextComponent) Constructori: : JTextArea(int rows, int columns) JTextArea(String text) JTextArea(String text, int rows, int columns) Metode: void append(string str) void insert(string str, int pos) void setcolumns(int columns) void setrows(int rows) 35

36 Exemplu import java.awt.*; import java.awt.event.*; import javax.swing.*; import java.lang.*; public class Actions extends JPanel implements ActionListener { int power=0; JTextField field, fieldrez; ImageIcon buttonimage; JButton button; JRadioButton radiobutton; ButtonGroup grp; JCheckBox checkbox; JLabel label1; JLabel label2; JLabel label3; 36

37 public Actions() { setlayout (new GridLayout(5,1,10,10)); setbackground (Color.lightGray); JPanel subpanel = new JPanel(); label1 = new JLabel("Number:"); subpanel.add(label1); // Creates a text field where the number is read field = new JTextField(10); field.addactionlistener (this); label1.setlabelfor(field); subpanel.add(field); add(subpanel); subpanel = new JPanel(); subpanel.setlayout(new GridLayout(3,2)); label2 = new JLabel("Power:"); 37

38 // Creates three radio buttons that specifies the exponent grp = new ButtonGroup(); radiobutton = new JRadioButton("One"); radiobutton.addactionlistener(this); radiobutton.setactioncommand("one Activated"); grp.add(radiobutton); subpanel.add(new JLabel("")); subpanel.add(radiobutton); subpanel.add(label2); radiobutton = new JRadioButton("Two"); radiobutton.addactionlistener(this); radiobutton.setactioncommand("two Activated"); grp.add(radiobutton); subpanel.add(radiobutton); radiobutton = new JRadioButton("Three"); radiobutton.addactionlistener(this); radiobutton.setactioncommand("three Activated"); grp.add(radiobutton); subpanel.add(new JLabel("")); subpanel.add(radiobutton); add(subpanel); 38

39 // Creates a checkbox that specifies if the square root is computed subpanel=new JPanel(); checkbox=new JCheckBox("Square Root"); checkbox.addactionlistener(this); subpanel.add(checkbox); add(subpanel); subpanel=new JPanel(); // Creates a button with an icon buttonimage = new ImageIcon("c:/temp/qs_cons.gif"); button = new JButton("Compute"); button.seticon(buttonimage); button.addactionlistener(this); button.setactioncommand("button Activated"); subpanel.add(button); add(subpanel); subpanel=new JPanel(); label3 =new JLabel("Result"); subpanel.add(label3); fieldrez = new JTextField(15); fieldrez.seteditable(false); subpanel.add(fieldrez); add(subpanel); 39

40 public void actionperformed(actionevent e) { if (e.getactioncommand().equals("one Activated")) power=1; if (e.getactioncommand().equals("two Activated")) power=2; if (e.getactioncommand().equals("three Activated")) power=3; if (e.getactioncommand().equals("button Activated")) { double rez; try{ rez=integer.parseint(field.gettext()); rez=math.pow(rez,power); if (checkbox.isselected()) rez=math.sqrt(rez); fieldrez.settext((new Double(rez)).toString()); catch(numberformatexception ee){ JOptionPane.showMessageDialog( field,"give an integer number!","error", JOptionPane.ERROR_MESSAGE ) ; field.requestfocus(); 40

41 public Dimension getpreferredsize() { return new Dimension(200, 400); public static void main(string s[]) { JFrame frame = new JFrame("Computer"); Actions panel = new Actions(); frame.setforeground(color.blue); frame.setbackground(color.lightgray); frame.setlocation(100,100); frame.addwindowlistener(new WindowCloser()); frame.getcontentpane().add(panel,"center"); frame.pack(); frame.setvisible(true); class WindowCloser extends WindowAdapter { public void windowclosing(windowevent e) { System.exit(0); 41

42 Liste O componenta JList afiseaza un grup de elemente din care utilizatorul poate alege. Listele sunt incluse in general in scroll pane. Separare dintre date si afisare: Model / View Datele continute intr-o lista sunt pastrate intr-un ListModel 42

43 Interfata ListModel ListModel void addlistdatalistener(listdatalistener l) Object getelementat(int index) int getsize(). void removelistdatalistener(listdatalistener l) Clasa DefaultListModel Se pot creare propriile clase de tip ListModel prin extinderea clasei AbstractListModel 43

44 Setarea elementelor unei liste Method JList(ListModel) JList(Object[]) JList(Vector) void setmodel(listmodel) ListModel getmodel() void setlistdata(object[]) void setlistdata(vector) Purpose Create a list with the initial list items specified. The second and third constructors implicitly create an immutable ListModel. Set or get the model that contains the contents of the list. Set the items in the list. These methods implicitly create an immutable ListModel 44

45 Tipuri de selectii Exemple Mod SINGLE_SELECTION Descriere La un moment dat doar un element este selectat. SINGLE_INTERVAL_ SELECTION La un moment dat pot fi selectate mai multe elemente consecutive. MULTIPLE_INTERVAL_ SELECTION (implicit) Orice combinatie de selectii. Deselectarea se face explicit. 45

46 Method void addlistselectionlistener( ListSelectionListener) Selectarea in liste void setselectedindex(int) void setselectedindices(int[]) void setselectedvalue(object, boolean) void setselectedinterval(int, int) int getselectedindex() int getminselectionindex() int getmaxselectionindex() int[] getselectedindices() Object getselectedvalue() Object[] getselectedvalues() void setselectionmode(int) int getselectionmode() void clearselection() boolean isselectionempty() boolean isselectedindex(int) Purpose Register to receive notification of selection changes. Set the current selection as indicated. Use setselectionmode to set what ranges of selections are acceptable. The boolean argument specifies whether the list should attempt to scroll itself so that the selected item is visible. Get information about the current selection as indicated. Set or get the selection mode. Acceptable values are: SINGLE_SELECTION, SINGLE_INTERVAL_SELECTION, or MULTIPLE_INTERVAL_SELECTION (the default), which are defined in ListSelectionModel. Set or get whether any items are selected. Determine whether the specified index is selected. 46

47 Exemplu import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.event.*; public class ListDemoSimple extends JFrame implements ListSelectionListener { private JList list; private DefaultListModel listmodel; private static final String addstring = "Add"; private static final String deletestring ="Delete"; 47

48 private JButton addbutton; private JButton deletebutton; private JTextField namefield; private JTextArea log; static private String newline = "\n"; ListDemoSimple(String s){ super(s); // the constructor of JFrame public Dimension getpreferredsize() { return new Dimension(600, 400); 48

49 public JPanel init() { //Create and populate the list model. listmodel = new DefaultListModel(); listmodel.addelement("whistler, Canada"); listmodel.addelement("jackson Hole, Wyoming"); listmodel.addelement("squaw Valley, California"); listmodel.addelement("telluride, Colorado"); listmodel.addelement("taos, New Mexico"); listmodel.addelement("snowbird, Utah"); listmodel.addelement("chamonix, France"); listmodel.addelement("banff, Canada"); listmodel.addlistdatalistener( new MyListDataListener()); 49

50 //Create the list and put it in a scroll pane. list = new JList(listModel); list.setselectionmode( ListSelectionModel.SINGLE_INTERVAL_SELECTION); list.setselectedindex(0); list.addlistselectionlistener(this); JScrollPane listscrollpane = new JScrollPane(list); //Create the list modifying buttons. addbutton = new JButton(addString); addbutton.setactioncommand(addstring); addbutton.addactionlistener( new AddButtonListener()); deletebutton = new JButton(deleteString); deletebutton.setactioncommand(deletestring); deletebutton.addactionlistener( new DeleteButtonListener()); 50

51 //Create the text field for entering new names. namefield = new JTextField(15); namefield.addactionlistener( new AddButtonListener()); String name = listmodel.getelementat( list.getselectedindex()).tostring(); namefield.settext(name); //Create a control panel (uses the default FlowLayout). JPanel buttonpane = new JPanel(); buttonpane.add(namefield); buttonpane.add(addbutton); buttonpane.add(deletebutton); 51

52 //Create the log for reporting list data events. log = new JTextArea(5, 2); JScrollPane logscrollpane = new JScrollPane(log); //Create a split pane for the log and the list. JSplitPane splitpane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, listscrollpane, logscrollpane); JPanel panel=new JPanel(); panel.setlayout(new BorderLayout()); panel.add(buttonpane, BorderLayout.NORTH); panel.add(splitpane, BorderLayout.CENTER); return panel; 52

53 class MyListDataListener implements ListDataListener { public void contentschanged(listdataevent e) { log.append("contentschanged: " + e.getindex0() + ", " + e.getindex1() + newline); public void intervaladded(listdataevent e) { log.append("intervaladded: " + e.getindex0() + ", " + e.getindex1() + newline); public void intervalremoved(listdataevent e) { log.append("intervalremoved: " + e.getindex0() + ", " + e.getindex1() + newline); 53

54 class DeleteButtonListener implements ActionListener { public void actionperformed(actionevent e) { ListSelectionModel lsm = list.getselectionmodel(); int firstselected = lsm.getminselectionindex(); int lastselected = lsm.getmaxselectionindex(); listmodel.removerange(firstselected, lastselected); int size = listmodel.size(); if (size == 0) { //List is empty: disable delete. deletebutton.setenabled(false); else { //Adjust the selection. if (firstselected == listmodel.getsize()) { //Removed item in last position. firstselected--; list.setselectedindex(firstselected); 54

55 class AddButtonListener implements ActionListener { public void actionperformed(actionevent e) { if (namefield.gettext().equals("")) { //User didn't type in a name... Toolkit.getDefaultToolkit().beep(); return; int index = list.getselectedindex(); int size = listmodel.getsize(); //If no selection or if item in last position is selected, //add the new one to end of list, and select new one. if (index == -1 (index+1 == size)) { listmodel.addelement(namefield.gettext()); list.setselectedindex(size); //Otherwise insert the new one after // the current selection, and select new one. else { listmodel.insertelementat(namefield.gettext(), index+1); list.setselectedindex(index+1); 55

56 //Listener method for list selection changes. public void valuechanged(listselectionevent e) { if (e.getvalueisadjusting() == false) { if (list.getselectedindex() == -1) { //No selection: disable delete button. deletebutton.setenabled(false); namefield.settext(""); else if (list.getselectedindices().length > 1) { //Multiple selection: disable add button. deletebutton.setenabled(true); addbutton.setenabled(false); else { //Single selection: permit all operations. deletebutton.setenabled(true); addbutton.setenabled(true); namefield.settext( list.getselectedvalue().tostring()); 56

57 public static void main(string args[]){ ListDemoSimple frame= new ListDemoSimple("Lista"); frame.setforeground(color.blue); frame.setbackground(color.lightgray); frame.setlocation(100,100); frame.addwindowlistener(new WindowAdapter() { public void windowclosing(windowevent e) {System.exit(0); ); JPanel panel=frame.init(); frame.getcontentpane().add(panel,"center"); frame.setsize(panel.getpreferredsize()); frame.pack(); frame.setvisible(true); 57

58 JScrollPanel - Decorator Constructori JScrollPane() Creaza un JScrollPane vid (fara viewport); bare de scroll orizontale si verticale apar cand este necesar. JScrollPane(Component view) Creaza a JScrollPane care afiseaza continutul componentei; bare de scroll orizontale si verticale apar daca componenta este mai mare. 58

59 Meniuri Clase: JMenuBar, JMenu, JMenuItem Exemplu private JMenuItem additem; private JMenuItem deleteitem; additem = new JMenuItem(addString); additem.addactionlistener(new AddButtonListener()); deleteitem = new JMenuItem(deleteString); deleteitem.addactionlistener(new DeleteButtonListener()); private JMenuBar menub = new JMenuBar(); private JMenu menu1 = new JMenu("menu1"); private JMenu menu2 = new JMenu("menu2"); menu1.add(additem); menu2.add(deleteitem); menub.add(menu1); menub.add(menu2); frame.setjmenubar(menub); 59

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

Ingineria Sistemelor de Programare

Ingineria Sistemelor de Programare Ingineria Sistemelor de Programare Interfete grafice (Swing) mihai.hulea@aut.utcluj.ro 2017 Scurt istoric AWT: Abstract Windowing Toolkit import java.awt.* Swing Java FX Swing Demo Libraria Swing Swing

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

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

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

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

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 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.,

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

Laborator 3 Java. Introducere in programarea vizuala

Laborator 3 Java. Introducere in programarea vizuala Laborator 3 Java Introducere in programarea vizuala 1. Pachetele AWT si Swing. 2. Ferestre 3.1. Introduceti urmatorul program JAVA: public class Pv public static void main(string args[ ]) JFrame fer=new

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

GUI Design. Overview of Part 1 of the Course. Overview of Java GUI Programming

GUI Design. Overview of Part 1 of the Course. Overview of Java GUI Programming GUI Design Michael B. Spring Department of Information Science and Telecommunications University of Pittsburgh spring@imap.pitt.edu http://www.sis.pitt.edu /~spring Overview of Part 1 of the Course Demystifying

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

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

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

12/22/11. Copyright by Pearson Education, Inc. All Rights Reserved.

12/22/11. Copyright by Pearson Education, Inc. All Rights Reserved. } Radio buttons (declared with class JRadioButton) are similar to checkboxes in that they have two states selected and not selected (also called deselected). } Radio buttons normally appear as a group

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

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

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

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

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

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

Datenbank-Praktikum. Universität zu Lübeck Sommersemester 2006 Lecture: Swing. Ho Ngoc Duc 1 Datenbank-Praktikum Universität zu Lübeck Sommersemester 2006 Lecture: Swing Ho Ngoc Duc 1 Learning objectives GUI applications Font, Color, Image Running Applets as applications Swing Components q q Text

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

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

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

CS111: PROGRAMMING LANGUAGE II

CS111: PROGRAMMING LANGUAGE II CS111: PROGRAMMING LANGUAGE II Computer Science Department Lecture 10(b): Working with Controls Agenda 2 Case study: TextFields and Labels Combo Boxes buttons List manipulation Radio buttons and checkboxes

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

Tool Kits, Swing. Overview. SMD158 Interactive Systems Spring Tool Kits in the Abstract. An overview of Swing/AWT

Tool Kits, Swing. Overview. SMD158 Interactive Systems Spring Tool Kits in the Abstract. An overview of Swing/AWT INSTITUTIONEN FÖR Tool Kits, Swing SMD158 Interactive Systems Spring 2005 Jan-28-05 2002-2005 by David A. Carr 1 L Overview Tool kits in the abstract An overview of Swing/AWT Jan-28-05 2002-2005 by David

More information

JAVA NOTES GRAPHICAL USER INTERFACES

JAVA NOTES GRAPHICAL USER INTERFACES 1 JAVA NOTES GRAPHICAL USER INTERFACES Terry Marris July 2001 8 DROP-DOWN LISTS 8.1 LEARNING OUTCOMES By the end of this lesson the student should be able to understand and use JLists understand and use

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

Programming Languages and Techniques (CIS120e)

Programming Languages and Techniques (CIS120e) Programming Languages and Techniques (CIS120e) Lecture 29 Nov. 19, 2010 Swing I Event- driven programming Passive: ApplicaHon waits for an event to happen in the environment When an event occurs, the applicahon

More information

Swing Programming Example Number 2

Swing Programming Example Number 2 1 Swing Programming Example Number 2 Problem Statement (Part 1 and 2 (H/w- assignment) 2 Demonstrate the use of swing Label, TextField, RadioButton, CheckBox, Listbox,Combo Box, Toggle button,image Icon

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

(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

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

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

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

Java Graphical User Interfaces AWT (Abstract Window Toolkit) & Swing Java Graphical User Interfaces AWT (Abstract Window Toolkit) & Swing Rui Moreira Some useful links: http://java.sun.com/docs/books/tutorial/uiswing/toc.html http://www.unix.org.ua/orelly/java-ent/jfc/

More information

Module 5 The Applet Class, Swings. OOC 4 th Sem, B Div Prof. Mouna M. Naravani

Module 5 The Applet Class, Swings. OOC 4 th Sem, B Div Prof. Mouna M. Naravani Module 5 The Applet Class, Swings OOC 4 th Sem, B Div 2016-17 Prof. Mouna M. Naravani The layout manager helps lay out the components held by this container. When you set a layout to null, you tell the

More information

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

GUI Program Organization. Sequential vs. Event-driven Programming. Sequential Programming. Outline Sequential vs. Event-driven Programming Reacting to the user GUI Program Organization Let s digress briefly to examine the organization of our GUI programs We ll do this in stages, by examining three example

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

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

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

Example Programs. COSC 3461 User Interfaces. GUI Program Organization. Outline. DemoHelloWorld.java DemoHelloWorld2.java DemoSwing. COSC User Interfaces Module 3 Sequential vs. Event-driven Programming Example Programs DemoLargestConsole.java DemoLargestGUI.java Demo programs will be available on the course web page. GUI Program Organization

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

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

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

Graphical Interfaces

Graphical Interfaces Weeks 11&12 Graphical Interfaces All the programs that you have created until now used a simple command line interface, which is not user friendly, so a Graphical User Interface (GUI) should be used. The

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

JList. Displays a series of items The user can select one or more items Class JList extends directly class Jcomponent Class Jlist supports

JList. Displays a series of items The user can select one or more items Class JList extends directly class Jcomponent Class Jlist supports GUI Component - 4 JList Displays a series of items The user can select one or more items Class JList extends directly class Jcomponent Class Jlist supports Single-selection lists: one item to be selected

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

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

Building Java Programs Bonus Slides

Building Java Programs Bonus Slides Building Java Programs Bonus Slides Graphical User Interfaces Copyright (c) Pearson 2013. All rights reserved. Graphical input and output with JOptionPane JOptionPane An option pane is a simple dialog

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

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

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

Chapter 6: Graphical User Interfaces

Chapter 6: Graphical User Interfaces Chapter 6: Graphical User Interfaces CS 121 Department of Computer Science College of Engineering Boise State University April 21, 2015 Chapter 6: Graphical User Interfaces CS 121 1 / 36 Chapter 6 Topics

More information

Graphical Interfaces

Graphical Interfaces Weeks 9&11 Graphical Interfaces All the programs that you have created until now used a simple command line interface, which is not user friendly, so a Graphical User Interface (GUI) should be used. The

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 Lecturer: Michael Hotan slides created by Marty Stepp based on materials by M. Ernst, S. Reges, D. Notkin, R. Mercer,

More information

Graphical User Interfaces in Java - SWING

Graphical User Interfaces in Java - SWING Graphical User Interfaces in Java - SWING 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...

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

user-friendly and easy to use.

user-friendly and easy to use. Java Graphic User Interface GUI Basic Dr. Umaporn Supasitthimethee Computer Programming II -2- Java GUI A graphical user interface (GUI) makes a system user-friendly and easy to use. Creating a GUI requires

More information

17 GUI API: Container 18 Hello world with a GUI 19 GUI API: JLabel 20 GUI API: Container: add() 21 Hello world with a GUI 22 GUI API: JFrame: setdefau

17 GUI API: Container 18 Hello world with a GUI 19 GUI API: JLabel 20 GUI API: Container: add() 21 Hello world with a GUI 22 GUI API: JFrame: setdefau List of Slides 1 Title 2 Chapter 13: Graphical user interfaces 3 Chapter aims 4 Section 2: Example:Hello world with a GUI 5 Aim 6 Hello world with a GUI 7 Hello world with a GUI 8 Package: java.awt and

More information

DM550 / DM857 Introduction to Programming. Peter Schneider-Kamp

DM550 / DM857 Introduction to Programming. Peter Schneider-Kamp DM550 / DM857 Introduction to Programming Peter Schneider-Kamp petersk@imada.sdu.dk http://imada.sdu.dk/~petersk/dm550/ http://imada.sdu.dk/~petersk/dm857/ GRAPHICAL USER INTERFACES 2 HelloWorld Reloaded

More information

2110: GUIS: Graphical User Interfaces

2110: GUIS: Graphical User Interfaces 2110: GUIS: Graphical User Interfaces Their mouse had a mean time between failure of a week it would jam up irreparably, or... jam up on the table--... It had a flimsy cord whose wires would break. Steve

More information

SD Module-1 Advanced JAVA

SD Module-1 Advanced JAVA Assignment No. 4 SD Module-1 Advanced JAVA R C (4) V T Total (10) Dated Sign Title: Transform the above system from command line system to GUI based application Problem Definition: Write a Java program

More information

Chapter 14. More Swing

Chapter 14. More Swing Chapter 14 More Swing Menus Making GUIs Pretty (and More Functional) Box Containers and Box Layout Managers More on Events and Listeners Another Look at the Swing Class Hierarchy Chapter 14 Java: an Introduction

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

SD Module-1 Advanced JAVA. Assignment No. 4

SD Module-1 Advanced JAVA. Assignment No. 4 SD Module-1 Advanced JAVA Assignment No. 4 Title :- Transform the above system from command line system to GUI based application Problem Definition: Write a Java program with the help of GUI based Application

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

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

Chapter 12 Advanced GUIs and Graphics

Chapter 12 Advanced GUIs and Graphics Chapter 12 Advanced GUIs and Graphics Chapter Objectives Learn about applets Explore the class Graphics Learn about the classfont Explore the classcolor Java Programming: From Problem Analysis to Program

More information

Object-Oriented Programming Design. Topic : User Interface Components with Swing GUI Part III

Object-Oriented Programming Design. Topic : User Interface Components with Swing GUI Part III Electrical and Computer Engineering Object-Oriented Topic : User Interface Components with Swing GUI Part III Maj Joel Young Joel.Young@afit.edu 17-Sep-03 Maj Joel Young Creating GUI Apps The Process Overview

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

GUI Programming: Swing and Event Handling

GUI Programming: Swing and Event Handling GUI Programming: Swing and Event Handling Sara Sprenkle 1 Announcements No class next Tuesday My Fourth of July present to you: No quiz! Assignment 3 due today Review Collections: List, Set, Map Inner

More information

Chapter 17 Creating User Interfaces

Chapter 17 Creating User Interfaces Chapter 17 Creating User Interfaces 1 Motivations A graphical user interface (GUI) makes a system user-friendly and easy to use. Creating a GUI requires creativity and knowledge of how GUI components work.

More information

Utilizarea formularelor in HTML

Utilizarea formularelor in HTML Utilizarea formularelor in HTML Formulare Un formular este constituit din elemente speciale, denumite elemente de control (controls), cum ar fi butoane radio, butoane de validare, câmpuri text, butoane

More information

Chapter 7: A First Look at GUI Applications

Chapter 7: A First Look at GUI Applications Chapter 7: A First Look at GUI Applications Starting Out with Java: From Control Structures through Objects Fourth Edition by Tony Gaddis Addison Wesley is an imprint of 2010 Pearson Addison-Wesley. All

More information

Java & Graphical User Interface II. Wang Yang wyang AT njnet.edu.cn

Java & Graphical User Interface II. Wang Yang wyang AT njnet.edu.cn Java & Graphical User Interface II Wang Yang wyang AT njnet.edu.cn Outline Review of GUI (first part) What is Event Basic Elements of Event Programming Secret Weapon - Inner Class Full version of Event

More information

Java - Applications. The following code sets up an application with a drop down menu, as yet the menu does not do anything.

Java - Applications. The following code sets up an application with a drop down menu, as yet the menu does not do anything. Java - Applications C&G Criteria: 5.3.2, 5.5.2, 5.5.3 Java applets require a web browser to run independently of the Java IDE. The Dos based console applications will run outside the IDE but have no access

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

Layouts and Components Exam

Layouts and Components Exam Layouts and Components Exam Name Period A. Vocabulary: Answer each question specifically, based on what was taught in class. Term Question Answer JScrollBar(a, b, c, d, e) Describe c. ChangeEvent What

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

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

JLayeredPane. Depth Constants in JLayeredPane

JLayeredPane. Depth Constants in JLayeredPane JLayeredPane Continuing on Swing Components A layered pane is a Swing container that provides a third dimension for positioning components depth or Z order. The class for the layered pane is JLayeredPane.

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

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

Marcin Luckner Warsaw University of Technology Faculty of Mathematics and Information Science

Marcin Luckner Warsaw University of Technology Faculty of Mathematics and Information Science Marcin Luckner Warsaw University of Technology Faculty of Mathematics and Information Science mluckner@mini.pw.edu.pl http://www.mini.pw.edu.pl/~lucknerm } Abstract Window Toolkit Delegates creation and

More information

1.1 GUI. JFrame. import java.awt.*; import javax.swing.*; public class XXX extends JFrame { public XXX() { // XXX. init() main() public static

1.1 GUI. JFrame. import java.awt.*; import javax.swing.*; public class XXX extends JFrame { public XXX() { // XXX. init() main() public static 18 7 17 1 1.1 GUI ( ) GUI ( ) JFrame public class XXX extends JFrame { public XXX() { // XXX // init()... // ( )... init() main() public static public class XXX extends JFrame { public XXX() { // setsize(,

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

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

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

JComponent. JPanel. JFrame. JFrame JDialog, JOptionPane. JPanel. JPanel

JComponent. JPanel. JFrame. JFrame JDialog, JOptionPane. JPanel. JPanel JComponent JPanel JPanel JFrameJDialog, JOptionPane JFrame JPanel Myclass SomeInterface SomeInterface anobject = new SomeInterface () { public void interfacefunc() { System.out.println("Some

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

MIT AITI Swing Event Model Lecture 17

MIT AITI Swing Event Model Lecture 17 MIT AITI 2004 Swing Event Model Lecture 17 The Java Event Model In the last lecture, we learned how to construct a GUI to present information to the user. But how do GUIs interact with users? How do applications

More information

Graphical interfaces & event-driven programming

Graphical interfaces & event-driven programming Graphical interfaces & event-driven programming Lecture 12 of TDA 540 (Objektorienterad Programmering) Carlo A. Furia Alex Gerdes Chalmers University of Technology Gothenburg University Fall 2017 Pop quiz!

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

Together, the appearance and how user interacts with the program are known as the program look and feel.

Together, the appearance and how user interacts with the program are known as the program look and feel. Lecture 10 Graphical User Interfaces A graphical user interface is a visual interface to a program. GUIs are built from GUI components (buttons, menus, labels etc). A GUI component is an object with which

More information

core 2 Basic Swing GUI Controls in Java 2

core 2 Basic Swing GUI Controls in Java 2 core Web programming Basic Swing GUI Controls in Java 2 1 2001-2003 Marty Hall, Larry Brown http:// Agenda New features Basic approach Summary of Swing components Starting points JApplet, JFrame Swing

More information

core programming Basic Swing GUI Controls in Java Marty Hall, Larry Brown

core programming Basic Swing GUI Controls in Java Marty Hall, Larry Brown core programming Basic Swing GUI Controls in Java 2 1 2001-2003 Marty Hall, Larry Brown http:// Agenda New features Basic approach Summary of Swing components Starting points JApplet, JFrame Swing equivalent

More information

Calculator Class. /** * Create a new calculator and show it. */ public Calculator() { engine = new CalcEngine(); gui = new UserInterface(engine); }

Calculator Class. /** * Create a new calculator and show it. */ public Calculator() { engine = new CalcEngine(); gui = new UserInterface(engine); } A Calculator Project This will be our first exposure to building a Graphical User Interface (GUI) in Java The functions of the calculator are self-evident The Calculator class creates a UserInterface Class

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