制作多层次的程序 [英] Making a multi-tiered program

查看:36
本文介绍了制作多层次的程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在完成一项作业,需要将我创建的两个程序合并为一个正常运行的程序.我希望的最终结果是一个程序一旦启动,就会打开一个登录窗口,然后一旦登录,用户就可以玩井字游戏.基本上我只是想知道如何有一个窗口,当您单击按钮时,会在其中打开一个可以运行大量代码的新窗口.

I am working on an assignment in which I need to combine two programs that I have created into one functioning program. The end result I am hoping for is a program that once launched, opens a log in window, then once logged in, the user gets to play a tic tac toe game. Basically I just was wonder how to have a window within which when you click a button, a new window opens that can run extensive code.

推荐答案

如果您使用的是 Swing 框架,请创建第二个 JFrame 并将其可见性设置为 false,当按钮被点击时,将它的 visibility 设置为 true.

If you're using Swing framework, Create a second JFrame and set its visibility to false, and when the button is clicked, set it visibility to true.

public class MyFrame extends JFrame {
    private JButton jbt = new JButton("Open Window");
    private AnotherFrame jfrm = new AnotherFrame();

    public MyFrame(){
        add(jbt);
        jfrm.setVisibility(false);
        add(jfrm);

        jbt.addActionListener(new ActionListener(){
            public void actionPerformed(ActionEvent e){
                jfrm.setVisibility(true);
            }
        });
    }

    private AnotherFrame extends JFrame {

        public AnotherFrame(){

       }

    }
}

这篇关于制作多层次的程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆