6.2 JTextField JTextField is used for taking input of single line of text. It is most widely used text component. It has three constructors,
|
JTextField(int cols) JTextField(String str, int cols) JTextField(String str) |
xample using JTextField
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
|
import javax.swing.*; import java.awt.event.*; import java.awt.*; public class MyTextField extends JFrame { public MyTextField() { JTextField jtf = new JTextField(20); //creating JTextField. add(jtf); //adding JTextField to frame. setLayout(new FlowLayout()); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setSize(400, 400); setVisible(true); } public static void main(String[] args) { new MyTextField(); } } |
6.3 JButton JButton class provides functionality of a button. JButton class has three constuctors,
|
JButton(Icon ic) JButton(String str) JButton(String str, Icon ic) |
It allows a button to be created using icon, a string or […]
Continue Reading