本帖最後由 張健勳 於 2018-3-4 22:22 編輯
- package bbs.istak.org.tw;
- import java.awt.BorderLayout;
- import java.awt.EventQueue;
- import javax.swing.JFrame;
- import javax.swing.JPanel;
- import javax.swing.border.EmptyBorder;
- import javax.swing.JLabel;
- import java.awt.Toolkit;
- import javax.swing.ImageIcon;
- import java.awt.event.MouseAdapter;
- import java.awt.event.MouseEvent;
- public class Main extends JFrame {
- private JPanel contentPane;
- private int x,y;
- /**
- * Launch the application.
- */
- public static void main(String[] args) {
- EventQueue.invokeLater(new Runnable() {
- public void run() {
- try {
- Main frame = new Main();
- frame.setVisible(true);
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- });
- }
- /**
- * Create the frame.
- */
- public Main() {
- setIconImage(Toolkit.getDefaultToolkit().getImage(Main.class.getResource("icon.png")));
- setTitle("\u6ED1\u9F20\u6307\u6A19\u727D\u5F15\u5716\u6848");
- 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 lb = new JLabel("");
-
-
- addMouseListener(new MouseAdapter() {
- @Override
- public void mouseClicked(MouseEvent a) {
- x = a.getX();
- y = a.getY();
-
-
- lb.setLocation(x,y);
-
- }
- });
-
-
- lb.setIcon(new ImageIcon(Main.class.getResource("icon.png")));
- lb.setBounds(10, 10, 89, 79);
- contentPane.add(lb);
- }
- }
複製代碼 |