Emon766

Clicked And UnClicked

Sep 23rd, 2021 (edited)
933
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package swingdemo.Video3;
  2.  
  3. import java.awt.Checkbox;
  4. import java.awt.FlowLayout;
  5. import java.awt.Frame;
  6. import java.awt.Label;
  7. import java.awt.TextField;
  8. import java.awt.event.ItemEvent;
  9. import java.awt.event.ItemListener;
  10. import java.awt.event.WindowEvent;
  11. import java.awt.event.WindowListener;
  12.  
  13. public class FrameWindow2 extends Frame implements WindowListener,ItemListener
  14.  
  15.  
  16. {
  17.     TextField tx1;
  18.    
  19.  
  20.     public FrameWindow2() {
  21.  
  22.         setLayout(new FlowLayout());
  23.         setSize(370, 170);
  24.         addWindowListener(this);      
  25.         setVisible(true);
  26.        
  27.  
  28.        
  29.       tx1 = new TextField(40);
  30.      
  31.       Checkbox chk1 = new Checkbox();
  32.    
  33.         add(chk1);
  34.        
  35.         add(tx1);
  36.        
  37.         chk1.addItemListener(this);
  38.      
  39.     }
  40.  
  41.       @Override
  42.     public void itemStateChanged(ItemEvent e) {
  43.         Checkbox Click1 = (Checkbox) e.getItemSelectable();
  44.    
  45.           if (e.getStateChange()== ItemEvent.SELECTED) {
  46.              
  47.               tx1.setText("Clicked");
  48.           }
  49.            else
  50.               tx1.setText("Un-Clicked");
  51.    
  52.     }
  53.    
  54.  
  55.     @Override
  56.     public void windowOpened(WindowEvent we) {
  57.     }
  58.  
  59.     @Override
  60.     public void windowClosing(WindowEvent we) {
  61.      System.exit(0);
  62.     }
  63.  
  64.     @Override
  65.     public void windowClosed(WindowEvent we) {
  66.         this.dispose();
  67.     }
  68.  
  69.     @Override
  70.     public void windowIconified(WindowEvent we) {
  71.     }
  72.  
  73.     @Override
  74.     public void windowDeiconified(WindowEvent we) {
  75.     }
  76.  
  77.     @Override
  78.     public void windowActivated(WindowEvent we) {
  79.     }
  80.  
  81.     @Override
  82.     public void windowDeactivated(WindowEvent we) {
  83.      
  84.     }
  85.  
  86.    
  87.     public static void main(String[] args) {
  88.         FrameWindow2 f = new FrameWindow2();
  89.     }
  90.    
  91. }
  92.  
RAW Paste Data