想实现组件间切换,可是没实现
部分代码如下
import javax.swing.*;
import javax.swing.border.*;import java.awt.*;
import java.awt.event.*;
public class BorrowerIofoPanel extends JPanel implements ActionListener{
  private JPanel infoPanel;
  private JLabel name1,name2;
  private JLabel position1,position2;
  private JLabel id1,id2;
  private JLabel mail1,mail2;
  private JLabel maxBorrowNum1,maxBorrowNum2;
  private JLabel maxBorrowTime1,maxBorrowTime2;
  private JLabel maxContinueBorrowTime1,maxContinueBorrowTime2;
  private JButton change_bt;
  private Borrower borrower;
  
  private ChangeKeyPanel changeKeyPanel;

  public BorrowerIofoPanel(){
 infoPanel=new JPanel();
 borrower=new Borrower("1","dg","123456" );
 name1=new JLabel("姓名");
 name2=new JLabel(borrower.getBorrowerName());
 position1=new JLabel("身份");
 position2=new JLabel("本科生");
 id1=new JLabel("编号");
 id2=new JLabel(borrower.getBorrowerNum());
 mail1=new JLabel("邮箱");
 mail2=new JLabel("[email protected]");
 maxBorrowNum1=new JLabel("最大借阅册数");
 maxBorrowNum2=new JLabel("borrower.maxBorrowedNumber");
 maxBorrowTime1=new JLabel("最长借阅时间");
 maxBorrowTime2=new JLabel("31天");
 maxContinueBorrowTime1=new JLabel("最大续借次数");
 maxContinueBorrowTime2=new JLabel("borrower.maxContinueBorrowTime");
 change_bt=new JButton("修改密码");
 
 changeKeyPanel=new ChangeKeyPanel();
 
 infoPanel.setLayout(new GridLayout(8,2));
 infoPanel.setBorder(new TitledBorder(borrower.getBorrowerName()+":你好!" ));
 changeKeyPanel.setVisible(false);
 
 infoPanel.add(id1);
 infoPanel.add(id2);
 infoPanel.add(name1);
 infoPanel.add(name2);
 infoPanel.add(position1);
 infoPanel.add(position2);
 infoPanel.add(mail1);
 infoPanel.add(mail2);
 infoPanel.add(maxBorrowNum1);
 infoPanel.add(maxBorrowNum2);
 infoPanel.add(maxBorrowTime1);
 infoPanel.add(maxBorrowTime2);
 infoPanel.add(maxContinueBorrowTime1);
 infoPanel.add(maxContinueBorrowTime2);
 infoPanel.add(new JLabel());
 infoPanel.add(change_bt);
 
 add(infoPanel);
 add(changeKeyPanel);
 
  }
      public void actionPerformed(ActionEvent e){
       if(e.getSource().equals(change_bt)){
       infoPanel.setVisible(false);
       changeKeyPanel.setVisible(true);
       
       }
      }
      
      
      
      class ChangeKeyPanel extends JPanel implements ActionListener{
       private JLabel oldKeyLabel,newKeyLabel,confirmKeyLabel;
       private JPasswordField oldKeyField,newKeyField,confirmKeyField;
       private JButton ok_bt,ret_bt;
      
       public ChangeKeyPanel(){
       setLayout(new GridLayout(4,2));
       oldKeyLabel=new JLabel("旧密码 ");
       newKeyLabel=new JLabel("新密码 ");
       confirmKeyLabel=new JLabel("确认密码");
       oldKeyField=new JPasswordField();
       newKeyField=new JPasswordField();
       confirmKeyField=new JPasswordField();
       ok_bt=new JButton("确定");
       ret_bt=new JButton("返回");
      
       oldKeyField.setEditable(true);
       newKeyField.setEditable(true);
       confirmKeyField.setEditable(true);
      
       ok_bt.addActionListener(this);
       ret_bt.addActionListener(this);
      
       add(oldKeyLabel);
       add(oldKeyField);
       add(newKeyLabel);
       add(newKeyField);
       add(confirmKeyLabel);
       add(confirmKeyField);
       add(ok_bt);
       add(ret_bt);
      
       }
                 
      }
}刚学java没多久,求大神指导~~

解决方案 »

  1.   

    就是infoPanel和changeKeyPanel之间切换
    这个没有实现
      

  2.   

    你的代码没贴完整
    还有borrower类没有
    运行不起来
    把所有类贴完整
      

  3.   

    代码太多,不好写,你就不要管borrower类,随便写点数据就可以啦,另外在吧这个BorrowerIofoPanel添加到JFrame中就可以运行啦
      

  4.   

    用弹出一个JDialog或者Tab布局管理器都可以啊
      

  5.   

    import javax.swing.*;
    import javax.swing.border.*;import java.awt.*;
    import java.awt.event.*;public class BorrowerInfoPanel { private JLabel oldKeyLabel, newKeyLabel;
    private JPasswordField oldKeyField, newKeyField, confirmKeyField; private JPanel infoPanel;
    private JLabel name1, name2; private JLabel position1, position2;
    private JLabel id1, id2;
    private JLabel mail1, mail2;
    private JLabel maxBorrowNum1, maxBorrowNum2;
    private JLabel maxBorrowTime1, maxBorrowTime2;
    private JLabel maxContinueBorrowTime1, maxContinueBorrowTime2;
    private JButton change_bt;
    private Borrower borrower;
    private JFrame frame = new JFrame();; private JDialog jd = new JDialog(frame, "修改密码", true); public BorrowerInfoPanel() {
    infoPanel = new JPanel();
    borrower = new Borrower("1", "dg", "123456");
    name1 = new JLabel("姓名");
    name2 = new JLabel(borrower.getBorrowerName());
    position1 = new JLabel("身份");
    position2 = new JLabel("本科生");
    id1 = new JLabel("编号");
    id2 = new JLabel(borrower.getBorrowerNum());
    mail1 = new JLabel("邮箱");
    mail2 = new JLabel("[email protected]");
    maxBorrowNum1 = new JLabel("最大借阅册数");
    maxBorrowNum2 = new JLabel("borrower.maxBorrowedNumber");
    maxBorrowTime1 = new JLabel("最长借阅时间");
    maxBorrowTime2 = new JLabel("31天");
    maxContinueBorrowTime1 = new JLabel("最大续借次数");
    maxContinueBorrowTime2 = new JLabel("borrower.maxContinueBorrowTime");
    change_bt = new JButton("修改密码"); infoPanel.setLayout(new GridLayout(8, 2));
    infoPanel.setBorder(new TitledBorder(borrower.getBorrowerName()
    + ":你好!")); infoPanel.add(id1);
    infoPanel.add(id2);
    infoPanel.add(name1);
    infoPanel.add(name2);
    infoPanel.add(position1);
    infoPanel.add(position2);
    infoPanel.add(mail1);
    infoPanel.add(mail2);
    infoPanel.add(maxBorrowNum1);
    infoPanel.add(maxBorrowNum2);
    infoPanel.add(maxBorrowTime1);
    infoPanel.add(maxBorrowTime2);
    infoPanel.add(maxContinueBorrowTime1);
    infoPanel.add(maxContinueBorrowTime2);
    infoPanel.add(new JLabel());
    infoPanel.add(change_bt); oldKeyLabel = new JLabel("    旧密码");
    newKeyLabel = new JLabel("    新密码"); oldKeyField = new JPasswordField(10);
    newKeyField = new JPasswordField(10);
    confirmKeyField = new JPasswordField(10); oldKeyField.setEditable(true);
    newKeyField.setEditable(true);
    confirmKeyField.setEditable(true); } public void init() {
    change_bt.addActionListener(new ActionListener() { @Override
    public void actionPerformed(ActionEvent e) {
    jd.setVisible(true);// TODO Auto-generated method stub }
    });
    jd.addWindowListener(new WindowAdapter() {
    public void windowClosing(WindowEvent e) {
    jd.setVisible(false);
    }
    });
    jd.setLocation(620, 340);
    JPanel jp = new JPanel();
    JPanel jp2 = new JPanel();
    jp.add(oldKeyField);
    jp.add(oldKeyLabel);
    jp2.add(newKeyField);
    jp2.add(newKeyLabel);
    Box top = Box.createVerticalBox();
    top.add(jp);
    top.add(jp2);
    jd.add(top); jd.pack();
    jd.setResizable(false);
    frame.setLocation(450, 240);
    frame.add(infoPanel);
    frame.pack();
    frame.setVisible(true);
    frame.setResizable(false);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    } public static void main(String[] args) {
    new BorrowerInfoPanel().init();
    } class Borrower {
    private String borrowerName; public String getBorrowerName() {
    return borrowerName;
    } public void setBorrowerName(String borrowerName) {
    this.borrowerName = borrowerName;
    } public String getBorrowerNum() {
    return borrowerNum;
    } public void setBorrowerNum(String borrowerNum) {
    this.borrowerNum = borrowerNum;
    } public String getPassword() {
    return password;
    } public void setId(String id) {
    this.password = id;
    } private String borrowerNum;
    private String password; public Borrower(String borrowerNum, String borrowerName, String password) {
    this.password = password;
    this.borrowerName = borrowerName;
    this.borrowerNum = borrowerNum;
    } }}
      

  6.   

    ChangeKeyPanel
    还没实现ActionListener 的方法。
      

  7.   

    1.点击跟改密码,让原窗口隐藏,让新窗口显示setVisible()
    2.extends JFrame
    3.直接用JDialog 就好啦