GUI Components. The Swing package has numerous GUI components that can be added to a window. The Swing package has numerous GUI components that can be.

Slides:



Advertisements
Similar presentations
Computer Science 209 Images and GUIs. Working with Java Colors The class java.awt.Color includes constants, such as Color.red, for some commonly used.
Advertisements

Basic Java – Interface design. Understand: How to use TextPad for Java How to define classes and objects How to create a GUI interface How event-driven.
Problem Solving 6 GUIs and Event Handling ICS-201 Introduction to Computing II Semester 071.
CMSC 341 Building Java GUIs. 09/26/2007 CMSC 341 GUI 2 Why Java GUI Development? Course is about Data Structures, not GUIs. We are giving you the opportunity.
Introduction to Java Classes, events, GUI’s. Understand: How to use TextPad How to define a class or object How to create a GUI interface How event-driven.
Java Swing Recitation – 11/(20,21)/2008 CS 180 Department of Computer Science, Purdue University.
Chapter 6 Graphical User Interface (GUI) and Object-Oriented Design (OOD)
©2004 Brooks/Cole Applets Graphics & GUIs. Figures ©2004 Brooks/Cole CS 119: Intro to JavaFall 2005 Graphical Programs Most applications these days are.
Implementing GUIs in Java ● The Java Foundation Classes (JFC) are a set of packages encompassing the following APIs: – Abstract Window Toolkit (AWT): native.
A Simple Applet. Applets and applications An applet is a Java program that runs on a web page –Applets can be run from: Internet Explorer Netscape Navigator.
Java Review Structure of a graphics program. Computer Graphics and User Interfaces Java is Object-Oriented A program uses objects to model the solution.
Drawing pictures with Java. JFrame: the basic Java window The swing package contains classes, objects and methods that can be used to create a consistent.
Chapter 5 - Making Music: An On-Screen Piano
GUI Basics: Introduction. Creating GUI Objects // Create a button with text OK JButton jbtOK = new JButton("OK"); // Create a label with text "Enter your.
Using the Netbeans GUI Builder. The Netbeans IDE provides a utility called the GUI Builder that assists you with creating Windows applications. The Netbeans.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Outline 20.1 Test-Driving the Screen Saver Application.
1 CSC111H Graphical User Interfaces (GUIs) Introduction GUIs in Java Understanding Events A Simple Application The Containment Hierarchy Layout Managers.
METHODS AND SCOPE CSCE More on Methods  This is chapter 6 in Small Java.
Applets and Frames CS 21a: Introduction to Computing I First Semester,
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.
Chapter 12- GUI’s, Java, and Swing.. Overview n What are GUI’s n How Java does GUI’s- Swing n Buttons n Containers n Text I/O and Swing n Review.
GUI programming Graphical user interface-based programming.
Part 1: Intro to GUI & events
Applets Applet is java program that can be embedded into HTML pages. Java applets runs on the java enabled web browsers such as mozilla and internet explorer.
1 CSC111H Graphical User Interfaces (GUIs) Introduction GUIs in Java Understanding Events A Simple Application The Containment Hierarchy Layout Managers.
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.
Digital Pictures Represented by pixels –With a red, green, and blue value stored for each pixel (each has a range from 0 to 255) Stored in.jpg (JPEG) files.
ManipulatingPictures-Mod6-part11 Manipulating Pictures, Arrays, and Loops part 1 Barb Ericson Georgia Institute of Technology.
Swing GUI Components You can create graphics components to place on your applet using classes available in the Swing package ( javax.swing ) Class names.
 2003 Joel C. Adams. All Rights Reserved. Calvin CollegeDept of Computer Science(1/15) MVC and Swing Joel Adams and Jeremy Frens Calvin College.
Object Oriented programming Instructor: Dr. Essam H. Houssein.
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved Introduction to Android (Part.
1 GUIs, Layout, Drawing Rick Mercer. 2 Event-Driven Programming with Graphical user Interfaces  Most applications have graphical user interfaces (GUIs)
Applets and Frames. Copyright 2005, by the authors of these slides, and Ateneo de Manila University. All rights reserved L14: GUI Slide 2 Applets Usually.
MIT-AITI 2004 – Lecture 16 Introduction to Swing.
Creating Windows. How can we use Java to create programs that use windows (GUI applications)? How can we use Java to create programs that use windows.
Java GUI. Graphical User Interface (GUI) a list a button a text field a label combo box checkbox.
A simple swing example GETTING STARTED WITH WIND CHILL.
Classes Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Classes. Preparation Scene so far has been background material and experience –Computing systems and problem solving –Variables –Types –Input and output.
Review_6 AWT, Swing, ActionListener, and Graphics.
Using classes. One step instantiation, Composition I JFrame myWindow = new JFrame( ); Two step Instantiation, Composition II private JFrame myWindow;
CSC 1051 – Data Structures and Algorithms I Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University Course website:
Outline Creating Objects The String Class The Random and Math Classes Formatting Output Enumerated Types Wrapper Classes Components and Containers Images.
1 Chapter 16: Creating Windows. 2 Basics of GUI Programming How to create a Window. TryWindow.java You always need a JFrame component before creating.
CSC 1051 – Data Structures and Algorithms I Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University Course website:
Java Swing One of the most important features of Java is its ability to draw graphics.
Lecture # 6 Graphical User Interface(GUI). Introduction A graphical user interface (GUI) presents a user- friendly mechanism for interacting with an application.
CSC 1051 – Data Structures and Algorithms I Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University Course website:
1 Drawing C Sc 335 Object-Oriented Programming and Design Rick Mercer.
Swing GUI Components So far, we have written GUI applications which can ‘ draw ’. These applications are simple, yet typical of all Java GUI applications.
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.
5-1 GUIs and Events Rick Mercer. 5-2 Event-Driven Programming with Graphical user Interfaces  Most applications have graphical user interfaces to respond.
C Sc 335 Object-Oriented Programming and Design Rick Mercer
Break Time! Graphical User Interface (GUI) NO EXAM….ONLY PROJECT!
CREATING A SIMPLE GUI Mr. Crone. First GUI Today we will use Swing to create the following application:
A First Look at GUI Applications
Computer Science 209 Graphics and GUIs.
Object Oriented Programming
Graphical User Interface (pronounced "gooey")
Digital Pictures Represented by pixels Stored in .jpg (JPEG) files
Ellen Walker Hiram College
Graphical user interface-based programming
Week 8 Swing NetBeans GUI Builder
Digital Pictures Represented by pixels Stored in .jpg (JPEG) files
Digital Pictures Represented by pixels Stored in .jpg (JPEG) files
CiS 260: App Dev I Chapter 6: GUI and OOD.
Chapter 12 GUI Basics.
Graphical User Interface
Presentation transcript:

GUI Components

The Swing package has numerous GUI components that can be added to a window. The Swing package has numerous GUI components that can be added to a window. There are three that we are focusing on today: There are three that we are focusing on today: Label  We worked with this yesterday. Label  We worked with this yesterday. Text Field Text Field Button Button

Labels: Labels: The JLabel class is used to create a label. The JLabel class is used to create a label. To create a label: To create a label: Define the label in the class fields. Define the label in the class fields. Ex: Ex: private JLabel lblMessage2; Create the label object and send it’s constructor the text of the label. Create the label object and send it’s constructor the text of the label. Ex: Ex: lblMessage2 = new JLabel("Moby's music is majestic!"); Add the label to the panel. Add the label to the panel. Ex: Ex:panel.add(lblMessage2);

Textboxes: Textboxes: The JTextField class is used to create a textbox. The JTextField class is used to create a textbox. To create a textbox: To create a textbox: Define the textbox in the class fields. Define the textbox in the class fields. Ex: Ex: private JTextField txtBox2; private JTextField txtBox2; Create the textbox object and send it’s constructor the width of the textbox (in characters). Create the textbox object and send it’s constructor the width of the textbox (in characters). Ex: Ex: txtBox2 = new JTextField(30); Add the textbox to the panel. Add the textbox to the panel. Ex: Ex:panel.add(txtBox2);

Buttons: Buttons: The JButton class is used to create a button. The JButton class is used to create a button. To create a button: To create a button: Define the button in the class fields. Define the button in the class fields. Ex: Ex: private JButton btnMeaning2; private JButton btnMeaning2; Create the button object and send it’s constructor the text for the button Create the button object and send it’s constructor the text for the button Ex: Ex: btnMeaning2 = new JButton("Brian Eno is a genius."); Add the button to the panel. Add the button to the panel. Ex: Ex:panel.add(btnMeaning2);

To alter the color of a JFrame Component: To alter the color of a JFrame Component: Many of the Swing component classes have the following methods: Many of the Swing component classes have the following methods: setBackground( )  This sets the background color. setBackground( )  This sets the background color. setForeground( )  This sets the text color. setForeground( )  This sets the text color. To use these methods, you have to import the AWT package: To use these methods, you have to import the AWT package: import java.awt.* import java.awt.* For example, to change the text color of a label: For example, to change the text color of a label: lblMessage.setForeground(Color.RED); lblMessage.setForeground(Color.RED);

Here are a few of the color constants you may use: Here are a few of the color constants you may use: Color.BLACK Color.BLACK Color.CYAN Color.CYAN Color.GRAY Color.GRAY Color.LIGHT_GREY Color.LIGHT_GREY Color.ORANGE Color.ORANGE Color.RED Color.RED Color.YELLOW Color.YELLOW Color.BLUE Color.BLUE Color.DARK_GREY Color.DARK_GREY Color.GREEN Color.GREEN Color.MAGENTA Color.MAGENTA Color.PINK Color.PINK Color.WHITE Color.WHITE

The Color Class: The Color Class: What if I need a different color? Easy! You can create a color object. What if I need a different color? Easy! You can create a color object. Just create a color object and pass its constructor the color value you want: Just create a color object and pass its constructor the color value you want: Ex: Ex: Color c4 = new Color(230, 204,255); Color c4 = new Color(230, 204,255); Then you pass the color object to the setBackground( ) or setForeground( ) method. Then you pass the color object to the setBackground( ) or setForeground( ) method. Ex: Ex: btnMeaning.setBackground(c4); btnMeaning.setBackground(c4);

RGB Settings: RGB Settings: The Color class uses the RGB (Red Green Blue) standard for setting its color. The Color class uses the RGB (Red Green Blue) standard for setting its color. Each letter is given a value from 1 to 255. For example, the following setttings create the color “yellow.” Each letter is given a value from 1 to 255. For example, the following setttings create the color “yellow.” R – 255 R – 255 G – 255 G – 255 B – 0 B – 0 You can use the following website to find different colors, and the RGB code that goes along with those colors:\ You can use the following website to find different colors, and the RGB code that goes along with those colors:\

Just copy the RGB value and replace the periods with commas. Just copy the RGB value and replace the periods with commas.

Using a main( ) method with GUI classes: Using a main( ) method with GUI classes: We have often used a Main class with a main( ) method to create instances of other classes. We have often used a Main class with a main( ) method to create instances of other classes. We can simply our programs by equipping the GUI class with a main method. We can simply our programs by equipping the GUI class with a main method. Just have the main method call the No-Arg constructor: Just have the main method call the No-Arg constructor: public static void main(String[] args) { Nihilism window = new Nihilism( ); Nihilism window = new Nihilism( ); }