【Java开源代码栏目提醒】:网学会员在Java开源代码频道为大家收集整理了UpdateDialog.java提供大家参考,希望对大家有所帮助!
package QQ;
/**
*更新面板,用于用户更新自己的信息
*/
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.net.*;
import java.util.*;
import javax.swing.*;
import javax.swing.border.*;
import com.borland.jbcl.layout.*;
public class UpdateDialog extends JDialog implements ActionListener,ItemListener {
JPanel panel1 = new JPanel();
JLabel jLabel1 = new JLabel();
JLabel jLabel2 = new JLabel();
JLabel jLabel3 = new JLabel();
JLabel jLabel4 = new JLabel();
JLabel jLabel5 = new JLabel();
JLabel jLabel6 = new JLabel();
JLabel jLabel7 = new JLabel();
JLabel jLabel8 = new JLabel();
JLabel jLabel9 = new JLabel();
JPanel jPanel1 = new JPanel();
JPanel iconPane = new JPanel();
Border border1 = BorderFactory.createLineBorder(UIManager.getColor(
"EditorPane.selectionBackground"), 1);
Border border2 = new TitledBorder(border1, "修改信息");
JTextField userName = new JTextField();
JTextField email = new JTextField();
JTextField address = new JTextField();
JScrollPane jScrollPane1 = new JScrollPane();
JTextArea introduceMe = new JTextArea();
ButtonGroup group = new ButtonGroup();
JRadioButton men = new JRadioButton();
JRadioButton women = new JRadioButton();
DefaultComboBoxModel yearModel = new DefaultComboBoxModel();
DefaultComboBoxModel monthModel = new DefaultComboBoxModel();
JComboBox year = new JComboBox();
JLabel jLabel10 = new JLabel();
JComboBox month = new JComboBox();
JLabel jLabel11 = new JLabel();
JPanel jPanel2 = new JPanel();
JButton reset = new JButton();
JButton submit = new JButton();
JLabel imageLabel = new JLabel();
JScrollPane iconScrollPane = new JScrollPane();
JList pictureList = new JList();
BorderLayout borderLayout1 = new BorderLayout();
FlowLayout flowLayout1 = new FlowLayout();
BorderLayout borderLayout2 = new BorderLayout();
XYLayout xYLayout1 = new XYLayout();
String file_separate = System.getProperty("file.separator");
ImageIcon defaultIcon = new ImageIcon("image" + file_separate + "face" +
file_separate + "1-1.gif");
String imagePath = "image" + file_separate + "face" + file_separate +
"1-1.gif"; //用户选择的图像路径
String sex = "男"; //记录用户选择的性别
InetAddress logAddress = null; //服务器IP
int serverPort = 0; //服务器端口
//存储用户的基本信息的类
UserInfoBean userInfo = null;
JPasswordField password = new JPasswordField();
JPasswordField configPassword = new JPasswordField();
public UpdateDialog(Frame owner, String title, boolean modal,
InetAddress address, int port,UserInfoBean userInfo) {
super(owner, title, modal);
this.logAddress = address;
this.serverPort = port;
this.userInfo = userInfo;
jLabel5.setBounds(new Rectangle(41, 165, 61, 15));
jLabel6.setHorizontalAlignment(SwingConstants.RIGHT);
try {
jbInit();
makeIcon();
iconScrollPane.getViewport().add(iconPane);
showInfo();
pack();
} catch (Exception ex) {
ex.printStackTrace();
}
}
public UpdateDialog() {
this(new Frame(), "UpdateDialog", false,null,0,null);
}
//这个方法用来获取用户的信息,并显示在修改面板上
public void showInfo(){
userName.setText(userInfo.getName());
address.setText(userInfo.getPlace());
email.setText(userInfo.getEmail());
imageLabel.setIcon(new ImageIcon(userInfo.getPic()));
introduceMe.setText(userInfo.getInfo());
String sex = userInfo.getSex();
password.setText(userInfo.getPassword());
configPassword.setText(userInfo.getPassword());
if(sex.equals("男")){
men.setSelected(true);
}else{
women.setSelected(true);
}
String birth = userInfo.getBirthday();
String yearBirth = birth.substring(0,birth.indexOf("-"));
String monthBirth = birth.substring(birth.indexOf("-") +1,birth.length());
yearModel.setSelectedItem(yearBirth);
monthModel.setSelectedItem(monthBirth);
}
//这个方法从文件中读取图像文件的路径,并创建图像
private void makeIcon() {
String path = "image" + file_separate + "face";
try {
RandomAccessFile file = new RandomAccessFile(path + file_separate +
"face.ini", "r");
long fileLongth = file.length();
System.out.println("fileLongth :" + fileLongth);
long filePointer = 0;
JLabel[] iconLabel = new JLabel[85];
int i = 0;
while (filePointer < fileLongth) {
iconLabel[i] = new JLabel(new ImageIcon(new String(path +
file_separate + file.readLine())));
iconLabel[i].addMouseListener(new MouseAdapter() {
public void mousePressed(MouseEvent e) {
String iconInfo = e.toString();
int beginIndex = iconInfo.indexOf("image" +
file_separate + "face");
int endIndex = iconInfo.lastIndexOf("-1.gif");
imagePath = iconInfo.substring(beginIndex,
endIndex + 6);
imageLabel.setIcon(new ImageIcon(imagePath));
}
});
iconPane.add(iconLabel[i]);
i += 1;
filePointer = file.getFilePointer();
}
file.close();
} catch (IOException ex) {
ex.printStackTrace();
}
}
private void jbInit() throws Exception {
border2 = new TitledBorder(BorderFactory.createEtchedBorder(Color.white,
new Color(164, 163, 165)), "你的信息如下");
panel1.setLayout(borderLayout2);
jLabel1.setHorizontalAlignment(SwingConstants.RIGHT);
jLabel1.setText("用户名:");
jLabel2.setHorizontalAlignment(SwingConstants.RIGHT);
jLabel2.setText("新密码:");
jLabel3.setHorizontalAlignment(SwingConstants.RIGHT);
jLabel3.setText("确认密码:");
jLabel4.setHorizontalAlignment(SwingConstants.RIGHT);
jLabel4.setText("性别:");
jLabel5.setBounds(new Rectangle(24, 165, 78, 15));
jLabel6.setHorizontalAlignment(SwingConstants.RIGHT);
jLabel5.setHorizontalAlignment(SwingConstants.RIGHT);
jLabel5.setText("出生日期:");
jLabel6.setHorizontalAlignment(SwingConstants.RIGHT);
jLabel6.setText("籍贯:");
jLabel7.setHorizontalAlignment(SwingConstants.RIGHT);
jLabel7.setText("邮箱:");
jLabel8.setHorizontalAlignment(SwingConstants.RIGHT);
jLabel8.setText("头像:");
jLabel9.setHorizontalAlignment(SwingConstants.RIGHT);
jLabel9.setText("自我介绍:");
jPanel1.setBorder(border2);
jPanel1.setLayout(xYLayout1);
men.setSelected(true);
men.setText("男");
men.addItemListener(new UpdateDialog_radioButton_itemAdapter(this));
women.setSelected(false);
women.setText("女");
women.addItemListener(new UpdateDialog_radioButton_itemAdapter(this));
jLabel10.setText("年");
jLabel11.setText("月");
jPanel2.setLayout(flowLayout1);
reset.setText("取消");
reset.addActionListener(new UpdateDialog_reset_actionAdapter(this));
submit.setText("修改");
submit.addActionListener(new UpdateDialog_submit_actionAdapter(this));
imageLabel.setIcon(defaultIcon);
this.getContentPane().setLayout(borderLayout1);
jPanel2.setBorder(Bor
上一篇:
UpdateDemo.java
下一篇:
扛起年轻化大旗,哈弗F系玩转行业新风潮