Java Fundamentals (iii)

Source: Internet
Author: User

  • How are you doing
        • Code
    Package Com.lky;import Java.awt.borderlayout;import Java.awt.flowlayout;import java.awt.event.actionevent;import Java.awt.event.actionlistener;import Java.io.ioexception;import Java.util.calendar;import Javax.swing.JButton; Import Javax.swing.jframe;import javax.swing.jlabel;import javax.swing.joptionpane;import Javax.swing.JPanel; public class Closecomputer extends jframe{private JPanel panel_main = new JPanel (New BorderLayout (5, ten));p rivate JPanel p  Anel_subnorth = new JPanel (new FlowLayout (3));p rivate JPanel panel_subcenter = new JPanel (new FlowLayout (1, 5, 5));p rivate JButton countdown = new JButton ("Countdown shutdown");p rivate JButton time = new JButton ("Timed shutdown");p rivate JButton Cancel = new JButton ( "Cancel Shutdown");p rivate JLabel tag; String key;public Closecomputer () {This.getcontentpane (). Add (Panel_main);p Anel_main.add (Panel_subnorth, Borderlayout.north);p Anel_main.add (Panel_subcenter, Borderlayout.center);p anel_subnorth.add (tag = new JLabel (" Please select shutdown mode: "));p Anel_subcenter.add (countdown);p Anel_subcenter.add(time);p Anel_subcenter.add (cancel), Countdown.addactionlistener (New Button1hander ()); Time.addactionlistener (new Button2hander ()); Cancel.addactionlistener (new Button3hander ());} public void time () {Calendar calendar = calendar.getinstance (); int h = calendar.get (calendar.hour); int m = Calendar.get (Ca Lendar. MINUTE); int s = Calendar.get (Calendar.second);//Get current system time//string a = string.valueof (h); int hour, MINUTE, Secord; String hourtmp, minutetmp, secordtmp;hourtmp = Joptionpane.showinputdialog (This, "Please enter the hour of shutdown (12 hours)", "Input", 1); minutetmp = Joptionpane.showinputdialog (This, "Please enter minutes for shutdown", "input", 1); secordtmp = Joptionpane.showinputdialog (This, "Please enter shutdown seconds", "input ", 1); hour = Integer.parseint (hourtmp); minute = Integer.parseint (minutetmp); Secord = Integer.parseint (secordtmp); long Set_time = Timesum (hour, minute, Secord); Long currently_time = Timesum (H, M, s); Long discrepancy_time = Set_time-current Ly_time;if (Discrepancy_time < 0) {try{runtime.getruntime (). EXEC ("Shutdown-s");} catch (IOException e) {E. Printstacktrace ();}} Else{counttimetool.deleytime (Discrepancy_time); Joptionpane.showmessagedialog (This, "Congratulations, set success!", "Confirm", 2);}} Private class Button1hander implements actionlistener{@Overridepublic void actionperformed (ActionEvent arg0) { Countdown ();}} Private class Button2hander implements actionlistener{@Overridepublic void actionperformed (ActionEvent arg0) {time ();}} Private class Button3hander implements actionlistener{@Overridepublic void actionperformed (ActionEvent arg0) {cancel () ;}} public void Countdown () {key = Joptionpane.showinputdialog (This, "Please enter the countdown time to shutdown (seconds)", "Input Box", 1); Counttimetool.deleytime ( Long.parselong (key));} public int timesum (int h, int m, int s) {int sum = h * 3600 + M * + S;return sum;} Calculates the sum of time and returns the public void Cancel () {Try{joptionpane.showmessagedialog (this, "You have successfully canceled the shutdown operation!", "message", 2); Runtime.getruntime (). EXEC ("shutdown-a");} catch (IOException e) {}}public static void main (string[] args) {Closecomputer frame = new Closecomputer (); Frame.setdefaultcloseoperation (JFRAME.EXit_on_close); Frame.pack (); Frame.setsize (), Frame.settitle ("Power off Tool"); Frame.setlocation (350, 350); Frame.setvisible (True); frame.setresizable (false);}}

Java Fundamentals (iii)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.