Java Jbutton Example With Actionlistener: "Button Exampl E" "Click Here"
Java Jbutton Example With Actionlistener: "Button Exampl E" "Click Here"
1. import java.awt.event.*;
2. import javax.swing.*;
3. public class ButtonExample {
4. public static void main(String[] args) { JFrame f=new JFrame("Button Exampl
e");
5. final JTextField tf=new JTextField(); tf.setBounds(50,50, 150,20);
6. JButton b=new JButton("Click Here"); b.setBounds(50,100,95,30);
7. b.addActionListener(new ActionListener(){
8. public void actionPerformed(ActionEvent e){
9. tf.setText("Welcome to Javatpoint.");
10. }
11. });
12. f.add(b);f.add(tf); f.setSize(400,400);
13. f.setLayout(null); f.setVisible(true);
14. } }
Output:
1
Java JTextField Example
1. import javax.swing.*;
2. class TextFieldExample
3. {
4. public static void main(String args[])
5. {
6. JFrame f= new JFrame("TextField Example");
7. JTextField t1,t2;
8. t1=new JTextField("Welcome to Javatpoint.");
9. t1.setBounds(50,100, 200,30);
10. t2=new JTextField("AWT Tutorial");
11. t2.setBounds(50,150, 200,30);
12. f.add(t1); f.add(t2);
13. f.setSize(400,400);
14. f.setLayout(null);
15. f.setVisible(true);
16. }
17. }
Output:
2
32. { new TextFieldExample();
33. } }