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 } }