gpt4 book ai didi

Java:清除 JFrame 并加载新按钮

转载 作者:行者123 更新时间:2023-12-01 23:11:56 25 4
gpt4 key购买 nike

所以,我显示了主屏幕,我希望这样当用户单击“登录”时加载另一个屏幕。我的第二个屏幕位于另一个名为“fixtureLists”的函数中。当我调用此函数时,它只是将按钮覆盖在登录屏幕上。我如何获得它以便清除屏幕然后加载fixtureLists屏幕?

import java.awt.*;
import javax.swing.*;
import java.awt.event.*;

public class Main extends JFrame
{

public Main()
{

loginButton = new JButton("Login");
loginButton.setBounds( 125, 300, 100, 35);
add(loginButton);
loginButton.addActionListener(new ActionListener()
{

public void actionPerformed(ActionEvent e)
{
//Execute when button is pressed
fixtureList();
System.out.println("Loading the fixtures screen");
}

});

}

public void fixtureList()
{

JButton editButton;
JButton createButton;
JCheckBox chkBox;

setLayout(null);

editButton = new JButton("Edit");
editButton.setBounds( 10, 10, 100, 35);
add(editButton);
createButton = new JButton("Create");
createButton.setBounds( 140, 10, 100, 35);
add(createButton);
editButton = new JButton("Edit");
createButton.setBounds( 10, 30, 100, 35);



}

public static void main(String args[])
{

Main window = new Main();
window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
window.setSize(250, 430);
window.getContentPane().setBackground(new Color(53, 56, 64));
window.setVisible(true);
window.setTitle("PE Timetable v1.0");

}
}

最佳答案

我不会在主框架中定义登录对话框。

您的登录对话框应该在框架上方的对话框中弹出。

话虽如此,如果您希望在同一框架上登录,请使用Cardlayout。在一个卡片布局上有您的登录内容,然后当您登录时,将卡片布局切换到另一个面板。

关于Java:清除 JFrame 并加载新按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21799965/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com