Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

button event

import java.awt.*;// import functions 
import java.awt.event.*;

public class buttonevent extends Frame implements ActionListener {
    int num;
    Button b1;
    TextField t1;

    public buttonevent() {//constructor
        setLayout(new FlowLayout());

        b1 = new Button("click me");//button named "click me" is created.
        t1 = new TextField(20);

        add(b1);//that button is added to the frame by add function.
        add(t1);

        b1.addActionListener(this);

    }

    public void actionPerformed(ActionEvent ae) {//event function
        String cmd = ae.getActionCommand();
        if (num == 0) {
            System.out.println(cmd);
        }
        if (cmd.equals("click me")) {
            num++;
        }
        if ((num % 2) != 0) {
            t1.setText("Hello Buddy!");
        }
        if ((num % 2) == 0) {
            t1.setText(" ");
            System.out.println(num);
        }
    }

    public static void main(String args[]) {//main function
        buttonevent ob = new buttonevent();
        ob.setSize(500, 500);
        ob.setVisible(true);
        ob.setTitle("button Event Handling");
    }
}
Comment

PREVIOUS NEXT
Code Example
Java :: directory size java 
Java :: arraylist remove value in java 
Java :: java division of 2 numbers with decimal places 
Java :: number of matches regex java 
Java :: start an activity in adapter 
Java :: java swing date picker 
Java :: Access HashMap Elements 
Java :: input 3 int 1 line in java 
Java :: java in 5 minutes 
Java :: save text in edditext java 
Java :: ticket sales java program 
Java :: java.lang.NoClassDefFoundError: net/sf/cb2xml/def/IItem 
Sql :: sql disable safe mode 
Sql :: today minus 15 days postgresql 
Sql :: sql find text in sp 
Sql :: oracle get table schema 
Sql :: psql kill pid 
Sql :: put line oracle 
Sql :: rails execute sql 
Sql :: sql add column 
Sql :: mysql convert timestamp to date 
Sql :: sql server check version 
Sql :: mysql copy table with new name 
Sql :: search stored procedures by name 
Sql :: mysql modify foreign key 
Sql :: how to ckeck that email is present in databse in mysqli 
Sql :: mariadb get column names from table 
Sql :: InnoDB: page_cleaner: 1000ms intended loop took 7742ms. The settings might not be optimal 
Sql :: oracle compile schema 
Sql :: sql try catch 
ADD CONTENT
Topic
Content
Source link
Name
9+8 =