JDialog .setBackground失效解决办法

public LoginDialog(GameWin gw,String s,boolean isYouMoShi,Client client){
        super(gw, s,isYouMoShi);
        this.client=client;
        setLayout(null);

        getContentPane().setBackground(new Color(12,14,56));

        //setBackground(new Color(12,14,56));//会出错!因为分层原因

        setSize(200,200);
        setLocation(gw.getDim().width/2-100,200);
        loginTf=new JTextField(10);
        passwordTf=new JTextField(10);
        loginLb=new JLabel("用户名:");
        passwordLb=new JLabel("密    码:");
        btnLogin=new JButton("登录");
        
        loginTf.setName("登录");
        loginLb.setBounds(5, 20, 60, 25);
        loginTf.setBounds(50, 20, 100,25);
        passwordLb.setBounds(5, 60, 60,25);
        passwordTf.setBounds(50, 60, 100,25);
        btnLogin.setBounds(60, 100, 70, 30);
        btnLogin.addActionListener(this);
        loginTf.setBorder (BorderFactory.createLineBorder(Color.black,1));
        passwordTf.setBorder (BorderFactory.createLineBorder(Color.black,1));
        add(loginLb);
        add(loginTf);
        add(passwordTf);
        add(passwordLb);
        add(btnLogin);
        setVisible(true);
        validate();
        
    }
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
改进以下代码,让错误出现三次弹出冻结信息并关闭窗体。denglu.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { int count = 0; String inputzh = zhanghu.getText(); boolean bl = true; try { new Mysql(); bl = Mysql.jujle(inputzh); } catch (ClassNotFoundException e1) { // TODO 自动生成的 catch 块 e1.printStackTrace(); } catch (SQLException e1) { // TODO 自动生成的 catch 块 e1.printStackTrace(); } System.out.println(bl); if (bl) { try { System.out.println(inputzh); new GUI2(inputzh); jf.dispose(); } catch (Exception e1) { // TODO 自动生成的 catch 块 e1.printStackTrace(); } } else { ImageIcon titleIcon = new ImageIcon("F:\\ATM.png"); JDialog jDialog = new JDialog(jf, "错误", true); jDialog.setSize(400, 200); jDialog.setLocation(575, 400); JTextField jTextField = new JTextField("您的账号和密码输入有误!请重新输入。"); jTextField.setHorizontalAlignment(JTextField.CENTER); jTextField.setEditable(false); jTextField.setSelectedTextColor(Color.black); jDialog.add(jTextField); jDialog.setIconImage(titleIcon.getImage()); jTextField.setVisible(true); jDialog.setVisible(true); count++; if (count == 3) { ImageIcon titleIcon1 = new ImageIcon("F:\\ATM.png"); JDialog jDialog1 = new JDialog(jf, "错误", true); jDialog.setSize(400, 200); jDialog.setLocation(575, 400); JTextField jTextField1 = new JTextField("您的账号已冻结!请联系人工处理。"); jTextField.setHorizontalAlignment(JTextField.CENTER); jTextField.setEditable(false); jTextField.setSelectedTextColor(Color.black); jDialog.add(jTextField1); jDialog.setIconImage(titleIcon1.getImage()); jTextField.setVisible(true); jDialog.setVisible(true); jf.setDefaultCloseOperation(3); System.exit(0); } else { jpl.repaint(); } } } });
最新发布
05-31
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值