首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Java框架故障

Java框架故障
EN

Stack Overflow用户
提问于 2014-02-11 16:41:39
回答 1查看 72关注 0票数 0

我需要帮助我的程序,因为我想把一个密码和用户名到我的程序,所以如果用户名是测试&&密码是12345,我的程序将出现一个新的框架,但不幸的是,我的第二个不适用于我的标签,按钮等,这是我的代码到目前为止。

代码语言:javascript
复制
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

public class SwapFields extends JFrame{

    public static void main(String[] args) {
        SwapFields frameTabel = new SwapFields();
    }

    JButton blogin = new JButton("Login");
    JPanel panel = new JPanel();
    JTextField txuser = new JTextField(15);
    JPasswordField pass = new JPasswordField(15);
    JLabel lab = new JLabel("Username :");
    JLabel pas = new JLabel("Password :");
    JLabel cos;
    // JPanel panel = new JPanel();
    JButton y1;
    JButton y2;

    SwapFields() {
        super("Enter Your Account !");
        setSize(300, 200);
        setLocation(500, 280);
        panel.setLayout(null);

        txuser.setBounds(90, 30, 150, 20);
        pass.setBounds(90, 65, 150, 20);
        blogin.setBounds(110, 100, 80, 20);
        lab.setBounds(15, 28, 150, 20);
        pas.setBounds(15, 63, 150, 20);

        panel.add(lab);
        panel.add(pas);
        panel.add(blogin);
        panel.add(txuser);
        panel.add(pass);

        getContentPane().add(panel);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setVisible(true);
        actionlogin();
    }

    public void actionlogin() {
        blogin.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent ae) {
                String puname = txuser.getText();
                String ppaswd = pass.getText();
                if (puname.equals("test") && ppaswd.equals("12345")) {

                    JFrame frame = new JFrame("Customer");
                    JPanel panel1 = new JPanel();

                    frame.setVisible(true);
                    frame.setSize(300, 200);
                    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

                    cos = new JLabel("Do you have a Customer ?");
                    y1 = new JButton("Yes");
                    y2 = new JButton("No");

                    panel1.setLayout(null);
                    cos.setBounds(70, 30, 150, 20);
                    y1.setBounds(80, 65, 150, 20);
                    y2.setBounds(140, 65, 150, 20);

                    y1.setSize(55, 30);
                    y2.setSize(55, 30);
                    panel1.add(y1);
                    panel1.add(y2);
                    panel1.add(cos);
                    frame.getContentPane().add(panel1);
                    // this is the code ill change this is the second frame .

                    dispose();
                } else {

                    JOptionPane.showMessageDialog(null, "Wrong Password / Username");
                    txuser.setText("");
                    pass.setText("");
                    txuser.requestFocus();
                }

            }
        });
    }
}
EN

回答 1

Stack Overflow用户

发布于 2014-02-11 20:43:31

变化

代码语言:javascript
复制
    panel.setLayout(null);

代码语言:javascript
复制
    panel.setLayout(new Flowlayout());
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/21696882

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档