AWT TEXTFIELD CLASS. Constructs a new empty text field with the specified number of columns.

Similar documents
AWT LIST CLASS. The List represents a list of text items. The list can be configured to that user can choose either one item or multiple items.

AWT CHOICE CLASS. Choice control is used to show pop up menu of choices. Selected choice is shown on the top of the menu.

AWT CHECKBOX CLASS. Creates a check box with the specified label and sets the specified state.

AWT SCROLLBAR CLASS. Scrollbar control represents a scroll bar component in order to enable user to select from range of values.

AWT DIALOG CLASS. Dialog control represents a top-level window with a title and a border used to take some form of input from the user.

AWT WINDOW CLASS. The class Window is a top level window with no border and no menubar. It uses BorderLayout as default layout manager.

AWT MENUBAR CLASS. Introduction. Class declaration. Class constructors. Class methods

SWING - GROUPLAYOUT CLASS

Laborator 2 Aplicatii Java

AWT COLOR CLASS. Introduction. Class declaration. Field

AWT QUADCURVE2D CLASS

AWT GRAPHICS CLASS. Introduction. Class declaration. Class constructors. Class methods

JRadioButton account_type_radio_button2 = new JRadioButton("Current"); ButtonGroup account_type_button_group = new ButtonGroup();

Where the methods with the Java 1.0 comment are deprecated. The

Java TM 2 Platform Std. Ed. v Overview Package Class Use Tree Deprecated Index Help

กล ม API ท ใช. Programming Graphical User Interface (GUI) Containers and Components 22/05/60

Graphical Interfaces

Graphical Interfaces

Swing from A to Z Some Simple Components. Preface

Java Graphical User Interfaces AWT (Abstract Window Toolkit) & Swing

MIT AITI Swing Event Model Lecture 17

The AWT Package, Placing Components in Containers, CardLayout. Preface. Introduction

Control Flow: Overview CSE3461. An Example of Sequential Control. Control Flow: Revisited. Control Flow Paradigms: Reacting to the User

Example 3-1. Password Validation

Window Interfaces Using Swing Objects

GUI in Java TalentHome Solutions

GUI Program Organization. Sequential vs. Event-driven Programming. Sequential Programming. Outline

CSE 143. Event-driven Programming and Graphical User Interfaces (GUIs) with Swing/AWT

The AWT Event Model 9

Example Programs. COSC 3461 User Interfaces. GUI Program Organization. Outline. DemoHelloWorld.java DemoHelloWorld2.java DemoSwing.

Chapter 1 GUI Applications

Window Interfaces Using Swing Objects

Frames, GUI and events. Introduction to Swing Structure of Frame based applications Graphical User Interface (GUI) Events and event handling

IPM 12/13 P4 Handling Events in AWT

CSE 331. Event-driven Programming and Graphical User Interfaces (GUIs) with Swing/AWT

BM214E Object Oriented Programming Lecture 13

Classes and Objects 3/28/2017. How can multiple methods within a Java class read and write the same variable?

GUAVA - CHARMATCHER CLASS

Programming Languages and Techniques (CIS120e)

Java. GUI building with the AWT

SD Module-1 Advanced JAVA

Queens College, CUNY Department of Computer Science. CS 212 Object-Oriented Programming in Java Practice Exam 2. CS 212 Exam 2 Study Guide

Building a GUI in Java with Swing. CITS1001 extension notes Rachel Cardell-Oliver

SD Module-1 Advanced JAVA. Assignment No. 4

7. Program Frameworks

Java Event Handling -- 1

GUI and its COmponent Textfield, Button & Label. By Iqtidar Ali

CSEN401 Computer Programming Lab. Topics: Graphical User Interface Window Interfaces using Swing

Java & Graphical User Interface II. Wang Yang wyang AT njnet.edu.cn

CONTENTS. Chapter 1 Getting Started with Java SE 6 1. Chapter 2 Exploring Variables, Data Types, Operators and Arrays 13

Dr. Hikmat A. M. AbdelJaber

Table of Contents. Chapter 1 Getting Started with Java SE 7 1. Chapter 2 Exploring Class Members in Java 15. iii. Introduction of Java SE 7...

The Abstract Window Toolkit

Datenbank-Praktikum. Universität zu Lübeck Sommersemester 2006 Lecture: Swing. Ho Ngoc Duc 1

Packages: Putting Classes Together

GUI Forms and Events, Part II

DCS235 Software Engineering Exercise Sheet 2: Introducing GUI Programming

Java - Applications. The following code sets up an application with a drop down menu, as yet the menu does not do anything.

JAVA NOTES GRAPHICAL USER INTERFACES

AP CS Unit 11: Graphics and Events

CS Exam 1 Review Suggestions

Java AWT Windows, Text, & Graphics

GUAVA - RANGE CLASS. Range represents an interval or a sequence. It is used to get a set of numbers/ strings lying in a particular range.

Java for Programmers Course (equivalent to SL 275) 36 Contact Hours

G51PRG: Introduction to Programming Second semester Applets and graphics

Advanced Java Programming

Chapter 13 Lab Advanced GUI Applications

Programming Mobile Devices J2SE GUI

CHAPTER 2. Java Overview

Introduction. Overview of the Course on Java. Overview of Part 1 of the Course

Theory Test 3A. University of Cape Town ~ Department of Computer Science. Computer Science 1016S ~ For Official Use

Building Graphical User Interfaces. Overview

Part 3: Graphical User Interface (GUI) & Java Applets

Overloading Example. Overloading. When to Overload. Overloading Example (cont'd) (class Point continued.)

Building Graphical User Interfaces. GUI Principles

Overview. Building Graphical User Interfaces. GUI Principles. AWT and Swing. Constructing GUIs Interface components GUI layout Event handling

The AWT Package, An Overview

SINGLE EVENT HANDLING

B2.52-R3: INTRODUCTION TO OBJECT ORIENTATED PROGRAMMING THROUGH JAVA

PROGRAMMING DESIGN USING JAVA (ITT 303) Unit 7

Handout 14 Graphical User Interface (GUI) with Swing, Event Handling

Chapter 13 Lab Advanced GUI Applications Lab Objectives. Introduction. Task #1 Creating a Menu with Submenus

(listener)... MouseListener, ActionLister. (adapter)... MouseAdapter, ActionAdapter. java.awt AWT Abstract Window Toolkit GUI

CS11 Java. Fall Lecture 3

index.pdf January 21,

The JFrame Class Frame Windows GRAPHICAL USER INTERFACES. Five steps to displaying a frame: 1) Construct an object of the JFrame class

Programming Language Concepts: Lecture 8

DEMYSTIFYING PROGRAMMING: CHAPTER SIX METHODS (TOC DETAILED) CHAPTER SIX: METHODS 1

Programming Languages and Techniques (CIS120)

ITI Introduction to Computing II

Java - Applets. C&G criteria: 1.2.2, 1.2.3, 1.2.4, 1.3.4, 1.2.4, 1.3.4, 1.3.5, 2.2.5, 2.4.5, 5.1.2, 5.2.1,

OBJECT ORIENTED PROGRAMMING. Java GUI part 1 Loredana STANCIU Room B616

GWT - UIOBJECT CLASS

ITI Introduction to Computing II

GUI Event Handlers (Part I)

LUCENE - BOOLEANQUERY

Swing from A to Z Using Focus in Swing, Part 2. Preface

JAVA NOTES GRAPHICAL USER INTERFACES

All the Swing components start with J. The hierarchy diagram is shown below. JComponent is the base class.

PIC 20A GUI with swing

Transcription:

http://www.tutorialspoint.com/awt/awt_textfield.htm AWT TEXTFIELD CLASS Copyright tutorialspoint.com Introduction The textfield component allows the user to edit single line of text.when the user types a key in the text field the event is sent to the TextField. The key event may be key pressed, Key released or key typed. The key event is passed to the registered KeyListener. It is also possible to for an ActionEvent if the ActionEvent is enabled on the textfield then ActionEvent may be fired by pressing the return key. Class declaration Following is the declaration for java.awt.textfield class: public class TextField extends TextComponent Class constructors S.N. 1 Constructor & Description TextField Constructs a new text field. 2 TextFieldintcolumns Constructs a new empty text field with the specified number of columns. 3 TextFieldStringtext Constructs a new text field initialized with the specified text. 4 TextFieldStringtext, intcolumns Constructs a new text field initialized with the specified text to be displayed, and wide enough to hold the specified number of columns. Class methods S.N. 1 Method & Description void addactionlisteneractionlistenerl Adds the specified action listener to receive action events from this text field. 2 void addnotify Creates the TextField's peer.

3 boolean echocharisset Indicates whether or not this text field has a character set for echoing. 4 AccessibleContext getaccessiblecontext Gets the AccessibleContext associated with this TextField. 5 ActionListener[] getactionlisteners Returns an array of all the action listeners registered on this textfield. 6 int getcolumns Gets the number of columns in this text field. 7 char getechochar Gets the character that is to be used for echoing. 8 <T extends EventListener> T[] getlistenersclass < T > listenertype Returns an array of all the objects currently registered as FooListeners upon this TextField. 9 Dimension getminimumsize Gets the minumum dimensions for this text field. 10 Dimension getminimumsizeintcolumns Gets the minumum dimensions for a text field with the specified number of columns. 11 Dimension getpreferredsize Gets the preferred size of this text field. 12 Dimension getpreferredsizeintcolumns Gets the preferred size of this text field with the specified number of columns. 13 Dimension minimumsize Deprecated. As of JDK version 1.1, replaced by getminimumsize. 14 Dimension minimumsizeintcolumns

Deprecated. As of JDK version 1.1, replaced by getminimumsizeint. 15 protected String paramstring Returns a string representing the state of this TextField. 16 Dimension preferredsize Deprecated. As of JDK version 1.1, replaced by getpreferredsize. 17 Dimension preferredsizeintcolumns Deprecated. As of JDK version 1.1, replaced by getpreferredsizeint. 18 protected void processactioneventactionevente Processes action events occurring on this text field by dispatching them to any registered ActionListener objects. 19 protected void processeventawtevente Processes events on this text field. 20 void removeactionlisteneractionlistenerl Removes the specified action listener so that it no longer receives action events from this text field. 21 void setcolumnsintcolumns Sets the number of columns in this text field. 22 void setechocharcharc Sets the echo character for this text field. 23 void setechocharactercharc Deprecated. As of JDK version 1.1, replaced by setechocharchar. 24 void settextstringt Sets the text that is presented by this text component to be the specified text. Methods inherited This class inherits methods from the following classes:

java.awt.textcomponent java.awt.component java.lang.object TextField Example Create the following java program using any editor of your choice in say D:/ > AWT > com > tutorialspoint > gui > AwtControlDemo.java package com.tutorialspoint.gui; import java.awt.*; import java.awt.event.*; public class AwtControlDemo { private Frame mainframe; private Label headerlabel; private Label statuslabel; private Panel controlpanel; public AwtControlDemo(){ preparegui(); public static void main(string[] args){ AwtControlDemo awtcontroldemo = new AwtControlDemo(); awtcontroldemo.showtextfielddemo(); private void preparegui(){ mainframe = new Frame("Java AWT Examples"); mainframe.setsize(400,400); mainframe.setlayout(new GridLayout(3, 1)); mainframe.addwindowlistener(new WindowAdapter() { public void windowclosing(windowevent windowevent){ System.exit(0); ); headerlabel = new Label(); headerlabel.setalignment(label.center); statuslabel = new Label(); statuslabel.setalignment(label.center); statuslabel.setsize(350,100); controlpanel = new Panel(); controlpanel.setlayout(new FlowLayout()); mainframe.add(headerlabel); mainframe.add(controlpanel); mainframe.add(statuslabel); mainframe.setvisible(true); private void showtextfielddemo(){ headerlabel.settext("control in action: TextField"); Label namelabel= new Label("User ID: ", Label.RIGHT); Label passwordlabel = new Label("Password: ", Label.CENTER); final TextField usertext = new TextField(6); final TextField passwordtext = new TextField(6); passwordtext.setechochar('*'); Button loginbutton = new Button("Login"); loginbutton.addactionlistener(new ActionListener() {

public void actionperformed(actionevent e) { String data = "Username: " + usertext.gettext(); data += ", Password: " + passwordtext.gettext(); statuslabel.settext(data); ); controlpanel.add(namelabel); controlpanel.add(usertext); controlpanel.add(passwordlabel); controlpanel.add(passwordtext); controlpanel.add(loginbutton); mainframe.setvisible(true); Compile the program using command prompt. Go to D:/ > AWT and type the following command. D:\AWT>javac com\tutorialspoint\gui\awtcontroldemo.java If no error comes that means compilation is successful. Run the program using following command. D:\AWT>java com.tutorialspoint.gui.awtcontroldemo Verify the following output Loading [MathJax]/jax/output/HTML-CSS/jax.js