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对话框呀、、、望高手说说 谢谢 展开
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对话框呀、、、望高手说说 谢谢 展开
2个回答
展开全部
在按钮事件里让JFrame消失(dispose()方法),然后让你的JDialog显示出来就行了
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
this.dispose();
new NewJDialog().setVisible(true);
}
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
this.dispose();
new NewJDialog().setVisible(true);
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
改一下你的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;
}
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;
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询