gpt4 book ai didi

java - 特殊的 GUI 问题

转载 作者:行者123 更新时间:2023-12-02 05:40:12 26 4
gpt4 key购买 nike

由于一些尴尬的原因,每当我在 actionPerformed() 内部将所需的框架设置为 Visible(true) 时,它都会打印出该框架,其中包含标题,但没有组件,也没有我之前选择的颜色。

但是,当在当前帧的顶部将可见性设置为 true 时(无需按下按钮),它工作正常。

这是我正在使用的框架:

enter image description here

但是一旦我在actionPerformed中将可见性设置为true,就会打印这个:

enter image description here

我已经在 actionPerformed() 中将另一个框架(主客户端框架)设置为 true 并且工作正常。这是我第一次遇到这个问题,所以我真的不确定是什么原因造成的。

我还假设这可能是由于在 actionPerformed 期间客户端必须连接到特定服务器详细信息,但话又说回来,一旦实例化第一帧,框架对象就会被实例化,所以它应该是很好..

这是我的actionPerformed(),抱歉代码困惑:

JButton connectButton = new JButton("Connect");
connectButton.setBackground(SystemColor.activeCaption);
connectButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {

//If any of the first three fields are empty, turn them red
if(serverField.getText().equalsIgnoreCase("")){
lblSever.setForeground(new Color(240, 128, 128));
}
if(channelField.getText().equalsIgnoreCase("")){
lblChannel.setForeground(new Color(240, 128, 128));
}
if(nicknameField.getText().equalsIgnoreCase("")){
lblNickname.setForeground(new Color(240, 128, 128));
}

//Set Waiting Connection frame to true
wc.setVisible(true);

//None of the first three fields are empty
if(!serverField.getText().equalsIgnoreCase("")
&& !channelField.getText().equalsIgnoreCase("")
&& !nicknameField.getText().equalsIgnoreCase("")){

//Set current frame visibility to false
setVisible(false);

//Set connection details
Main.bot.setServer(serverField.getText());
Main.bot.setChannel(channelField.getText());
Main.bot.setNickname(nicknameField.getText());
Main.bot.setPassword(formattedTextField.getText());

//Connect to server and channel
try{
Main.bot.connect(serverField.getText());
Main.bot.changeNick(nicknameField.getText());
Main.bot.joinChannel(channelField.getText());
}catch(Exception e){ //Catch all errors, if invalid server is thrown, close Waiting Connection frame
InvalidServer error = new InvalidServer();
e.printStackTrace();
wc.setVisible(false);
wc.dispose();
error.setVisible(true);
}

setVisible(false);

//Custom Timer class
Timer runTime = new Timer();

while(runTime.getTimeElapsed() < 5000){
//To-Do
}
wc.setVisible(false);

//Instantiate next frame
MainFrame mainFrame = new MainFrame();
mainFrame.setVisible(true);

//Kill current frame
dispose();
}
}
});

最佳答案

一些要点:

关于java - 特殊的 GUI 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24585777/

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