亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

JButton 不會顯示另一個 jframe

JButton 不會顯示另一個 jframe

吃雞游戲 2023-05-17 14:39:48
我目前正在處理一個項目,每當我單擊 jframe 2(登錄后的第二個 jframe)上的 jbutton“設置約會”/btn1 時,它不會顯示另一個 jframe,即 jframe3。該程序本身可以工作,但該按鈕不會顯示其他 jframe。import java.awt.event.*;import java.io.*;import javax.swing.*;import java.awt.Color;import java.awt.Font;import java.awt.Container;public class me {public static void main (String [] args) {    JFrame jframe = new JFrame();    jframe.setSize(450,350);    jframe.getContentPane().setBackground(Color.WHITE);    ImageIcon c = new ImageIcon("teethlogo5.png");    JLabel bi = new JLabel("",c,JLabel.RIGHT);    bi.setBounds(25,35,400,40);    jframe.add(bi);    ImageIcon a = new ImageIcon("teethlogo2.png");    JLabel si = new JLabel("",a,JLabel.RIGHT);    si.setBounds(50,90,100,120);    jframe.add(si);    JLabel jl1 = new JLabel("Username:");    jl1.setBounds(190,100,100,50);    jframe.add(jl1);    JTextField uss = new JTextField();    uss.setBounds(270,110,120,30);    jframe.add(uss);    JLabel jl2 = new JLabel("Password:");    jl2.setBounds(190,150,100,50);    jframe.add(jl2);    JPasswordField pss = new JPasswordField();    pss.setBounds(270,160,120,30);    jframe.add(pss);    JButton enter = new JButton("log in");    enter.setBounds(250,210,100,40);    jframe.add(enter);    enter.addActionListener(new ActionListener(){        public void actionPerformed(ActionEvent e){            String userText;            String pwdText;            userText = uss.getText();            pwdText = String.valueOf(pss.getPassword());            if (userText.equals("user") && pwdText.equals("pass")) {                JOptionPane.showMessageDialog(null, "LoginSuccessful","Message",JOptionPane.PLAIN_MESSAGE);                jframe.setVisible(false);                JFrame jframe2 = new JFrame();                jframe2.setSize(850,560);                jframe2.getContentPane().setBackground(Color.WHITE);我是 Java 的初學者,我真的很想知道如何解決這個問題。
查看完整描述

1 回答

?
慕碼人2483693

TA貢獻1860條經驗 獲得超9個贊

你是在搬起石頭砸自己的腳:

if (btn1.isSelected()){
    // ...
    }

不需要這個代碼塊——一個按鈕不會被“選中”,除非它從 JToggleButton(例如 JCheckBox)擴展并且已經被選中,這是 JButton 不允許的,更重要的是,它正在阻止它從運行中保存的偵聽器代碼。解決方案:擺脫它。


查看完整回答
反對 回復 2023-05-17
  • 1 回答
  • 0 關注
  • 152 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號