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

2025-03-18 18:22:46
推荐回答(2个)
回答1:

在按钮事件里让JFrame消失(dispose()方法),然后让你的JDialog显示出来就行了
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
this.dispose();
new NewJDialog().setVisible(true);
}

回答2:

改一下你的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;
}