





















Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Community
Ask the community for help and clear up your study doubts
Discover the best universities in your country according to Docsity users
Free resources
Download our free guides on studying techniques, anxiety management strategies, and thesis advice from Docsity tutors
This lecture is delivered by Prem Vikas at Jaypee Institute of Information Technology University for discussing following points of Java Network Programming: Interfaces, Event, Handling, Model, Listener, Techniques, Declaration, Constructor, Runnable
Typology: Slides
1 / 29
This page cannot be seen from the preview
Don't miss anything!
Interfaces..cont..
Cut Copy Paste
Clipboard capacity
public private protected Extends interface EditAble { - - - - -body of interface - - - - - } public interface EditAble{ - - - - body of interface - - - } public interface EditAbleGraphics extends EditAble{- - - -body- - }
Methods are public by default public void cut(); public void paste(); public void copy(); Version- public void cut(int start,int end);
Constants are static and final by default Must be initialized when declared int LIMIT=2;
public class TrafficSignal implements BasicColors{ -----body------- }
package InterfaceTest;
public class TrfficSignal implements BasicColors{ public void changeToRed(){ System.out.println(“The color of the signal is RED”); } public void changeToGreen(){ System.out.println(“The color of the signal is GREEN”); } public void changeToBlue(){ System.out.println(“The color of the signal is BLUE”); } }
Play() Stop() Loop()
Implemented by classes for providing playback functionality
Implemented by the classes that want to become a layout manager
run()
Implemented by any class whose instances are intended to be executed by a thread
When a button of an applet is pressed A button press event object is generated Applet translates the event and try to find some handler in the applet If a handler in the program is found the event is handed over to it If no handler is found the default handler is used
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
public class myApplet extends Applet implements ActionListener{ //class declaration
private Button button1 = new Button();
public void init () {
button1.setText(“Click It");
button1.addActionListener(this); //specifying the action listener
add(button1);
}
//implementing method of ActionListener
public void actionPerformed(ActionEvent event){
System.out.println("The Button is pressed");
} }
Handling events for more than one button
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
public class myApplet extends Applet implements ActionListener{
private Button button1 = new Button();
private Button button2 = new Button();
public void init () {
button1.setText(“Click It");
button1.addActionListener(this);
button2.addActionListener(this);
add(button2);
add(button1); }
//implementing method of ActionListener
public void actionPerformed(ActionEvent event){
System.out.println("The Button is pressed");
} }
Solution-
class button1_listener implements ActionListener{
public void actionPerformed(ActionEvent e){ System.out.println(“Button 1 is pressed “); } }
class button2_listener implements ActionListener{
public void actionPerformed(ActionEvent e){ System.out.println(“Button 2 is pressed “); } }