如何获得父Frame?

angus203 2008-03-22 08:01:29
为什么弹出的frame 没有呎寸..?
什么原因?

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class t2 extends JPanel {

JButton button ;

public t2() {
button = new JButton("Open");
setLayout(new FlowLayout());
add(button);

button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
dialog dlog = new dialog(new Frame(), true);
}
});
}

private static void createAndShowGUI() {

JFrame frame = new JFrame("TimeTabling System");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

JComponent newContentPane = new t2();
newContentPane.setOpaque(true);
frame.setContentPane(newContentPane);

frame.pack();
frame.setVisible(true);
}

public static void main(String[] args) {

javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
createAndShowGUI();
}
});
}
}

class dialog extends JDialog{

JButton OKBtn, CancelBtn;

public dialog(Frame parent, boolean modal){
super(parent, modal);
setLayout(new FlowLayout());
OKBtn = new JButton("OK");
CancelBtn = new JButton("CancelBtn");
add(OKBtn);
add(CancelBtn);
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
setVisible(true);
pack();

}

}
...全文
149 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
angus203 2008-03-22
  • 打赏
  • 举报
回复
为什么没有跟着 main frame 弹出???

dialog dlog = new dialog(new Frame(), true);
dlog.setLocationRelativeTo(this);
angus203 2008-03-22
  • 打赏
  • 举报
回复
为什么没有跟着 main frame 弹出???

dialog dlog = new dialog(new Frame(), true);
dlog .addSendObjectListen(this);
angus203 2008-03-22
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 dracularking 的回复:]
dialog构造方法中在setVisible句前加setSize句
默认是0
[/Quote]


原来先后次序问题, 以前也不以为然
谢谢
dracularking 2008-03-22
  • 打赏
  • 举报
回复
dialog构造方法中在setVisible句前加setSize
默认是0

62,623

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧