Showing posts with label Event Handling. Show all posts
Showing posts with label Event Handling. Show all posts

Wednesday, October 24, 2012

Login using applet class and ActionListener interface


You can see all event methods in java.awt.Event class
and java.awt.event.ActionListener is an Interface that includes method named actionPerformed and takes ActionEvent as an argument.



Step 1:Create a java source file with name Login.java that is name of java class and it is mandatory that class-name and file-name must be same.
Applet class must be public.

In java source file commented applet code will not be compile by java compiler but will executed by AppletViewer.
In command addActionListener(this) "this" keyword refers as object of current class. we can also write "new Login()" at place of "this" keyword.
setEchoChar() is a method that makes password hidden.



Step 2: Run cmd(command prompt) and compile java source file, Login.class file'll be build.

then give appletviewer command and applet will pop out.

output: when you click on login then related output will display on console.

 

Sunday, October 21, 2012

Event handling using applet class and FocusListener interface


You can see all event methods in java.awt.Event class and java.awt.event.FocusListener is an Interface that includes methods named focusGained() and focusLost() and both takes FocusEvent as an argument.
javap java.awt.event.FocusListener(type over command prompt)

echo %path%(type over command prompt to check path)


Step 1:Create a java source file with name SecondEvent.java that is name of java class and it is mandatory that class name and file name must be same.

Applet class must be public.

In java source file commented applet code will not be compile by java compiler but will executed by AppletViewer.
In command addFocusListener(this) "this" keyword refers as object of current class. we can also write "new SecondEvent()" at place of "this" keyword.

Step 2: Run cmd(command prompt) and compile java source file, SecondEvent.class file'll be build.

then give appletviewer command and applet will pop out.


Download Code Link 1
Download Code Link 2

output:
Focus Gained
Focus Lost

Event handling using applet class and ActionListener interface


You can see all event methods in java.awt.Event class and java.awt.event.ActionListener is an Interface that includes method named actionPerformed and takes ActionEvent as an argument.
javap java.awt.event.ActionListener(type over command prompt)



Step 1:Create a java source file with name FirstEvent.java that is name of java class and it is mandatory that class-name and file name must be same.

Applet class must be public.

In java source file commented applet code will not be compile by java compiler but will executed by AppletViewer.
In command addActionListener(this) "this" keyword refers as object of current class. we can also write "new FirstEvent()" at place of "this" keyword.


Step 2: Run cmd(command prompt) and compile java source file, FirstEvent.class file'll be build.

then give appletviewer command and applet will pop out.
Download Code Link 1
Download Code Link 2
output: click first and second button

Popular Posts