简体   繁体   中英

how to open a new window(2nd frame) when a button is clicked in present window(1st frame) in java swing

所以我一直在一个项目中,在该项目中我创建的框架中有一个“登录”按钮,我必须这样做,以便当用户单击“登录”按钮时,当前窗口应终止,并出现一个新窗口。标签和文本字段将打开,提示用户输入他的用户名,通过我用文本字段n标签创建了另一个框架,只是不知道如何将两者链接在一起,我为LOGIN按钮框架和userid传递框架做了两个不同的类这些类是从一个单独的具有主要功能的主类中调用的,请帮助您在星期一提交项目:( :(

In Login button: add action to it which allow you to

       1- dispose the Login frame 
       2- open the second frame

Like this :

private void LoginButtonActionPerformed(java.awt.event.ActionEvent evt) {
        dispose();////////////will dispose the Login frame
        UsernameAndPassword username = new UsernameAndPassword();//////UsernameAndPassword :is the second frame. 
        username .setVisible(true);//////the Username and password frame will be visible
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM