Java ( Otomatik Kapanmaya Örnek )
import java.awt.*;
import java.awt.event.*;
public class otokapama extends Frame implements ActionListener,ItemListener
{
private Checkbox cb1,cb2,cb3,cb4,cb5,otokapama;
private Button btn1,btn2,btn3;
Choice sure;
private int zmn=0;
private int kapanmazamani=15;//kaç sniye işlem yapmazsan otomatik kapanmanın gerçekleşeceği
private int otoKapatDurum=1;//1 yaparsan otomatik olarak kapa aktif 0 yaparsan diaktif olur
Robot robot;
Label lab1,lab2;
public otokapama()
{
try
{
System.out.println ("otokapat basladi");
setLayout(new FlowLayout());
cb1=new Checkbox("mr",false);
cb2=new Checkbox("mrs",false);
cb3=new Checkbox("miss",false);
cb4=new Checkbox("married",false);
cb5=new Checkbox("single",false);
otokapama=new Checkbox("Otokapama",true);
sure=new Choice();
lab1=new Label("Islem yapmazsanız programınız");
lab2=new Label("sn sonra kapanıcak");
sure.add("15");
sure.add("30");
sure.add("45");
sure.add("60");
Robot robot=new Robot();
System.out.println ("robot olusturuldu");
btn1= new Button("Temizle");
btn2= new Button("Doldur");
btn3= new Button("Degiştir");
add(cb1);
add(cb2);
add(cb3);
add(cb4);
add(cb5);
add(btn1);
add(btn2);
add(btn3);
add(otokapama);
add(lab1);
add(sure);
add(lab2);
setSize(300,300);
setVisible(true);
while(zmn<kapanmazamani)
{
cb1.addItemListener(this);
cb2.addItemListener(this);
cb3.addItemListener(this);
cb4.addItemListener(this);
cb5.addItemListener(this);
btn1.addActionListener(this);
btn2.addActionListener(this);
btn3.addActionListener(this);
otokapama.addItemListener(this);
sure.addItemListener(this);
robot.delay(1000);
zmn++;
System.out.println ("zmn bir arttirildi,durumu="+zmn);
setTitle(""+zmn);
if(zmn==kapanmazamani&& otoKapatDurum==1)
{
System.exit(0);
}
if(zmn==kapanmazamani&& otoKapatDurum==0)
{
zmn=0;
}
}
}
catch(Exception ex)
{
}
}
public void actionPerformed(ActionEvent ae)
{
if(ae.getActionCommand()=="Temizle")
{
cb1.setState(false);
cb2.setState(false);
cb3.setState(false);
cb4.setState(false);
cb5.setState(false);
zmn=0;
}
if(ae.getActionCommand()=="Doldur")
{
cb1.setState(true);
cb2.setState(true);
cb3.setState(true);
cb4.setState(true);
cb5.setState(true);
zmn=0;
}
if(ae.getActionCommand()=="Degiştir")
{
cb1.setState(!cb1.getState());
cb2.setState(!cb2.getState());
cb3.setState(!cb3.getState());
cb4.setState(!cb4.getState());
cb5.setState(!cb5.getState());
zmn=0;
}
}
public void itemStateChanged(ItemEvent ie)
{
zmn=0;
if(ie.getSource()==otokapama)
{
if(otokapama.getState())
{
otoKapatDurum=1;
System.out.println ("otokapama acildi");
lab1.setVisible(true);
sure.setVisible(true);
lab2.setVisible(true);
}
else
{
otoKapatDurum=0;
System.out.println ("otokapama kapatildi");
lab1.setVisible(false);
sure.setVisible(false);
lab2.setVisible(false);
}
}
if(ie.getSource()==sure)
{
if(sure.getSelectedItem()=="15")
{
kapanmazamani=15;
}
else if(sure.getSelectedItem()=="30")
{
kapanmazamani=30;
}
else if(sure.getSelectedItem()=="45")
{
kapanmazamani=45;
}
else
{
kapanmazamani=60;
}
System.out.println ("kapanma zamani degisti="+kapanmazamani);
zmn=0;
}
}
public static void main(String er[])
{
new otokapama();
}
}