返回列表 發帖
  1. import java.awt.BorderLayout;
  2. import java.awt.EventQueue;

  3. import javax.swing.JFrame;
  4. import javax.swing.JPanel;
  5. import javax.swing.border.EmptyBorder;
  6. import javax.swing.JLabel;
  7. import javax.swing.ImageIcon;
  8. import java.awt.Toolkit;
  9. import java.awt.event.MouseAdapter;
  10. import java.awt.event.MouseEvent;


  11. public class GIFT extends JFrame {

  12.         private JPanel contentPane;

  13.         /**
  14.          * Launch the application.
  15.          */
  16.         public static void main(String[] args) {
  17.                 EventQueue.invokeLater(new Runnable() {
  18.                         public void run() {
  19.                                 try {
  20.                                         GIFT frame = new GIFT();
  21.                                         frame.setVisible(true);
  22.                                 } catch (Exception e) {
  23.                                         e.printStackTrace();
  24.                                 }
  25.                         }
  26.                 });
  27.         }

  28.         /**
  29.          * Create the frame.
  30.          */
  31.         public GIFT() {
  32.                 setIconImage(Toolkit.getDefaultToolkit().getImage("D:\\TEST\\GIFT\\bin\\star.png"));
  33.                 setTitle("\u9EDE\u6309\u6ED1\u9F20\u5207\u63DB\u5716\u5F62");
  34.                 setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  35.                 setBounds(100, 100, 450, 300);
  36.                 contentPane = new JPanel();
  37.                 contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
  38.                 setContentPane(contentPane);
  39.                 contentPane.setLayout(null);
  40.                
  41.                 JLabel gift = new JLabel("");
  42.                 gift.addMouseListener(new MouseAdapter() {
  43.                         @Override
  44.                         public void mouseClicked(MouseEvent e) {
  45.                                 if(e.getButton() == 1)
  46.                                 {
  47.                                         gift.setIcon(new ImageIcon(GIFT.class.getResource("hippo.png")));
  48.                                 }       
  49.                         }
  50.                 });
  51.                
  52.                 gift.setIcon(new ImageIcon(GIFT.class.getResource("gift-green.png")));
  53.                 gift.setBounds(139, 54, 128, 142);
  54.                 contentPane.add(gift);
  55.         }
  56. }
複製代碼

TOP

返回列表