如何在一个dialog点按钮弹出一个dialog
展开全部
看以下代码:
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class MainF extends JFrame{
public MainF(){
JButton b = new JButton("Dia");
b.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
// TODO Auto-generated method stub
new MainD(MainF.this);
}
});
JPanel p = new JPanel();
p.add(b);
add(p);
setSize(100,100);
setVisible(true);
}
public static void main(String[] args) {
new MainF();
}
}
回复收起回复
3楼
2013-10-20 20:51
举报 |个人企业举报垃圾信息举报
我也说一句
我的女神130
淼沝
5
import java.awt.Frame;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JDialog;
public class MainD extends JDialog{
public MainD(Frame owner) {
super(owner);
final Frame f = owner;
JButton b = new JButton("Dia");
add(b);
b.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
// TODO Auto-generated method stub
new MainD(f);
}
});
setSize(100,100);
setVisible(true);
}
}
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class MainF extends JFrame{
public MainF(){
JButton b = new JButton("Dia");
b.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
// TODO Auto-generated method stub
new MainD(MainF.this);
}
});
JPanel p = new JPanel();
p.add(b);
add(p);
setSize(100,100);
setVisible(true);
}
public static void main(String[] args) {
new MainF();
}
}
回复收起回复
3楼
2013-10-20 20:51
举报 |个人企业举报垃圾信息举报
我也说一句
我的女神130
淼沝
5
import java.awt.Frame;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JDialog;
public class MainD extends JDialog{
public MainD(Frame owner) {
super(owner);
final Frame f = owner;
JButton b = new JButton("Dia");
add(b);
b.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
// TODO Auto-generated method stub
new MainD(f);
}
});
setSize(100,100);
setVisible(true);
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询