返回顶部

收藏

java swing打印窗体的位置

更多
package cn.outofmemory.snippets.desktop;

import java.awt.event.ComponentEvent;
import java.awt.event.ComponentListener;

import javax.swing.JFrame;

public class WidowPosition extends JFrame implements ComponentListener {

    public WidowPosition() {

        addComponentListener(this);
        setSize(410, 300);
        setLocationRelativeTo(null);
        setDefaultCloseOperation(EXIT_ON_CLOSE);
        setVisible(true);

    }

    @Override
    public void componentResized(ComponentEvent event) {
    }

    @Override
    public void componentMoved(ComponentEvent event) {

        int x = event.getComponent().getX();
        int y = event.getComponent().getY();
        System.out.println("x: " + x);
        System.out.println("y: " + y);
    }

    @Override
    public void componentShown(ComponentEvent event) {
    }

    @Override
    public void componentHidden(ComponentEvent event) {
    }

    public static void main(String[] args) {
        new WidowPosition();
    }
}

标签:java,swing

收藏

0人收藏

支持

0

反对

0

发表评论