如何在Java中连接两个框架?

如何在Java中连接两个框架?,java,jframe,Java,Jframe,我有三种不同的框架: welcome.java Register.java LoginForm.java 若我点击登录按钮,登录页面必须打开(即LoginForm.java),若我点击注册按钮,注册页面必须打开 //welcome.java import java.awt.EventQueue; import javax.swing.JFrame; import javax.swing.JButton; import java.awt.event.ActionListener; import

我有三种不同的框架:

  • welcome.java
  • Register.java
  • LoginForm.java
若我点击登录按钮,登录页面必须打开(即LoginForm.java),若我点击注册按钮,注册页面必须打开

//welcome.java
import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.JLabel;


public class welcome extends JFrame
{

private JFrame frame;

/**
 * Launch the application.
 */
public static void main(String[] args) {
    EventQueue.invokeLater(new Runnable() {
        public void run() {
            try {
                welcome window = new welcome();
                window.frame.setVisible(true);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    });
}

/**
 * Create the application.
 */
public welcome() {
    initialize();
}

/**
 * Initialize the contents of the frame.
 */
private void initialize() {
    frame = new JFrame();
    frame.setBounds(100, 100, 450, 300);
    frame.setVisible(true);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.getContentPane().setLayout(null);

    JButton btnLogIn = new JButton("LOG IN");
    btnLogIn.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
        }
    });
    btnLogIn.setBounds(200, 69, 117, 25);
    frame.getContentPane().add(btnLogIn);

    JButton btnRegister = new JButton("Register");
    btnRegister.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent arg0) {
        }
    });
    btnRegister.setBounds(200, 138, 117, 25);
    frame.getContentPane().add(btnRegister);

    JLabel lblNewToSvk = new JLabel("New to SVK Polytechnic ?");
    lblNewToSvk.setBounds(12, 143, 191, 15);
    frame.getContentPane().add(lblNewToSvk);
}
}

你可以用

frame.setVisible(true);
使JFrame(窗体)可见

 //Register.java
import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.JLabel;
import java.awt.Font;
import java.awt.Color;
import javax.swing.JComboBox;
import javax.swing.DefaultComboBoxModel;


 public class Register {

 private JFrame frame;

/**
 * Launch the application.
 */
public static void main(String[] args) {
    EventQueue.invokeLater(new Runnable() {
        public void run() {
            try {
                Register window = new Register();
                window.frame.setVisible(true);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    });
}

/**
 * Create the application.
 */
public Register() {
    initialize();
}

/**
 * Initialize the contents of the frame.
 */
private void initialize() {
    frame = new JFrame();
    frame.setBounds(100, 100, 450, 300);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.getContentPane().setLayout(null);

    JLabel lblRegisterForm = new JLabel("Register Form");
    lblRegisterForm.setForeground(Color.BLUE);
    lblRegisterForm.setFont(new Font("Dialog", Font.BOLD | Font.ITALIC, 25));
    lblRegisterForm.setBounds(119, 12, 209, 25);
    frame.getContentPane().add(lblRegisterForm);

    JLabel lblSelectTheUser = new JLabel("Select the user type");
    lblSelectTheUser.setFont(new Font("Dialog", Font.BOLD, 15));
    lblSelectTheUser.setBounds(22, 83, 192, 25);
    frame.getContentPane().add(lblSelectTheUser);

    JComboBox cb1 = new JComboBox();
    cb1.setModel(new DefaultComboBoxModel(new String[] {"Student", "Lecturer", "Office staff", "HOD"}));
    cb1.setBounds(213, 83, 151, 24);
    frame.getContentPane().add(cb1);
}

public void setVisible(boolean b) {
    // TODO Auto-generated method stub

}

public void setTitle(String string) {
    // TODO Auto-generated method stub

}

public void setSize(int i, int j) {
    // TODO Auto-generated method stub

}

public void setLocationRelativeTo(Object object) {
    // TODO Auto-generated method stub

}

public void setDefaultCloseOperation(int exitOnClose) {
    // TODO Auto-generated method stub

    }
 }
frame.setVisible(true);