- package bbs.istak.org.tw;
- import java.awt.BorderLayout;
- import java.awt.EventQueue;
- import java.awt.Image;
- import javax.swing.ImageIcon;
- import javax.swing.JFrame;
- import javax.swing.JPanel;
- import javax.swing.border.EmptyBorder;
- import javax.swing.JLabel;
- import java.awt.event.MouseAdapter;
- import java.awt.event.MouseEvent;
- public class Amove extends JFrame {
- private JPanel contentPane;
- private ImageIcon icon;
- /**
- * Launch the application.
- */
- public static void main(String[] args) {
- EventQueue.invokeLater(new Runnable() {
- public void run() {
- try {
- Amove frame = new Amove();
- frame.setVisible(true);
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- });
- }
- /**
- * Create the frame.
- */
- public Amove() {
-
-
- icon = new ImageIcon(crocodile.class.getResource("A-icon.png"));
- Image img = icon.getImage().getScaledInstance(32,32,java.awt.Image.SCALE_FAST );
- ImageIcon newicon = new ImageIcon(img);
-
- setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- setBounds(100, 100, 450, 300);
- contentPane = new JPanel();
- contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
- setContentPane(contentPane);
- contentPane.setLayout(null);
-
- JLabel Alabel = new JLabel(newicon);
- Alabel.setBounds(144, 70, 32, 32);
- contentPane.add(Alabel);
-
- addMouseListener(new MouseAdapter() {
- @Override
- public void mousePressed(MouseEvent arg0) {
- int x = arg0.getX();
- int y = arg0.getY();
- Alabel.setLocation(x, y);
- }
- });
- }
- }
複製代碼 |