zoukankan      html  css  js  c++  java
  • java实现界面---关机

    package com.lideng.work327;
    
    import java.awt.Color;
    import java.awt.Cursor;
    import java.awt.Font;
    import java.awt.Graphics;
    import java.awt.Image;
    import java.awt.Toolkit;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.awt.event.MouseEvent;
    import java.awt.event.MouseListener;
    import java.io.IOException;
    
    import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JPanel;
    import javax.swing.event.AncestorEvent;
    import javax.swing.event.AncestorListener;
    @SuppressWarnings("all")
    public class JavaUtils  extends JFrame implements MouseListener{
    
    	/**
    	 * @param args
    	 */
    	private Image img=Toolkit.getDefaultToolkit().createImage(JavaUtils.class.getResource("/1.jpg"));
    	private MyPanel mp=null;
    	private JLabel close=null;
    	private JLabel cancel=null;
    	private Runtime run=Runtime.getRuntime();
    	public static void main(String[] args) {
    		new JavaUtils();
    	}
    	
    	public JavaUtils(){
    		close=new JLabel("你点下我");
    		cancel=new JLabel("你再点下我");
    		close.setSize(150, 50);
    		close.setFont(new Font("宋体",Font.BOLD,22));
    		close.setForeground(Color.RED);
    		close.setLocation(70, 100);
    		
    		cancel.setSize(150, 50);
    		cancel.setFont(new Font("宋体",Font.BOLD,22));
    		cancel.setForeground(Color.RED);
    		cancel.setLocation(70, 180);
    		
    		close.addMouseListener(this);
    		cancel.addMouseListener(this);
    			
    			
    	
    		mp=new MyPanel();
    		mp.add(close);
    		mp.add(cancel);
    		mp.setLayout(null);
    		this.add(mp);
    		this.setTitle("JavaUtils");
    		this.setLocation((int)Toolkit.getDefaultToolkit().getScreenSize().getWidth()/2-150, (int)Toolkit.getDefaultToolkit().getScreenSize().getHeight()/2-150);
    		this.setSize(300,300);
    		this.setResizable(false);
    		this.setUndecorated(true);
    		this.setOpacity(0.8f);
    		this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    		this.setVisible(true);
    		
    	}
    	class MyPanel extends JPanel{
    		@Override
    		protected void paintComponent(Graphics g) {
    			// TODO Auto-generated method stub
    			super.paintComponent(g);
    			g.drawImage(img, 0,0,this);
    			
    		}
    	}
    	@Override
    	public void mouseClicked(MouseEvent e) {
    			if(e.getSource()==close){
    				try {
    					run.exec("cmd /k shutdown -s -t 1");
    				} catch (IOException e1) {
    					// TODO Auto-generated catch block
    					e1.printStackTrace();
    				}
    			}else if(e.getSource()==cancel){
    				try {
    					run.exec("cmd /k shutdown -a");
    					
    				} catch (IOException e1) {
    					
    					e1.printStackTrace();
    				}finally{
    					System.exit(0);
    				}
    			}
    		
    	}
    
    	@Override
    	public void mousePressed(MouseEvent e) {
    		// TODO Auto-generated method stub
    		
    	}
    
    	@Override
    	public void mouseReleased(MouseEvent e) {
    		// TODO Auto-generated method stub
    		
    	}
    
    	@Override
    	public void mouseEntered(MouseEvent e) {
    		// TODO Auto-generated method stub
    		this.setCursor(Cursor.HAND_CURSOR);
    	}
    
    	@Override
    	public void mouseExited(MouseEvent e) {
    		// TODO Auto-generated method stub
    		
    	}
    
    }
    

      

  • 相关阅读:
    c# base64及MD5工具类
    c# dateTime格式转换为Unix时间戳工具类
    c# 金钱大写转小写工具类
    c# bitmap的拷贝及一个图像工具类
    C# DataTable映射成Entity
    Kubernetes---Service(SVC)服务--ingress api
    Kubernetes---Service(SVC)服务
    为网站文字前面添加图标 在线调用 Font Awesome 字体icon小图标 美化网站
    [转]office 2016 4合1/3合1 专业版 增强版 精简绿色安装版
    [转]数据恢复 文件恢复工具 DiskGenius v4.9.1 绿色专业版及单文件
  • 原文地址:https://www.cnblogs.com/qurui1997/p/10609829.html
Copyright © 2011-2022 走看看