想实现组件间切换,可是没实现
部分代码如下
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没多久,求大神指导~~
部分代码如下
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没多久,求大神指导~~
解决方案 »
- 小白一枚,请教关于包装类中字符串类型转换成基本数据类型的问题
- JScrollpane的问题
- 冰天雪地跪求大师们帮助一下小弟!
- jedit入门问题请教
- 这个问题好难啊,请大家帮忙啊
- 急问!为什么JTree中的结点图标我怎么也改不了。
- 再再再散分100
- 500分求张孝祥java it就业培训教程 视频讲座
- 请问在java中怎样才能保证一个程序同一时刻只有一个在运行。谢谢各位大虾
- 我是初学者,请各位前辈帮忙.我把数组中的内容显示在文本域里,当数据多的时候,他显示一部分就不动了,为什么?如何解决??十万火急,!!!!!!
- 关于在jsp中使用response.sendRedirect()时出现的问题
- 本人菜鸟。。。。求解【泛型接口】
这个没有实现
还有borrower类没有
运行不起来
把所有类贴完整
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;
} }}
还没实现ActionListener 的方法。
2.extends JFrame
3.直接用JDialog 就好啦