Frame Windows Application program, not applet Construct and show frame JFrame frame = new JFrame(); *** frame.show(); *** Set default close operation..

Slides:



Advertisements
Similar presentations
Things to mention public static void main(String [] args) –The starting point for a free-standing Java application (i.e. one not run from the DrJava interactions.
Advertisements

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.
©TheMcGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter 7 Event-Driven Programming and Basic GUI Objects.
IEEM 110 Computing in Industrial Applications Basic User Interface in Java.
1 Event Driven Programming with Graphical User Interfaces (GUIs) A Crash Course © Rick Mercer.
Chapter 7 Event-Driven Programming and Basic GUI Objects.
CS3157 Java UI Recitation. Material Covered: Overview of AWT components, Event Handling, creating applets, and sample UI. Not covered in recitation: Drawing,
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter Chapter 14 GUI and Event-Driven Programming.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter Chapter 14 GUI and Event-Driven Programming.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter Chapter 14 GUI and Event-Driven Programming.
Graphical User Interfaces
GUI and Event-Driven Programming Part 2. Event Handling An action involving a GUI object, such as clicking a button, is called an event. The mechanism.
Chapter 6: Graphical User Interface (GUI) and Object-Oriented Design (OOD) J ava P rogramming: Program Design Including Data Structures Program Design.
PROGRAMMING REVIEW Lab 2 EECS 448 Dr Fengjun Li and Meenakshi Mishra.
Java Swing © Walter Milner 2005: Slide 1 Java Swing Walter Milner.
Introduction to GUI Java offers a great number of pre-defined classes to support the development of graphical user interfaces –These are broken down into.
Combo Box, Check Boxes, and Radio Buttons. Radio Buttons User can click radio buttons, just like other buttons BUT Radio buttons are mutually exclusive.
Using Inheritance to Customize Frames Use inheritance for complex frames to make programs easier to understand Design a subclass of JFrame Store the components.
Java Programming: From Problem Analysis to Program Design, Second Edition1  Learn about basic GUI components.  Explore how the GUI components JFrame,
Layout Management Containers can arrange their components. Our container is a JPanel, and it can set the way it’s components will be laid out : mypanel.setLayout.
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.
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.
עקרונות תכנות מונחה עצמים תרגול 4 - GUI. Outline  Introduction to GUI  Swing  Basic components  Event handling.
GUI programming Graphical user interface-based programming.
GUI Components and Design Here we add one more component to our programs, JButtons –JButtons can only be inserted into JPanels (or JApplets) –Clicking.
Java Event Handling CSIS 3701: Advanced Object Oriented Programming.
GUIs in Java Swing, Events CS2110, SW Development Methods Readings: MSD, Chapter 12 Lab Exercise.
Previous programs used a JLabel for OUTPUT. Another Swing component that can be used for both user input and output is the JTextfield. Suppose we want.
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.
Copyright © 2002, Systems and Computer Engineering, Carleton University c-Gui3.ppt * Object-Oriented Software Development Part 18-c Building.
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.
Swing GUI Components You can create graphics components to place on your applet using classes available in the Swing package ( javax.swing ) Class names.
Swing Differences between Swing and AWT Naming Conventions All Swing components begin with a capital J -- JPanel, JButton, JScrollBar, JApplet, etc..
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.
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.
1 / 67 COP 3503 FALL 2012 SHAYAN JAVED LECTURE 14 Programming Fundamentals using Java 1.
Java GUI. Graphical User Interface (GUI) a list a button a text field a label combo box checkbox.
DCS2133 Object Oriented Programming Graphical User Interface & Event-Driven Programming.
Introduction to GUI in 1 Graphical User Interface 2 Nouf Almunyif.
A simple swing example GETTING STARTED WITH WIND CHILL.
Java Programming: From Problem Analysis to Program Design, 3e Chapter 6 Graphical User Interface (GUI) and Object-Oriented Design (OOD)
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter Chapter 7-2 ( Book Chapter 14) GUI and Event-Driven Programming.
Java Programming: From Problem Analysis to Program Design, Second Edition1 Lecture 5 Objectives  Learn about basic GUI components.  Explore how the GUI.
CHAPTER 10 EVENT HANDLING. CHAPTER GOALS To understand the Java event model To install mouse and action listeners To accept mouse and text input To display.
Ajmer Singh PGT(IP) JAVA IDE Programming - I. Ajmer Singh PGT(IP) GUI (Graphical User Interface) It is an interface that uses a graphic entities along.
Big Java by Cay Horstmann Copyright © 2008 by John Wiley & Sons. All rights reserved. Event Handling and GUI Components.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Outline 17.1 Test-Driving the Student Grades Application.
Swing GUI Components So far, we have written GUI applications which can ‘ draw ’. These applications are simple, yet typical of all Java GUI applications.
Graphical User Interface (GUI)
Java Visual Applications CSIS 3701: Advanced Object Oriented Programming.
GUI.1 Graphical User Interfaces GUIs. GUI.2 The Plan Components Flat Layouts Hierarchical Layouts Designing a GUI Coding a GUI.
회원가입 - GUI ** 오지*.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter Chapter 7 ( Book Chapter 14) GUI and Event-Driven Programming.
Java Swing. Note - this presentation.. often needs to refer to source code which is too big to put on a slide So the source code is in a separate Word.
Multiple buttons and action calls
Modular Event Handling
Swing JComponents.
Graphical User Interface (pronounced "gooey")
Graphical user interface with Swing by jose maria gonzalez pinto
Chapter 4 Interface Types and Polymorphism Part 2
Ellen Walker Hiram College
Graphical user interface-based programming
Chapter 7-2 (Book Chapter 14)
Steps to Creating a GUI Interface
Chapter 7-2 (Book Chapter 14)
CiS 260: App Dev I Chapter 6: GUI and OOD.
Presentation transcript:

Frame Windows Application program, not applet Construct and show frame JFrame frame = new JFrame(); *** frame.show(); *** Set default close operation.. frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Add components to a panel, then set the panel as content pane JPanel panel = new JPanel(); panel.add(...); panel.add(...) frame.setContentPane(panel);

Text Components JTextField holds a single line of text JTextArea holds multiple lines Construct with new JTextArea(rows, columns) textArea.append(aString) appends text Use textArea.setEditable(false) to use for display only To add scroll bars, use JScrollPane scrollPane = new JScrollPane(textArea); panel.add(scrollPane); or frame.setContentPanel(scrollPane);

for example……. public class LineData0{ public static void main (String [] args) { int width = 5; JLabel x1Label = new JLabel("x1 = "); //instantiate components JTextField x1Field = new JTextField(width); JLabel y1Label = new JLabel("y1 = "); JTextField y1Field = new JTextField(width); JLabel x2Label = new JLabel("x2 = "); JTextField x2Field = new JTextField(width); JLabel y2Label = new JLabel("y2 = "); JTextField y2Field = new JTextField(width); JTextArea out = new JTextArea(15,30); JScrollPane sPane = new JScrollPane(out); JButton anotherButton = new JButton("Go"); //button event handling code would go here, this frame will just display

//create listener class class BtnListener implements ActionListener{ public void actionPerformed(ActionEvent e){ double x1 = Double.parseDouble(x1Field.getText()); double y1 = Double.parseDouble(y1Field.getText()); double x2 = Double.parseDouble(x2Field.getText()); double y2 = Double.parseDouble(y2Field.getText()); double slope = (y2-y1)/(x2-x1); out.append("Slope of line is: " + slope + "\n\n"); } //register a listener object with button component ActionListener bltn = new BtnListener(); anotherButton.addActionListener(bltn); *note the the textfields and textarea objects must have been declared as final in the main

//add components to panel JPanel thePanel = new JPanel (); thePanel.add(x1Label); thePanel.add(x1Field); thePanel.add(y1Label); thePanel.add(y1Field); thePanel.add(x2Label); thePanel.add(x2Field); thePanel.add(y2Label); thePanel.add(y2Field); thePanel.add(anotherButton); thePanel.add(sPane); // put panel on frame and show JFrame theFrame = new JFrame(); theFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); theFrame.setContentPane(thePanel); theFrame.pack(); theFrame.show(); }

Alternatively, 2 frames could be used……. // put panels on frames JFrame aFrame = new JFrame(); aFrame.setContentPane(sPane); //omit addition of this pane to thePanel aFrame.pack(); aFrame.show(); JFrame theFrame = new JFrame(); theFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); theFrame.setContentPane(thePanel); theFrame.pack(); theFrame.show(); }