LAB SESSION 9 * COMPONENTS IN JAPPLET * SETBOUNDS METHOD * DIRECTION OF INPUT TO STDIN.

Slides:



Advertisements
Similar presentations
GUI Elements Session 17. Memory Upload Layout Components Button TextField TextArea Label Choice Containers Panels The applet itself.
Advertisements

Swing! Components and Images. Example Swing Components (also called “widgets”) Graphic from sun.com.
TCU CoSc Programming with Java Visual Design (Chapter 5)
Problem Solving 6 GUIs and Event Handling ICS-201 Introduction to Computing II Semester 071.
TCU CoSc Programming with Java Handling Events.
Graphical User Interfaces CS 2110 Spring Ivan Sutherland: “Sketchpad”,
Jan AWT Widgets Yangjun Chen Dept. Business Computing University of Winnipeg.
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.
1 Simple Phone Applet Lab Mobile Phone Display Area Send, Menu and End Numbers 0-9 * and #
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved Chapter 15 Creating User.
Group Boxes and Panels Arrange components on a GUI Buttons and etc. can be placed inside a group box or panel. All these buttons move together when the.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved L04 (Chapter 15) Creating.
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.
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.
AWT Components (Chapter 9) Java Certification Study Group January 21, 1999 Mark Roth.
Chapter 13 Advanced GUIs and Graphics. Chapter Objectives Learn about applets Explore the class Graphics Learn about the class Font Explore the class.
TCU CoSc Introduction to Programming (with Java) Java Components.
Java Programming, 3e Concepts and Techniques Chapter 3 Section 65 – Manipulating Data Using Methods – Java Applet.
OBJECT ORIENTED PROGRAMMING
Java Programming: From Problem Analysis to Program Design, 4e Chapter 12 Advanced GUIs and Graphics.
Review Session for EXCEPTIONS & GUIS -David Gries 1 Adapted from Previous Review Slides.
Creating User Interfaces F JComponent F JButton F JLabel F JTextField F JTextArea F JComboBox F JList F JCheckBox F JRadioButton F Dialogs.
Applets and Frames CS 21a: Introduction to Computing I First Semester,
GUI Components and Design Here we add one more component to our programs, JButtons –JButtons can only be inserted into JPanels (or JApplets) –Clicking.
Chapter 9: Creating User Interfaces What is JavaBean? What is JavaBean? JComponent JComponent JButton JButton JLabel JLabel JTextField JTextField JTextArea.
Java Swing. Swing is a set of classes that provides more powerful and flexible components than are possible with the AWT. In addition to the familiar.
Chapter 9: Creating User Interfaces What is JavaBean? What is JavaBean? JComponent JComponent Jbutton Jbutton ImageIcon ImageIcon JLabel JLabel JTextField.
CC1007NI: Further Programming Week 6-7 Dhruba Sen Module Leader (Islington College)
1 Lesson: Applets with User Input and Output with GUI ICS4M.
Layout Managers Arranges and lays out the GUI components on a container.
Java Applets: GUI Components, Events, Etc. Ralph Westfall June, 2010.
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.
Class Class 20 Objectives Use JCheckbox, JRadioButton, and a JComboBox in a UID.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved Chapter 15 Creating User.
Java Applet Basics (2). The Body Mass Index Calculator.
Getting Input. Text Fields A text field is a box that the user can type in Use the JTextField class JTextField tf1 = new JTextField(15); 15 is the field.
Introduction to Java Chapter 9 - Graphical User Interfaces and Applets1 Chapter 9 Graphical User Interfaces and Applets.
Swing. Introduction to Swing What is Swing? “ Swing is a diverse collection of lightweight components that can be used to build sophisticated user interfaces.”
AWT Package. Java GUI classes are contained in the java.awt package. Java GUI classes are contained in the java.awt package. A graphical Java program.
The Swing GUI Components Chapter 29 An enhanced alternative to AWT The PC does not need an appletviewer or browser Swing overcomes some AWT drawbacks.
Visual Index of Swing GUI Components
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.
Software Construction LAB 08 Java Programming with SWING GUI Builder.
CSI 3125, Preliminaries, page 1 AWT Control. CSI 3125, Preliminaries, page 2 AWT Control The AWT supports the following types of controls: ■ Labels ■
Copyright © Curt Hill More Widgets In Abstract Window Toolbox.
Computer Science [3] Java Programming II - Laboratory Course Lab 4 -1 : Introduction to Graphical user interface GUI Components Faculty of Engineering.
Lecture 33: More Graphical User Interface (GUI) Announcements & Review Read Ch GU1 & GU2 Cohoon & Davidson Ch 14 Reges & Stepp Lab 10 set game due 4/26.
Lecture # 6 Graphical User Interface(GUI). Introduction A graphical user interface (GUI) presents a user- friendly mechanism for interacting with an application.
1 Java and AWT CPS 470 Spring 1998 Laura Campbell.
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.
Dept. of CSIE, National University of Tainan 10/21/2012 Working with Swing.
Chapter 3: Widgets for a GUI General Component methods Useful widgets classes –Text classes Label TextField TextArea –Active widgets Button Checkbox Choice.
GUIs & Event-Driven Programming Chapter 11 Review.
Java Visual Applications CSIS 3701: Advanced Object Oriented Programming.
Prepared by: Dr. Abdallah Mohamed, AOU-KW Unit 6 Graphical user interfaces 1.
Advanced OOP MCS-3 OOP BSCS-3 Lecture # 7. GUI Components - > Jframe ->JPasswordField (javax.Swing.JPasswordField) GUI Components - > Jframe ->JPasswordField.
A First Look at GUI Applications Radio Buttons and Check Boxes
JAVA SWINGS By: Pavan D.M..
Abstract Window ToolKit (AWT)
Chapter 7 Creating User Interfaces
Chapter 13 Creating User Interfaces
Basic Elements of The GUI
AWT Components and Containers
Java GUI programming with Swing
Presentation transcript:

LAB SESSION 9 * COMPONENTS IN JAPPLET * SETBOUNDS METHOD * DIRECTION OF INPUT TO STDIN

JAPPLET IS A SUB CLASS OF APPLET Components in JAPPLET AND APPLET JApplet Applet JButton Button JTextField TextField JCheckbox Checkbox JRadioButton RadioButton JComboBox Choice control ListBox ScrollBars TextArea

JLABEL JLabel(String str,int align) Str is a message displayed on label Align indicates the message should be aligned in center,left or right There are two methods to set the text and get the text on the Jlabel String getText(); Void setText();

Public applet1 extends JApplet { Public void init() { Container cpane=getContentPane(); Cpane.setLayout(null); JLabel ll=new JButton(String str); ll.setBounds(10,10,50,50); Cpane.add(ll); }

JTextField JTextField(String str,int cols) JTextField(int cols) Here str is string that is intially to be displayed in the textBox when applet is loaded cols-no of cols in textBox(width of the textBox);

Public applet1 extends JApplet { Public void init() { Container cpane=getContentPane(); Cpane.setLayout(null); JTextField tt=new JButton(String str); tt.setBounds(10,10,50,50); Cpane.add(tt); }

JButton JButton(String str) Str is a message displayed on button There are two methods to set the text and get the text on the Jlabel String getText(); Void setText();

Public applet1 extends JApplet { Public void init() { Container cpane=getContentPane(); Cpane.setLayout(null); JButton jb=new JButton(String str); Cpane.add(jb); Jb.setForeground(Color.BLUE); }

JCheckBox JCheckBox(String s,boolean state); Str is a message displayed on checkbox. state is set to True or False indicates whether the textbox should be selected or not The state of the textbox can be changed via this method Void setSelected(boolean state); void getSelected(); //get selected items

Public applet1 extends JApplet { Public void init() { Container cpane=getContentPane(); Cpane.setLayout(null); JCheckBox cb=new JButton(String str); Cb.setBounds(10,10,45,70); Cpane.add(cb); }

JRadioButton JRadioButton(String s,boolean state) Str is a message displayed on Radiobutton State indicates whether it is selected or not The state of the textbox can be changed via this method Void setSelected(boolean state); void getSelected(); //get selected items

Public applet1 extends JApplet { Public void init() { Container cpane=getContentPane(); Cpane.setLayout(null); RadioButtonGroup jpg=new RadioButtonGroup(); JRadioButton bb=new JButton(String str); JRadioButton bb1=new JButton(String str); bb.setBounds(10,10,50,50); bb1.setBounds(10,10,50,50); Jbg.add(bb); Jbg.add(bb1); Cpane.add(bb); }

COMBOBOX(Dropdown list) JComboBox(); JComboBox(vector v); It’s a dropdown list containing items that can be selected We can add items by using this method Void additem(Object ob);

Public applet1 extends JApplet { Public void init() { Container cpane=getContentPane(); Cpane.setLayout(null); JComboBox jcb=new JButton(String str); Cpane.add(jcb); Jcb.add(“france”); Jcb.add(“England”); }

LISTS LIST(int cols,int multipleselect) it list a list of items that can be selected cols indicates the length the list how many can be listed multiselect indicates 0/1 0-only one can be selected at a time 1 user can select 2 or more items Methods used to add items are Void add(String name); Void add(String str,int index);

There are two more methods to get selcted item name or index String getSelectedItem(); int getSelectedIndex(); IF MULTISELECT IS 1 THEN String[] getSelectedItems(); int[] getSelectedIndexes(); Void select(int index); Int itemCount();

Public applet1 extends JApplet { Public void init() { Container cpane=getContentPane(); Cpane.setLayout(null); ListBox lb=new ListBox(5,0); Cpane.add(lb); Jcb.additem(“france”,4); Jcb.additem(“England”); }

SETBOUNDS METHOD This method is used to set the Size and shape of all awt components This method works when we set the layout to null and we want to add the components manually Void setBounds(int x1,int y1,int width,int Height); X1,y1—coordinates where the component has to be placed Width and height –are that of the components

Public applet1 extends JApplet { Public void init() { Container cpane=getContentPane(); Cpane.setLayout(null); JButton b1=new JButton(String str); Jb.setBounds(10,10,50,50); Cpane.add(b1); }

Setting color for components Void setBackground(Color.c); Void setForeground(Color.c); Public applet1 extends JApplet { Public void init() { JButton jb=new JButton(String str); Jb.setBackground(Color.GREEN); Jb.setForeground(Color.BLUE); }