Datalogi A 6: 13/10. Java and swing Graphics programming: Windows with menus Buttons, textfields, scroll panels etc Animations, images, Events from mouse.

Slides:



Advertisements
Similar presentations
Liang, Introduction to Java Programming, Ninth Edition, (c) 2013 Pearson Education, Inc. All rights reserved. 1 Chapter 17 Creating User Interfaces.
Advertisements

Computer Science A 11: 24/3. Animation - Dubble buffering - Transformations - Sprites and textures - Sound.
Graphical User Interfaces CS 2110 Spring Ivan Sutherland: “Sketchpad”,
JAVA API (GUI) Subject:T0934 / Multimedia Programming Foundation Session:1 Tahun:2009 Versi:1/0.
GUI and Swing, part 2 The illustrated edition. Scroll bars As we have previously seen, a JTextArea has a fixed size, but the amount of text that can be.
1 Chapter 13 Creating User Interfaces. 2 Objectives F To create graphical user interfaces with various user-interface components: JButton, JCheckBox,
Chapter 6 Graphical User Interface (GUI) and Object-Oriented Design (OOD)
Liang, Introduction to Java Programming, Seventh Edition, (c) 2009 Pearson Education, Inc. All rights reserved Chapter 16 Creating User Interfaces.
Copyright © 2006 The McGraw-Hill Companies, Inc. Programming Languages 2nd edition Tucker and Noonan Chapter 16 Event-Driven Programming Of all men’s miseries.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved Chapter 15 Creating User.
1 Event Driven Programming with Graphical User Interfaces (GUIs) A Crash Course © Rick Mercer.
Computer Science A 11: 20/2. Java and swing Graphics programming: Windows with menus Buttons, textfields, scroll panels etc Animations, images, Events.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter Chapter 14 GUI and Event-Driven Programming.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved L03 (Chapter 15) Creating.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved L04 (Chapter 15) Creating.
1 GUI Elements in Java Nelson Padua-Perez Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
1 Creating User Interfaces. 2 Motivations A graphical user interface (GUI) makes a system user-friendly and easy to use. Creating a GUI requires creativity.
Chapter 13: Advanced GUIs and Graphics J ava P rogramming: From Problem Analysis to Program Design, From Problem Analysis to Program Design, Second Edition.
Unit 11 Object-oriented programming: Graphical user interface Jin Sa.
Web Design & Development Lecture 18. Java Graphics.
GUI Basics: Introduction. Creating GUI Objects // Create a button with text OK JButton jbtOK = new JButton("OK"); // Create a label with text "Enter your.
Chapter 13 Advanced GUIs and Graphics. Chapter Objectives Learn about applets Explore the class Graphics Learn about the class Font Explore the class.
Draw Shapes Introduction to simple graphics. What is a Component? A class that resides in the java.awt package Examples include: –Button, java.awt.Button.
1 Event Driven Programming wirh Graphical User Interfaces (GUIs) A Crash Course © Rick Mercer.
Java Programming: From Problem Analysis to Program Design, 4e Chapter 12 Advanced GUIs and Graphics.
Liang, Introduction to Java Programming, Fifth Edition, (c) 2005 Pearson Education, Inc. All rights reserved Chapter 13 Creating User.
1 CSC111H Graphical User Interfaces (GUIs) Introduction GUIs in Java Understanding Events A Simple Application The Containment Hierarchy Layout Managers.
Introduction to GUI in Java 1. Graphical User Interface Java is equipped with many powerful,easy to use GUI component such as input and output dialog.
MIT AITI 2003 Lecture 17. Swing - Part II. The Java Event Model Up until now, we have focused on GUI's to present information (with one exception) Up.
Java GUI CSCE 190 – Java Instructor: Joel Gompert Mon, July 26, 2004.
Java GUIs and Graphics CNS Outline  Introduction  Events  Components  Layout managers  Drawing  Introduction  Events  Components  Layout.
Introduction to Swing Components Chapter 14.  Part of the Java Foundation Classes (JFC)  Provides a rich set of GUI components  Used to create a Java.
GUI Basics.
GUI Chapter 10 Graphics context and objects Creating a window based application JFrame, JTextField, JButton Containers and Controls Graphics commands Layout.
Java GUIs and Graphics CNS Outline  Introduction  Events  Components  Layout managers  Drawing  Introduction  Events  Components  Layout.
1 CSC111H Graphical User Interfaces (GUIs) Introduction GUIs in Java Understanding Events A Simple Application The Containment Hierarchy Layout Managers.
Copyright © 2013 by John Wiley & Sons. All rights reserved. GRAPHICAL USER INTERFACES CHAPTER Slides by Donald W. Smith TechNeTrain.com Final Draft 10/30/11.
Graphic User Interface. Graphic User Interface (GUI) Most of us interact with computers using GUIs. GUIs are visual representations of the actions you.
FEN IntroJava2006 AAU1 GUI: Graphical User Interface AWT/SWING: Components Drag and Drop in NetBeans Events Listeners.
1 Graphical User Interfaces AWT and Swing packages Frames and Panels Components Nested Panels Images Reading for this Lecture: L&L, 3.9 – 3.11.
Graphics and Event-Driven Programming in Java John C. Ramirez Department of Computer Science University of Pittsburgh.
MSc Workshop - © S. Kamin, U. ReddyLect 3 - GUI -1 Lecture 3 - Graphical User Interfaces r GUI toolkits in Java API r JFrame r GUI components.
ITEC 109 Lecture 27 GUI. GUIs Review Sounds –Arrays hold sample values –Creating a keyboard –Sound effects Homework 3 –The big two –Due after break –Lab.
Introduction to GUI Programming with Java Graphical User Interfaces With AWT and Swing Towson University *Ref:
GUI Basics. What is GUI? A graphical user interface (GUI) is a type of user interface item that allows people to interact with programs in more ways than.
1 / 67 COP 3503 FALL 2012 SHAYAN JAVED LECTURE 14 Programming Fundamentals using Java 1.
Lec.10 (Chapter 8 & 9) GUI Jiang (Jen) ZHENG June 27 th, 2005.
Creating a GUI with JFC/Swing. What are the JFC and Swing? JFC –Java Foundation Classes –a group of features to help people build graphical user interfaces.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved Chapter 15 Creating User.
CHAPTER:07 JAVA IDE PROGRAMMING-II Prepared By Prepared By : VINAY ALEXANDER ( विनय अलेक्सजेंड़र ) PGT(CS),KV JHAGRAKHAND.
Java GUI. Graphical User Interface (GUI) a list a button a text field a label combo box checkbox.
GUI Basics. Agenda What GUI How to make in java Creating frames Frequently used GUI components Layout Managers.
Creating User Interfaces Event-Driven Programming.
Basics of GUI Programming Chapter 11 and Chapter 22.
Creating a Window. A basic window in Java is represented by an object of the class Window in the package java.awt.
GUI Components CSCI 201L Jeffrey Miller, Ph.D. HTTP :// WWW - SCF. USC. EDU /~ CSCI 201 USC CSCI 201L.
Swing GUI Components So far, we have written GUI applications which can ‘ draw ’. These applications are simple, yet typical of all Java GUI applications.
Getting Started with GUI Programming Chapter 10 CSCI 1302.
Java Swing. Graphical User Interfaces (GUIs) GUI: An application that uses graphical objects to interact with users GUI applications consist of: – Events:
Dept. of CSIE, National University of Tainan 10/21/2012 Working with Swing.
1 Event Driven Programming with Graphical User Interfaces (GUIs) A Crash Course © Rick Mercer.
A Quick Java Swing Tutorial
Graphical user interface with Swing by jose maria gonzalez pinto
Ellen Walker Hiram College
Chapter 13: Advanced GUIs and Graphics
Chapter 7 Creating User Interfaces
Chapter 13 Creating User Interfaces
Chapter 17 Creating User Interfaces
Chapter 17 Creating User Interfaces
Chapter 12 GUI Basics.
Presentation transcript:

Datalogi A 6: 13/10

Java and swing Graphics programming: Windows with menus Buttons, textfields, scroll panels etc Animations, images, Events from mouse clicks, keyboard etc. Can be quite complicated…

EmptyFrame.java import javax.swing.JFrame; public class EmptyFrame{ public static void main(String args[]){ JFrame frame=new JFrame("EmptyFrame"); frame.setSize(600,600); frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE); frame.setVisible(true); }

EmptyFrame

Add a canvas to the window public static void main(String args[]){ JFrame frame=new JFrame(); frame.setSize(600,600); frame.setTitle("DrawShapes"); frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE); JCanvas canvas = new JCanvas(); frame.add(canvas); frame.setVisible(true);.. }

Coordinate system:

drawLine(135,230,335,370)

drawOval(135,230,200,140)

What to draw on a canvas: Line Oval/ellipsis Arcs (parts of an ellipsis Rectangles Curves, quadratic, qubic, bezier Images Text

The state when drawing: Current Font Current Stroke (width of lines) Current Paint (color of areas) Current Transform (scaling, rotation, deformation of drawings) Current Composite (new items can be made partially transparent Current clipping area. (limit the area in which you can draw)

setFont(new Font("Serif",Font.BOLD,150)); drawString("(GyÑ)",50,200);

Paint canvas.setPaint(Color.red); canvas.fillRect(50,50,100,100); canvas.setPaint(Color.blue); canvas.fillOval(250,50,100,100); canvas.setPaint(Color.green); canvas.fillArc(450,50,100,100,45,270); canvas.setPaint(new GradientPaint( 50,350,Color.red,450,350,Color.blue)); canvas.fillRect(50,300,500,100);

Paint

Java swing components Windows and components

Example

JLabel A bit of text and/or an icon new JLabel(”Label 1”,new IconImage(..))

JButton A button you can press. Text and/or an image (icon)

Radiobutton and checkbox Press to select or de-select

JTextField TextField: a line where you can enter text using the keyboard.

JTextArea TextArea: a multi-line area for entering text

JSlider A slider: select a value By dragging a knob

JSpinner Select a value by stepping through a bounded range of values

JComboBox Select a value from a drop-down list

JList Select an a value or an interval of values from a list

Horizontal boxes and glue JBox.hbox(…)

Vertical box JBox.vbox(..)

Split pane, scroll pane

Borders Examples:

Making borders t1.setBorder(BorderFactory. createBevelBorder(BevelBorder.RAISED)); t2.setBorder(BorderFactory. createEtchedBorder()); t3.setBorder(BorderFactory. createMatteBorder(2,5,2,5,Color.red)); t4.setBorder(BorderFactory. createTitledBorder("My Title")); b1.setBorder(BorderFactory. createLineBorder(Color.blue,4));

Next time: events How to get information about user input.