GK SCIENTIST

General Knowledge One Stop Source
Menu
  • Home
  • Social Science
    • History
    • Political Science
    • Geography
  • Science
    • Physics
    • Chemistry
    • Biology
  • Chemistry Notes
  • Mathematics
  • Computer
  • Tutorial MySQL
  • Tutorial Python
  • Java Tutorial
  • English Grammar
  • English Essay
  • Indian Anthropology
  • Philosophy
  • Solved Paper
  • UPSC
  • Current Content
    • Current Affairs
    • RSTV News
    • Yojana and Kurukshetra Gist
  • Donate
  • Contact Us

If you are interested in advertising to our audience, submit the advertising enquiry form.

Advertising Enquiry
Computer

Java TextField

Gk Scientist January 20, 2023 No Comments
Tweet WhatsApp Telegram

Java TextField:

We can use the Eclipse IDE for this example. If you do not know about it then follow this link- How to Install Eclipse For Java and create a program in it.

Java TextField control creates a single-line text area. The TextField allows the user to enter and edit the text using cut, copy and paste keys, arrow keys, and mouse selections. It is an object of JTextField class which is a subclass of JTextComponent.

Some of the constructors defined by JTextField class are as follows-

  • JTextField( )
  • JTextField(int cols)
  • JTextField(String string, int cols)
  • JTextField(String string)

Where string is the initial string contained in the TextField and cols is the width of the TextField in terms of columns.

Sample Code for Java TextField:

Java TextField Code 1 - Java TextField
Java TextField Code 2 - Java TextField

Output:

Java TextField Output - Java TextField
import java.awt.Color;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JTextField;

public class Textfield extends JFrame implements ActionListener{
	
	JButton button;
	JTextField textField;
	
	Textfield(){
		this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		this.setLayout(new FlowLayout());
		
		button = new JButton("Submit");
		button.addActionListener(this);
		
		textField = new JTextField();
		textField.setPreferredSize(new Dimension(270,60));
		textField.setFont(new Font("Roboto",Font.PLAIN,25));
		textField.setForeground(new Color(0x00FF00));
		textField.setBackground(Color.black);
		textField.setCaretColor(Color.white);
		textField.setText("Type Your Text Here...");
		
		
		this.add(button);
		this.add(textField);
		this.pack();
		this.setVisible(true);
	}
	
	
	@Override
	public void actionPerformed(ActionEvent e) {
		if(e.getSource()==button) {
			System.out.println("You have Typed:- "+ textField.getText());
			
		}
		
	}

	public static void main(String[] args) {
		// TODO Auto-generated method stub

		new Textfield();
		
	}

}

Basic Components of Computer System
Computer Input Devices
Computer Output Devices
Computer Memory
Secondary Storage Devices
Characteristics of Computer
Applications of Computer
Java (programming language)– Wikipedia
Prev Article
Next Article

Related Articles

Python GUI Calculator Project
Python GUI Calculator Project: We can use the PyCharm code …
Gk Scientist December 25, 2022 Computer

Python GUI Calculator Project

MySQL Left Join and Right Join
MySQL Left Join: MySQL Left Join clause allows you to …
Gk Scientist November 17, 2022 Computer

MySQL Left Join and Right Join

MySQL Select Query with Where Clause
MySQL Select Query with Where Clause: (1) In the previous …
Gk Scientist November 11, 2022 Computer

MySQL Select Query with Where Clause

How to Create Variables in Python
Create Variables in Python: We can use the PyCharm code …
Gk Scientist November 21, 2022 Computer

How to Create Variables in Python

Tokens in C++
Tokens in C++ Tokens may be defined as the smallest …
Gk Scientist September 12, 2022 Computer

Tokens in C++

Python Dice Roll Simulator Project
Python Dice Roll Simulator: We can use the PyCharm code …
Gk Scientist December 21, 2022 Computer

Python Dice Roll Simulator Project

Python While Loop
Python While Loop: We can use the PyCharm code editor …
Gk Scientist November 24, 2022 Computer

Python While Loop

String Iteration in Python
String Iteration in Python: We can use the PyCharm code …
Gk Scientist November 25, 2022 Computer

String Iteration in Python

Leave a Reply Cancel Reply

Search




  • Popular
  • Recent




GK SCIENTIST

General Knowledge One Stop Source

Information

  • About Us
  • Terms and Condition, Disclaimer
  • Contact Us

Android Apps

  • IAS App For English Medium Students
  • IAS Basics App For English Medium Students
  • IAS Hindi App For Hindi Medium Students
DMCA.com Protection Status

Popular Tags

Biology (33) Biology Questions (88) Chemistry (57) Computer (213) Current Affairs (4) Current Content (0) Economy (10) English Essay (172) English Grammar (75) English Literature (10) Geography (83) History (259) Indian Anthropology (11) Indian Polity (14) JKAS Mains Question Papers (17) Mathematics (68) Moral Science (7) NCERT & Other Boards Books (25) Philosophy (114) Physics (89) Political Science (132) RS TV News (33) Science (553) Social Anthropology (7) Social Science (17) Solved Paper (47) UPSC (7) UPSC Mains Question Papers (26)

Downloads

  • NCERT Books
  • Old NCERT Books
  • NIOS Books For IAS, SSC, and State PSC Exam
  • Tamil Nadu Board Books: Important For UPSC, SSC, and State PSC Exam
  • Modern Indian and World History Notes For IAS Exam
  • UPSC Topper 2013 Gaurav Agrawal Notes For IAS Preparation
  • UPSC IAS Prelims General Studies – Previous Year Papers
  • UPSC Mains Question Papers

Copyright © 2023 GK SCIENTIST
Theme by MyThemeShop.com& Hosted On Cloudways

Ad Blocker Detected

Our website is made possible by displaying online advertisements to our visitors. Please consider supporting us by disabling your ad blocker.

Refresh
 

Loading Comments...