1. Kết quả Event Ghost 2016


    Dưới đây là danh sách những thành viên đoạt giải thưởng trong Event Ghost 2016

Phần mềm hẹn giờ tắt máy tính bằng java

Thảo luận trong 'Phần Mềm Khác' bắt đầu bởi mr.trung91, 21 Tháng năm 2012.


  1. mr.trung91

    mr.trung91 Member Tích Cực

    239
    210
    43
    [​IMG]

    Cái này đợt làm bài tập lớn môn java mình code bằng Jcreator, post lên cho ae ngịch chơi ;))

    http://www.mediafire.com/?6xtu9216cubhcpx

    Mã:
    package classfile;
    import java.awt.*;
    import java.awt.event.*;
    import java.util.Calendar;
    import javax.swing.Timer;
    @SuppressWarnings("serial")
    public class Demo extends Frame {
    
    	private Label lbTieude, lbMinAfter, lbHour, lbMinAt, lbClock, lbTime;
    	private TextField txMinAfter, txHour, txMinAt;
    	private Button btStart, btExit;
    	private Checkbox chAfter, chAt;
    	private CheckboxGroup g=new CheckboxGroup();
    	private int s, sh, sm, kt1=0;
    	private static String Hour, Min, Sec, sMin, sHour;
    	
    	public Demo(){
    		super("Auto Shutdown - Mr.Trung91");
    
    		Font f=new Font("TimesRoman",Font.BOLD,17);	
    		lbTieude=new Label("AUTO-SHUTDOWN");
    		lbTieude.setFont(new Font("TimesRoman",Font.BOLD,23));
    		lbTieude.setForeground(Color.blue);
    		lbMinAfter=new Label("minute");
    		lbMinAfter.setFont(f);
    		lbHour=new Label("hrs");
    		lbHour.setFont(f);
    		lbMinAt=new Label("minute");
    		lbMinAt.setFont(f);
    		lbClock=new Label();
    		lbClock.setFont(f);
    		lbClock.setForeground(Color.red);
    		lbTime=new Label("waiting...");
    		lbTime.setFont(f);
    		lbTime.setForeground(Color.blue);
    		txMinAfter=new TextField();
    		txMinAfter.setFont(f);
    		//
    		txMinAfter.addActionListener(new ActionListener() {
    			public void actionPerformed(ActionEvent arg0) {
    				Apply();
    			}
    		});
    		txHour=new TextField();
    		txHour.setFont(f);
    		txHour.setEditable(false);
    		//
    		txHour.addActionListener(new ActionListener() {
    			public void actionPerformed(ActionEvent arg0) {
    				Apply();
    			}
    		});
    		txMinAt=new TextField();
    		txMinAt.setFont(f);
    		txMinAt.setEditable(false);
    		//
    		txMinAt.addActionListener(new ActionListener() {
    			public void actionPerformed(ActionEvent arg0) {
    				Apply();
    			}
    		});	
    		chAfter=new Checkbox("After:",g,true);
    		chAfter.setFont(f);
    
    		chAfter.addItemListener(new ItemListener() {
    			public void itemStateChanged(ItemEvent arg0) {
    				txMinAfter.setEditable(true);
    				txHour.setEditable(false);
    				txMinAt.setEditable(false);
    			}
    		});
    
    		chAt=new Checkbox("At:",g,false);
    		chAt.setFont(f);
    		chAt.addItemListener(new ItemListener() {
    			public void itemStateChanged(ItemEvent arg0) {
    				txHour.setEditable(true);
    				txMinAt.setEditable(true);
    				txMinAfter.setEditable(false);
    				txHour.setText(""+Hour);
    				txMinAt.setText(""+Min);
    			}
    		});
    
    		btStart=new Button("Start");
    		btStart.setFont(f);
    		btStart.setForeground(Color.blue);
    		btStart.addActionListener(new ActionListener() {
    			public void actionPerformed(ActionEvent e) {
    				if(kt1==0)
    					Apply();
    				else
    					Stop();
    			}
    		});	
    
    		btExit=new Button("Exit");
    		btExit.setFont(f);
    		btExit.setForeground(Color.red);
    		btExit.addActionListener(new ActionListener() {
    			public void actionPerformed(ActionEvent e) {
    				System.exit(0);
    			}
    		});
    		
    		//Tao panel
    		Panel pan=new Panel();
    		pan.setLayout(null);
    		pan.setBounds(0, 0, getWidth(), getHeight());
    		lbTieude.setBounds(90, 10, 250, 25);
    		pan.add(lbTieude);		
    		chAfter.setBounds(25, 55, 70, 25);
    		pan.add(chAfter);		
    		txMinAfter.setBounds(130, 55, 70, 25);
    		pan.add(txMinAfter);		
    		lbMinAfter.setBounds(205, 55, 60, 25);
    		pan.add(lbMinAfter);		
    		chAt.setBounds(25, 95, 70, 25);
    		pan.add(chAt);		
    		txHour.setBounds(130, 95, 70, 25);
    		pan.add(txHour);		
    		lbHour.setBounds(205, 95, 30, 25);
    		pan.add(lbHour);		
    		txMinAt.setBounds(240, 95, 70, 25);
    		pan.add(txMinAt);		
    		lbMinAt.setBounds(315, 95, 60, 25);
    		pan.add(lbMinAt);		
    		btStart.setBounds(90, 145, 90, 35);
    		pan.add(btStart);
    		btExit.setBounds(210, 145, 90, 35);
    		pan.add(btExit);
    		lbClock.setBounds(15, 190, 150, 25);
    		pan.add(lbClock);
    		lbTime.setBounds(180, 190, 210, 25);
    		pan.add(lbTime);
    		//
    		add(pan);
    		pan.setBackground(Color.LIGHT_GRAY);
    		setSize(400, 270);
    		setVisible(true);
    		setResizable(false);
    		setLocationRelativeTo(null);
    		clock.start();
    
    		addWindowListener(new WindowAdapter(){
    			public void windowClosing(WindowEvent e){
    				System.exit(0);
    			}
    		});
    	}
    	//
    		public void Apply(){
    			if(g.getSelectedCheckbox()==chAfter){
    				try{
    					s=Integer.parseInt(txMinAfter.getText())*60;
    					t.start();
    				}catch(Exception e){
    					new Dia("Shutdown After","Loi du lieu! Ban phai nhap 1 so");
    				}
    			}else{
    				try{
    					sHour=txHour.getText(); sh=Integer.parseInt(sHour);
    					sMin=txMinAt.getText(); sm=Integer.parseInt(sMin);
    					if(sh<24&sh>-1&sm>-1&sm<60){
    						t3.start();
    						lbTime.setText("Shutdown at: "+sHour+":"+sMin+" min");
    					}else
    						new Dia("Shutdown At","Loi du lieu! Thoi gian khong dung");
    				}catch(Exception e){
    					new Dia("Shutdown At","Loi du lieu! Ban phai nhap vao 1 so");
    				}
    			}	
    		}
    		//
    		public void Stop(){
    			t.stop(); t3.stop(); kt1=0;
    			btStart.setLabel("Start");
    			btStart.setForeground(Color.blue);
    			lbTime.setText("Setting was be canceled!");
    		}
    		//Timer
    		Timer t=new Timer(1000, new ActionListener() {	
    			public void actionPerformed(ActionEvent e) {
    				if(s!=0){	
    					if(s>0){
    						s--; kt1=1;
    						btStart.setLabel("Cancel");
    						btStart.setForeground(Color.red);
    						lbTime.setText("Shutdown after: "+s+" sec");
    					}else{
    						t.stop();
    						new Dia("Shutdown After","Loi du lieu! So phut phai >= 0");
    					}
    				}else{
    					try{
    						Runtime.getRuntime().exec("Shutdown -s -t 0");
    					}catch (Exception e1) {
    						e1.printStackTrace();
    					}
    				}
    			}
    		});
    		Timer clock=new Timer(1000, new ActionListener() {
    			public void actionPerformed(ActionEvent e) {
    				Dates();
    				lbClock.setText(Hour+":"+Min+":"+Sec);
    			}
    		});
    		Timer t3=new Timer(1000, new ActionListener() {
    			public void actionPerformed(ActionEvent e) {
    				Dates(); kt1=1;
    				btStart.setLabel("Cancel");
    				btStart.setForeground(Color.red);
    				try{
    					if(Hour.equals(sHour)&Min.equals(sMin))
    						Runtime.getRuntime().exec("Shutdown -s -t 0");
    				}catch(Exception e1){
    					e1.printStackTrace();
    				}
    			}
    		});
    		public static void Dates(){
    			Calendar now= Calendar.getInstance();
    			Hour=Integer.toString(now.get(Calendar.HOUR_OF_DAY));
    			Min=Integer.toString(now.get(Calendar.MINUTE));
    			Sec=Integer.toString(now.get(Calendar.SECOND));
    		}
    	//Main
    	@SuppressWarnings("unused")
    	public static void main(String[] args) {
    		Demo d=new Demo();
    	}
    	
    	public class Dia extends Frame{
    		private Button btOK;
    		private Panel pal, pal1;
    		private Label lbl;
    		public Dia(String title, String tb){
    			super(title);
    			btOK=new Button("  OK  ");
    			btOK.setFont(new Font("TimesRoman",Font.BOLD,15));
    			btOK.setForeground(Color.BLUE);
    			btOK.addActionListener(new ActionListener(){
    				public void actionPerformed(ActionEvent agr1){
    					setVisible(false);
    				}
    			});
    			lbl=new Label(tb);
    			lbl.setFont(new Font("TimesRoman",Font.BOLD,15));
    			pal=new Panel();
    			pal.add(lbl);
    			pal1=new Panel();
    			pal1.add(btOK);
    			
    			add(pal,BorderLayout.NORTH);
    			add(pal1,BorderLayout.CENTER);
    			setBackground(Color.LIGHT_GRAY);
    			setVisible(true);
    			pack();
    			setLocationRelativeTo(null);
    			setResizable(false);
    			addWindowListener(new WindowAdapter(){
    			public void windowClosing(WindowEvent e){
    				setVisible(false);
    			}
    			});
    		}
    	}
    }
     

Chia sẻ trang này