Java问题,求大佬看看

我运行代码,然后就会有三个不同的窗口,随便关掉一个,其他两个也会关掉,这是怎么回事呀?我想要的是登录之后就只有一个窗口了

import java.awt.*;


import javax.swing.*;
import java.awt.event.*;
public class ceshi extends JFrame implements ActionListener{
   JTextField username;
   JPasswordField pwd;
   JButton submint,close;
   JLabel usenameLabel,pwdLabel;
   public ceshi(){
         super(" Login ");
      usenameLabel=new JLabel("用户名:",JLabel.RIGHT);
      pwdLabel=new JLabel("密码:",JLabel.RIGHT);
      username=new JTextField(10);
      pwd=new JPasswordField(10);
      submint=new JButton("登录");
      close=new JButton("关闭");
      setLayout(new GridLayout(3,2));
      add(usenameLabel);
      add(username);
      add(pwdLabel);
      add(pwd);
      add(submint);
      add(close);
      submint.addActionListener(this);
      close.addActionListener(this);
     
      setDefaultCloseOperation(EXIT_ON_CLOSE);
      setSize(260,150);
      setVisible(true);
    }
   
    public void actionPerformed(ActionEvent e){
       Object obj=e.getSource();
       if (obj==submint)
             if ( new String(pwd.getPassword()).equals("19436108") && username.getText().equals("贺易高"))
                { JFrame  jf2=new JFrame("记事本");
                   jf2.setSize(300,200);
                   jf2.setVisible(true);
                   Noteped notepad=new Noteped("",1000,1000);
                }
           else
               { JOptionPane.showMessageDialog(null,"用户名或密码错误!");
               }
      else
           System.exit(0);
    }
    public static void main(String[] args){
        ceshi login=new ceshi();
        //NotepedDemo login1= new NotepedDemo();
    }
   
  }
 

把EXIT_ON_CLOSE改成HIDE_ON_CLOSE

 

希望对你有帮助

 

import java.awt.*;
import java.awt.event.*;

import javax.swing.*;
class Noteped extends JFrame implements ActionListener{
    JMenuBar menubar;
    JMenu file,edit;
    JMenuItem newFile,open,save,copy,paste,cut;

    JTextArea textArea;
    JTextField textField;
    JScrollPane scroll;

    JPopupMenu pop;

    public Noteped(){};
    public Noteped(String s,int x,int y){
    setTitle(s);
    init();
    setSize(x,y);
    setVisible(true);
    setDefaultCloseOperation(EXIT_ON_CLOSE);
    }

    void init(){
    menubar=new JMenuBar();
    file=new JMenu("文件");
edit=new JMenu("编辑");

newFile=new JMenuItem("新建");
open=new JMenuItem("打开");
save=new JMenuItem("保存");
open.addActionListener(this);
    save.addActionListener(this);
    file.add(newFile);
    file.add(open);
    file.add(save);

    copy=new JMenuItem("复制");
cut=new JMenuItem("剪切");
paste=new JMenuItem("粘贴");

copy.addActionListener(this);
    paste.addActionListener(this);
    cut.addActionListener(this);

    edit.add(copy);
    edit.add(paste);
    edit.add(cut);

    menubar.add(file);
    menubar.add(edit);

    textField=new JTextField();

    textArea=new JTextArea();
    scroll=new JScrollPane(textArea);

    pop=new JPopupMenu();
    pop.add(copy);
    pop.add(paste);
    pop.add(cut);
    textArea.add(pop);
    textArea.addMouseListener(new MouseAdapter(){
    public void mousePressed(MouseEvent e){
    if(e.getButton()==MouseEvent.BUTTON3 )
    pop.show(e.getComponent(),e.getX(),e.getY());
    }
    });

    setJMenuBar(menubar);
    add(scroll,BorderLayout.CENTER);
    add(textField,BorderLayout.NORTH);

    textArea.add(pop);
    }

    public void actionPerformed(ActionEvent e){
    Object obj=e.getSource();
    if(obj==open){

    }
    else if(obj==save){

    }
    else if(obj==newFile) textArea.setText("");
    else if(obj==copy)textArea.copy();
    else if(obj==cut)textArea.cut();
    else if(obj==paste)textArea.paste();
    }
}
public class NotepedDemo{
    public static void main(String[] args) {
    Noteped notepad=new Noteped("",600,400);
    }
}