问题描述
我最近在做个一个登录系统,我登录界面做好了想点击登录按钮后可以弹出另外一个界面但是不知道怎么弄,希望有大神指点一下privateJTextFieldnameField;privateJPasswordFieldpasswordField;privateLoginFrameframe;privateMenuFramemenuFrame=newMenuFrame();publicLoginFrame(){init();}publicvoidsetNameFIeld(JTextFieldnameField){this.nameField=nameField;}publicvoidsetPwdFIeld(JPasswordFieldpasswordField){this.passwordField=passwordField;}privatevoidinit(){setTitle("在线系统--登录");setSize(300,200);setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);addWindowListener(newWindowAdapter(){publicvoidwindowClosing(WindowEvente){intval=JOptionPane.showConfirmDialog(newJFrame(),"确定退出?","离开系统",JOptionPane.YES_NO_OPTION);if(val==JOptionPane.YES_OPTION){newJFrame().setVisible(false);System.exit(0);}}});setContentPane(createContentPane());}privateJPanelcreateContentPane(){JPanelpane=newJPanel(newBorderLayout(0,8));pane.setBorder(newEmptyBorder(12,12,12,12));pane.add(BorderLayout.NORTH,newJLabel("登录系统",JLabel.CENTER));pane.add(BorderLayout.CENTER,createNamePwdPane());pane.add(BorderLayout.SOUTH,createBtnPane());returnpane;}privateJPanelcreateNamePwdPane(){JPanelpane=newJPanel(newBorderLayout());JPaneltop=newJPanel(newGridLayout(2,1,0,6));pane.add(BorderLayout.NORTH,top);top.add(createNamePane());top.add(createPwdPane());returnpane;}privateJPanelcreateNamePane(){JPanelpane=newJPanel(newBorderLayout(4,0));pane.add(BorderLayout.WEST,newJLabel("账号:"));nameField=newJTextField();pane.add(BorderLayout.CENTER,nameField);returnpane;}privateJPanelcreatePwdPane(){JPanelpane=newJPanel(newBorderLayout(4,0));pane.add(BorderLayout.WEST,newJLabel("密码:"));passwordField=newJPasswordField();passwordField.enableInputMethods(false);pane.add(BorderLayout.CENTER,passwordField);returnpane;}privateJPanelcreateBtnPane(){JPanelpane=newJPanel(newFlowLayout());JButtonlogin=newJButton("登录");login.addActionListener(newActionListener(){publicvoidactionPerformed(ActionEvente){if(getId()==123&&getPwd().equals("123")){menuFrame.showView();frame.setVisible(false);}else{JOptionPane.showMessageDialog(frame,"账号或者密码错误");}System.out.println("点击了登录按钮");}});JButtoncancel=newJButton("取消");cancel.addActionListener(newActionListener(){publicvoidactionPerformed(ActionEvente){intval=JOptionPane.showConfirmDialog(newJFrame(),"确定退出?","离开系统",JOptionPane.YES_NO_OPTION);if(val==JOptionPane.YES_OPTION){newJFrame().setVisible(false);System.exit(0);}}});JButtonregister=newJButton("注册");register.addActionListener(newActionListener(){publicvoidactionPerformed(ActionEvente){System.out.println("点击了注册按钮");}});pane.add(login);pane.add(cancel);pane.add(register);returnpane;}publicvoidshowView(){setVisible(true);}publicintgetId(){Stringid=nameField.getText();returnInteger.parseInt(id);}publicStringgetPwd(){char[]pwd=passwordField.getPassword();returnnewString(pwd);}publicstaticvoidmain(String[]args){newLoginFrame().showView();}}
解决方案
解决方案二:
哈哈,用的swing说,你可以点击登录之后,new一个Jframe啊,然后这个frmae作为你的主界面就可以了