Design Applet based java program to find the area and perimeter of a rectangle given its length and width. Java GUI.

Slides:



Advertisements
Similar presentations
Drawing in a frame – Java GUI
Advertisements

Chapter 6 Graphical User Interface (GUI) and Object-Oriented Design (OOD)
© L.Lúcio, An example GUI in Java n Two graphic libraries in Java u AWT u Swing n Swing is more recent than AWT: u Built on top of AWT classes;
Graphical User Interface (GUI) and Object-Oriented Design (OOD)
Chapter 14 Applets. 2 Knowledge Goals Understand the differing roles of applications and applets Understand how a browser operates Understand the role.
Creating a GUI with Swing. Introduction Very useful link: Swing – is a part of JFC (Java Foundation.
COMP 14 Introduction to Programming Miguel A. Otaduy June 7, 2004.
Graphical User Interface (GUI) and Object-Oriented Design (OOD)
Chapter 6 Graphical User Interface (GUI) and Object-Oriented Design (OOD)
1 Class 8. 2 Chapter Objectives Use Swing components to build the GUI for a Swing program Implement an ActionListener to handle events Add interface components.
Chapter 6: Graphical User Interface (GUI) and Object-Oriented Design (OOD) J ava P rogramming: Program Design Including Data Structures Program Design.
Lesson 35: Review of the Java GUI. The JFrame, Container and JButton.
PROGRAMMING REVIEW Lab 2 EECS 448 Dr Fengjun Li and Meenakshi Mishra.
Chapter 9: Applets Jim Burns Fall Outline Learn about applets Learn about applets Write an HTML doc to host an applet Write an HTML doc to host.
Java Programming: From Problem Analysis to Program Design, Second Edition1  Learn about basic GUI components.  Explore how the GUI components JFrame,
JAPPLET.
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.
11/9: Recursion, Method Overloading About Scoping.java Recursion Method overloading.
Lesson 36: The calculator – Java Applets. 1. Creating Your First Applet HelloWorldApp is an example of a Java application, a standalone program. Now you.
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.
עקרונות תכנות מונחה עצמים תרגול 4 - GUI. Outline  Introduction to GUI  Swing  Basic components  Event handling.
GUI programming Graphical user interface-based programming.
Java GUI building with Swing. 2 AWT (Abstract Window Toolkit) Present in all Java implementations Described in (almost) every Java textbook Adequate for.
Java Applets. Topics What is an applet? To convert GUI applications to Applets Hello World applet example!! Applets life cycle examples Invoking applets.
Graphic User Interface. Graphic User Interface (GUI) Most of us interact with computers using GUIs. GUIs are visual representations of the actions you.
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.
Chapter 12 1 TOPIC 13B l Buttons and Action Listeners Window Interfaces Using Swing Objects.
CompSci 100E 35.1 Graphical User Interfaces: GUIs  Components  Flat Layouts  Hierarchical Layouts  Designing a GUI  Coding a GUI.
Swing Differences between Swing and AWT Naming Conventions All Swing components begin with a capital J -- JPanel, JButton, JScrollBar, JApplet, etc..
Layout Managers Arranges and lays out the GUI components on a container.
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.
Java Programming Applets. Topics Write an HTML document to host an applet Understand simple applets Use Labels with simple AWT applets Write a simple.
1 Class 6. 2 Objectives Objectives Enable your applications to perform actions in response to JButton clicks Get the text the user enters in a textfield.
Java GUI. Graphical User Interface (GUI) a list a button a text field a label combo box checkbox.
CompSci Event Handling. CompSci Event Handling The Plan  Sequential (Single Thread) Model  Event Model  Making the GUI interactive  Examples.
Introduction to GUI in 1 Graphical User Interface 2 Nouf Almunyif.
Ch13 Creating windows and applets. Short overview AWT (Abstract Windowing Toolkit) Early Java development used graphic classesEarly Java development used.
A simple swing example GETTING STARTED WITH WIND CHILL.
1 GUI programming Graphical user interface-based programming Chapter G1 (pages )
Java Programming: From Problem Analysis to Program Design, 3e Chapter 6 Graphical User Interface (GUI) and Object-Oriented Design (OOD)
Java Programming: From Problem Analysis to Program Design, Second Edition1 Lecture 5 Objectives  Learn about basic GUI components.  Explore how the GUI.
Swing. Introduction to Swing What is Swing? “ Swing is a diverse collection of lightweight components that can be used to build sophisticated user interfaces.”
1 Applications & Applets Standalone applications & Java applets Peter Mozelius DSV/UCSC.
Review_6 AWT, Swing, ActionListener, and Graphics.
Chapter 10 - Writing Graphical User Interfaces1 Chapter 10 Writing Graphical User Interfaces.
Lesson 28: More on the GUI button, frame and actions.
Graphical User Interface (GUI)
Event Handling CS 21a: Introduction to Computing I First Semester,
Chapter 6 Graphical User Interface (GUI) and Object-Oriented Design (OOD)
Applets. 9/04/2005 Copyright 2005, by the authors of these slides, and Ateneo de Manila University. All rights reserved L12: Applets Slide 2 Applets Usually.
GUI.1 Graphical User Interfaces GUIs. GUI.2 The Plan Components Flat Layouts Hierarchical Layouts Designing a GUI Coding a GUI.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter Chapter 7 ( Book Chapter 14) GUI and Event-Driven Programming.
Multiple buttons and action calls
Introduction Many Java application use a graphical user interface or GUI (pronounced “gooey”). A GUI is a graphical window or windows that provide interaction.
Java Applet What is a Java Applet? How is applet compiled?
Graphical User Interfaces -- GUIs
A First Look at GUI Applications
Graphical User Interface (pronounced "gooey")
Java Programming: From Problem Analysis to Program Design,
Ellen Walker Hiram College
Graphical User Interface (GUI)
Chapter 13: Advanced GUIs and Graphics
Event-driven programming for GUI
Graphical user interface-based programming
Graphical User Interfaces in Java Event-driven programming
The calculator – Java GUI
CiS 260: App Dev I Chapter 6: GUI and OOD.
Advanced GUIs and Graphics
Presentation transcript:

Design Applet based java program to find the area and perimeter of a rectangle given its length and width. Java GUI

Final Code import javax.swing.*; import java.awt.*; import java.awt.event.*; import java.awt.Graphics; // program uses class Graphics import javax.swing.JApplet; // program uses class JApplet public class RectangleGUIFinal extends JApplet{ private JLabel lengthL, widthL, areaL, perimeterL; private JTextField lengthTF, widthTF, areaTF,perimeterTF; private JButton calculateB, exitB; private ExitButtonHandler ebHandler; private CalculateButtonHandler cbHandler; public void init () { //Create the four labels lengthL = new JLabel("Enter the length: ", SwingConstants.RIGHT); widthL = new JLabel("Enter the width: ", SwingConstants.RIGHT); areaL = new JLabel("Area: ", SwingConstants.RIGHT); perimeterL = new JLabel("Perimeter: ", SwingConstants.RIGHT);

//Create the four text fields lengthTF = new JTextField(10); widthTF = new JTextField(10); areaTF = new JTextField(10); perimeterTF = new JTextField(10); //Create Calculate Button calculateB = new JButton("Calculate"); cbHandler = new CalculateButtonHandler(); calculateB.addActionListener(cbHandler); //Create Exit Button exitB = new JButton("Exit"); ebHandler = new ExitButtonHandler(); exitB.addActionListener(ebHandler);

// Step 2 : Adding content pane to The Container Window Container pane = getContentPane(); // Step 3: Setting layout inside content pane pane.setLayout(new GridLayout(5, 2)); // Step 4: Adding Components to the content pane pane.add(lengthL); pane.add(lengthTF); pane.add(widthL); pane.add(widthTF); pane.add(areaL); pane.add(areaTF); pane.add(perimeterL); pane.add(perimeterTF); pane.add(calculateB); pane.add(exitB); }

//Step 5 : Adding soul to Components private class CalculateButtonHandler implements ActionListener{ public void actionPerformed(ActionEvent e){ double width, length, area, perimeter; length = Double.parseDouble(lengthTF.getText()); width = Double.parseDouble(widthTF.getText()); area = length * width; perimeter = 2 * (length + width); areaTF.setText("" + area); perimeterTF.setText("" + perimeter); } private class ExitButtonHandler implements ActionListener{ public void actionPerformed(ActionEvent e){ System.exit(0); } public void paint( Graphics g ){ super.paint( g ); }