求助,如何用JAVA从一个界面跳到另一个界面
菜鸟一枚。。。求助各位大神。。。第一个界面的程序:
package shiyan;
import javax.swing.SwingUtilities;
import java.awt.BorderLayout;
import javax.swing.JPanel;
import javax.swing.JFrame;
import java.awt.GridBagLayout;
import javax.swing.JButton;
import java.awt.Rectangle;
public class Dasi extends JFrame implements jiemian{
private static final long serialVersionUID = 1L;
private JPanel jPanel = null;
private JButton jButton = null;
/**
* This method initializes jPanel
*
* @return javax.swing.JPanel
*/
private JPanel getJPanel() {
if (jPanel == null) {
jPanel = new JPanel();
jPanel.setLayout(null);
jPanel.add(getJButton(), null);
}
return jPanel;
}
/**
* This method initializes jButton
*
* @return javax.swing.JButton
*/
private JButton getJButton() {
if (jButton == null) {
jButton = new JButton();
jButton.setBounds(new Rectangle(58, 26, 164, 46));
jButton.setText("按钮");
jButton.addActionListener(new java.awt.event.ActionListener()
{
public void actionPerformed(java.awt.event.ActionEvent e)
{
Jiemian jiemian=new Jiemian();
//System.out.println("actionPerformed()"); // TODO Auto-generated Event stub actionPerformed()
}
});
}
return jButton;
}
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
SwingUtilities.invokeLater(new Runnable() {
public void run() {
Dasi thisClass = new Dasi();
thisClass.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
thisClass.setVisible(true);
}
});
}
/**
* This is the default constructor
*/
public Dasi() {
super();
initialize();
}
/**
* This method initializes this
*
* @return void
*/
private void initialize() {
this.setSize(300, 200);
this.setContentPane(getJPanel());
this.setTitle("JFrame");
}
}
第二个界面的程序:
package shiyan;
import javax.swing.SwingUtilities;
import java.awt.BorderLayout;
import javax.swing.JPanel;
import javax.swing.JFrame;
import java.awt.GridBagLayout;
public class Jiemian extends JFrame {
private static final long serialVersionUID = 1L;
private JPanel jPanel1 = null;
/**
* This method initializes jPanel1
*
* @return javax.swing.JPanel
*/
private JPanel getJPanel1() {
if (jPanel1 == null) {
jPanel1 = new JPanel();
jPanel1.setLayout(null);
}
return jPanel1;
}
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
SwingUtilities.invokeLater(new Runnable() {
public void run() {
Jiemian thisClass = new Jiemian();
thisClass.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
thisClass.setVisible(true);
}
});
}
/**
* This is the default constructor
*/
public Jiemian() {
super();
initialize();
}
/**
* This method initializes this
*
* @return void
*/
private void initialize() {
this.setSize(300, 200);
this.setContentPane(getJPanel1());
this.setTitle("你好");
}
}
我是分成两个类,然后在第一个界面中的按钮那块监听事件里也加了 “Jiemian jiemian=new Jiemian();”
可是实现不了,求助各位大神!!怎么才能实现从“按钮”那个界面跳到“你好”那个界面,谢谢!!而且在“Jiemian jiemian=new Jiemian();”后面加了jiemian.open()、jiemian.go()都不顶用
--------------------编程问答-------------------- 从a页面跳到b
a.setVisible(false);
b.setVisible(true);
恩,是这样 --------------------编程问答-------------------- a.dispose() --------------------编程问答-------------------- 如果这两个类是同一个程序里的那么只要一个main函数就可以了,那个类是最先启动的main函数就放在那个类中,看你的意思应该是上面的那个类调用“你好”的那个界面,那么你好的那个界面就不用写mian函数了,关于你说的那个效果参照下面的模型:
import javax.swing.JButton;
import javax.swing.JFrame;
import java.awt.Rectangle;
public class Class {
private JButton jButton = null;
private JieMian j = new JieMian();
private JButton getJButton() {
if (jButton == null) {
jButton = new JButton();
jButton.setBounds(new Rectangle(58, 26, 164, 46));
jButton.setText("按钮");
jButton.addActionListener(new java.awt.event.ActionListener()
{
public void actionPerformed(java.awt.event.ActionEvent e)
{
j.start();
}
});
}
return jButton;
}
public static void main(String []args){
Class c = new Class();
}
}
public class JieMian extends JFrame{
public void start(){
this.setVisible(true);
}
}
补充:Java , Java SE