让JDialog随JFrame的移动而移动 从一JFrame触发一份JDialog怎么让他随JFrame的移动而移动 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 package com.yyb.model;import java.awt.Dimension;import java.awt.Toolkit;import java.awt.Window;import java.awt.event.ComponentEvent;import java.awt.event.ComponentListener;import javax.swing.JDialog;import javax.swing.JOptionPane;public class GPCDialog extends JDialog implements ComponentListener { private Window god; private Dimension screen=Toolkit.getDefaultToolkit().getScreenSize(); public GPCDialog() { } public GPCDialog(Window god) { setMyGod(god); } public void setMyGod(Window god) { if (this.god != null) { if (this.god.equals(god)) return; else this.god.removeComponentListener(this); } this.god = god; if(god!=null) this.god.addComponentListener(this); } public void componentHidden(ComponentEvent e) { this.setVisible(false); } public void componentMoved(ComponentEvent e) { int godWidth=god.getWidth(); int myX=god.getWidth()+god.getLocationOnScreen().x; if(myX>screen.getWidth()){ myX=god.getLocationOnScreen().x-getWidth(); if(Math.abs(myX)<getWidth()){ JOptionPane.showMessageDialog(god,"跟屁虫说:没有我的容身之处了"); return; } } this.setLocation(myX,god.getLocationOnScreen().y); } public void componentResized(ComponentEvent e) { } public void componentShown(ComponentEvent e) { this.setVisible(true); }}觉得可以给分,觉得不可以自己改下再给分 this.setVisible(..)用不了,晕,回家睡觉了 把事件写在window里面而不是dialog里面应该好些,慢慢琢磨,不要完全用别人的() java工程师应往哪方面发展 jtidy把html转为DOM树,并删除 html 特定标记 JTextPane插入图片的问题 在java中,我怎么取字符串右边的字符,就像right()函数那样??? 一个拗口的问题. 我建立了一个JTree,但如何取点中的对象呢? 在JAVA里生成随机文件名是用什么方法?文件名要永不重复。 【求助】文件拷贝不覆盖源文件/目录 本人无礼,想得到高手们的JAVA编程心得和使用技巧. 如何读取IE缓存的索引文件 数据库连接怎么也不成功? 关于JAVA中String 编码的问题
import java.awt.Toolkit;
import java.awt.Window;
import java.awt.event.ComponentEvent;
import java.awt.event.ComponentListener;import javax.swing.JDialog;
import javax.swing.JOptionPane;public class GPCDialog extends JDialog implements ComponentListener { private Window god;
private Dimension screen=Toolkit.getDefaultToolkit().getScreenSize();
public GPCDialog() { } public GPCDialog(Window god) {
setMyGod(god);
} public void setMyGod(Window god) {
if (this.god != null) {
if (this.god.equals(god))
return;
else
this.god.removeComponentListener(this);
}
this.god = god;
if(god!=null)
this.god.addComponentListener(this);
} public void componentHidden(ComponentEvent e) {
this.setVisible(false);
} public void componentMoved(ComponentEvent e) {
int godWidth=god.getWidth();
int myX=god.getWidth()+god.getLocationOnScreen().x;
if(myX>screen.getWidth()){
myX=god.getLocationOnScreen().x-getWidth();
if(Math.abs(myX)<getWidth()){
JOptionPane.showMessageDialog(god,"跟屁虫说:没有我的容身之处了");
return;
}
}
this.setLocation(myX,god.getLocationOnScreen().y);
} public void componentResized(ComponentEvent e) {
} public void componentShown(ComponentEvent e) {
this.setVisible(true);
}}
觉得可以给分,觉得不可以自己改下再给分