Search Your Topic

config
Thursday, 25 May 2017 06:20

JApplet class in Applet

Written by
Rate this item
(0 votes)
As we prefer Swing to AWT. Now we can use JApplet that can have all the controls of swing. The JApplet class extends the Applet class.

Example of EventHandling in JApplet:

 
  1. import java.applet.*;  
  2. import javax.swing.*;  
  3. import java.awt.event.*;  
  4. public class EventJApplet extends JApplet implements ActionListener{  
  5. JButton b;  
  6. JTextField tf;  
  7. public void init(){  
  8.   
  9. tf=new JTextField();  
  10. tf.setBounds(30,40,150,20);  
  11.   
  12. b=new JButton("Click");  
  13. b.setBounds(80,150,70,40);  
  14.   
  15. add(b);add(tf);  
  16. b.addActionListener(this);  
  17.   
  18. setLayout(null);  
  19. }  
  20.   
  21. public void actionPerformed(ActionEvent e){  
  22. tf.setText("Welcome");  
  23. }  
  24. }  
In the above example, we have created all the controls in init() method because it is invoked only once.

myapplet.html

 

 
  1. <html>  
  2. <body>  
  3. <applet code="EventJApplet.class" width="300" height="300">  
  4. </applet>  
  5. </body>  
  6. </html>  
Read 237 times
Anish Sir

"I am delighted once again to pen the welcome note to the Tosh!Yas Technologies ."

 Call +91 74 88 34 7779  | Email : anishsingh@live.com

toshiyas.in

Leave a comment

Make sure you enter all the required information, indicated by an asterisk (*). HTML code is not allowed.

Facebook