Java AWT Button

Java AWT Button

The button class is used to create a labeled button that has a platform-independent implementation. The application results in some action when the button is pushed.

AWT Button Class declaration

  1. public class Button extends Component implements Accessible

Java AWT Button Example

  1. import java.awt.*;
  2. public class ButtonExample {
  3. public static void main(String[] args) {
  4.     Frame f=new Frame(“Button Example”);
  5.     Button b=new Button(“Click Here”);
  6.     b.setBounds(50,100,80,30);
  7.     f.add(b);
  8.     f.setSize(400,400);
  9.     f.setLayout(null);
  10.     f.setVisible(true);
  11. }
  12. }

Output:

java awt button example 1


 

Java AWT Button Example with ActionListener

  1. import java.awt.*;
  2. import java.awt.event.*;
  3. public class ButtonExample {
  4. public static void main(String[] args) {
  5.     Frame f=new Frame(“Button Example”);
  6.     final TextField tf=new TextField();
  7.     tf.setBounds(50,50150,20);
  8.     Button b=new Button(“Click Here”);
  9.     b.setBounds(50,100,60,30);
  10.     b.addActionListener(new ActionListener(){
  11.     public void actionPerformed(ActionEvent e){
  12.             tf.setText(“Welcome to Javatpoint.”);
  13.         }
  14.     });
  15.     f.add(b);f.add(tf);
  16.     f.setSize(400,400);
  17.     f.setLayout(null);
  18.     f.setVisible(true);
  19. }
  20. }

Output:

java awt button example 2

java for beginners
java for beginners
java for beginners
CodSir //course // books
...

WikiSir

Java AWT Button The button class is used to create a labeled button that has a platform-independent implementation. The application results in some action when the button is pushed. AWT Button Class declaration public class Button extends Component implements Accessible Java AWT Button Example import java.awt.*; public class ButtonExample { public static void main(String[] args) {     Frame f=new Frame(“Button Example”);     Button b=new Button(“Click Here”);     b.setBounds(50,100,80,30);     f.add(b);     f.setSize(400,400);     f.setLayout(null);     f.setVisible(true); } } Output:   Java AWT Button […]

Tags:

....
...