主界面:importjava.awt.event.ActionEvent;importjava.awt.event.ActionListener;importjavax.swing.JFrame;publicclassMainFrame{publicstaticvoidmain(String[]args){lauchFramelf...
主界面:
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JFrame;
public class MainFrame{
public static void main(String[] args){
lauchFrame lf = new lauchFrame();
}
}
class lauchFrame extends JFrame {
JFrame mainframe = new JFrame();
public lauchFrame(){
this.setTitle("IS");
this.setSize(800, 600);
this.setResizable(false);
this.setLocationRelativeTo(null);
this.setVisible(true);
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
}
登陆界面:import java.awt.GridLayout;
import java.awt.Rectangle;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
public class logonWin extends JFrame {
public static void main(String[] args){
logonFrame lf = new logonFrame();
}
}
class logonFrame extends JFrame implements ActionListener{
static JFrame logon = new JFrame("Logon");
private JLabel lab1 = new JLabel();
private JLabel lab2 = new JLabel();
private JTextField tf = new JTextField();
private JPasswordField pf = new JPasswordField();
private JButton bt1 = new JButton();
private JButton bt2 = new JButton();
logonFrame(){
lab1.setBounds(new Rectangle(56, 26, 39, 18));
lab1.setText("用户名");
lab2.setBounds(new Rectangle(57, 59, 26, 18));
lab2.setText("密码");
tf.setBounds(new Rectangle(123, 25, 118, 22));
pf.setBounds(new Rectangle(123, 59, 118, 22));
bt1.setBounds(new Rectangle(57, 100, 60, 28));
bt1.setText("登陆");
bt1.addActionListener(this);
bt2.setBounds(new Rectangle(174, 100, 60, 28));
bt2.setText("退出");
bt2.addActionListener(this);
logon.setLayout(null);
logon.setSize(300, 200);
logon.add(lab1);
logon.add(tf);
logon.add(lab2);
logon.add(pf);
logon.add(bt1);
logon.add(bt2);
logon.setDefaultCloseOperation(EXIT_ON_CLOSE);
logon.setResizable(false);
logon.setLocationRelativeTo(null);
logon.setVisible(true);
}
public void actionPerformed(ActionEvent e) {
if (e.getSource() == bt2) {
System.exit(0);
}
if (e.getSource() == bt1) {
MainFrame mf = new MainFrame();
System.exit(0);
}
}
}
在登陆界面通过按键调用不了主界面,主界面单独运行时可以显示,请问是什么问题啊
是不是if (e.getSource() == bt1) {
MainFrame mf = new MainFrame();
System.exit(0);
}
的System.exit(0);的问题啊
展开