java swing 点击按钮跳转到一个dialog对话框

importjava.awt.BorderLayout;importjavax.swing.JPanel;importjavax.swing.JFrame;importj... import java.awt.BorderLayout;
import javax.swing.JPanel;
import javax.swing.JFrame;
import javax.swing.JButton;
import java.awt.Rectangle;
import javax.swing.JDialog;
import java.awt.Dimension;

public class tiaozhuan extends JFrame {

private static final long serialVersionUID = 1L;

private JPanel jContentPane = null;

private JButton jButton = null;

private JDialog jDialog = null; // @jve:decl-index=0:visual-constraint="429,29"

private JPanel jContentPane1 = null;

/**
* This is the default constructor
*/
public tiaozhuan() {
super();
initialize();
}

/**
* This method initializes this
*
* @return void
*/
private void initialize() {
this.setSize(300, 200);
this.setContentPane(getJContentPane());
this.setTitle("JFrame");
}

/**
* This method initializes jContentPane
*
* @return javax.swing.JPanel
*/
private JPanel getJContentPane() {
if (jContentPane == null) {
jContentPane = new JPanel();
jContentPane.setLayout(null);
jContentPane.add(getJButton(), null);
}
return jContentPane;
}

/**
* This method initializes jButton
*
* @return javax.swing.JButton
*/
private JButton getJButton() {
if (jButton == null) {
jButton = new JButton();
jButton.setBounds(new Rectangle(61, 55, 69, 28));
jButton.setText("dialog");
jButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
System.out.println("actionPerformed()"); // TODO Auto-generated Event stub actionPerformed()
}
});
}
return jButton;
}

/**
* This method initializes jDialog
*
* @return javax.swing.JDialog
*/
private JDialog getJDialog() {
if (jDialog == null) {
jDialog = new JDialog(this);
jDialog.setSize(new Dimension(329, 180));
jDialog.setContentPane(getJContentPane1());
}
return jDialog;
}

/**
* This method initializes jContentPane1
*
* @return javax.swing.JPanel
*/
private JPanel getJContentPane1() {
if (jContentPane1 == null) {
jContentPane1 = new JPanel();
jContentPane1.setLayout(new BorderLayout());
}
return jContentPane1;
}

我先现建了一个 JFrame,加了个按钮,怎样才可以点击按钮跳转到dialog对话框呀、、、望高手说说 谢谢
展开
 我来答
百度网友e7ad72e
2009-12-02 · 超过16用户采纳过TA的回答
知道答主
回答量:71
采纳率:0%
帮助的人:49万
展开全部
在按钮事件里让JFrame消失(dispose()方法),然后让你的JDialog显示出来就行了
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
this.dispose();
new NewJDialog().setVisible(true);
}
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
cxzucc
推荐于2016-02-17 · TA获得超过1317个赞
知道小有建树答主
回答量:1735
采纳率:79%
帮助的人:589万
展开全部
改一下你的getJButton方法:
private JButton getJButton() {
if (jButton == null) {
jButton = new JButton();
jButton.setBounds(new Rectangle(61, 55, 69, 28));
jButton.setText("dialog");
jButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
System.out.println("actionPerformed()"); // TODO
getJDialog().setVisible(true);//获得Dialog对象后设置它为可见
}
});
}
return jButton;
}
本回答被提问者采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式