?? userinfop.java
字號:
package connex.app.loginUI;
import java.awt.*;
import javax.swing.*;
import connex.app.utils.Countries;
import connex.app.utils.Languages;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import connex.app.utils.fileChooserUtils.ImagePreview;
import connex.app.utils.fileChooserUtils.ImageFilter;
import java.io.File;
import connex.app.utils.fileChooserUtils.Utils;
import java.awt.image.RenderedImage;
import java.awt.image.BufferedImage;
import javax.imageio.ImageIO;
import java.io.*;
import net.jxta.document.StructuredDocumentFactory;
import net.jxta.document.StructuredDocument;
import net.jxta.document.MimeMediaType;
import net.jxta.document.XMLElement;
import net.jxta.document.Element;
public class UserInfoP extends JLabel {
private JFileChooser fc;
//private BufferedImage tmpimg = null;
private ImageIcon img = null;
private ImageIcon img1 = new ImageIcon("images/back2.png");
private JTextField nick = new JTextField();
private JTextField mail = new JTextField();
private JPasswordField pass = new JPasswordField();
private JPasswordField pass2 = new JPasswordField();
private JLabel jLabel1 = new JLabel();
private JLabel jLabel2 = new JLabel();
private JLabel jLabel3 = new JLabel();
private JLabel jLabel4 = new JLabel();
private JLabel jLabel5 = new JLabel();
private JTextField city = new JTextField();
private JLabel jLabel6 = new JLabel();
private JComboBox country = new JComboBox(Countries.COUNTRIES);
private JLabel jLabel7 = new JLabel();
private JComboBox language = new JComboBox(Languages.LANGUAGES);
private JLabel jLabel8 = new JLabel();
private JTextField phone = new JTextField();
private JButton picbtn = new JButton();
private JLabel picLb = new JLabel();
/*****************************/
private boolean update = false; //wether the panel in profile change mode;
private boolean picChanged = false;
public UserInfoP(boolean update) {
this.update = update;
try {
jbInit();
} catch (Exception exception) {
exception.printStackTrace();
}
}
private void jbInit() throws Exception {
jLabel3.setText("* Password");
jLabel3.setBounds(new Rectangle(28, 87, 113, 22));
jLabel4.setLabelFor(nick);
jLabel4.setText("* Nick name");
jLabel4.setBounds(new Rectangle(30, 20, 113, 22));
jLabel5.setText("Country");
jLabel5.setBounds(new Rectangle(34, 161, 106, 25));
city.setBounds(new Rectangle(139, 195, 176, 24));
jLabel6.setText("City");
jLabel6.setBounds(new Rectangle(33, 194, 106, 25));
country.setBounds(new Rectangle(139, 160, 176, 24));
country.setSelectedItem("Germany");
jLabel7.setText("Language");
jLabel7.setBounds(new Rectangle(29, 231, 106, 25));
language.setBounds(new Rectangle(139, 230, 176, 24));
language.setSelectedItem("German");
jLabel8.setLabelFor(phone);
jLabel8.setText("Other");
jLabel8.setBounds(new Rectangle(28, 266, 104, 23));
mail.setText("");
mail.setBounds(new Rectangle(139, 55, 176, 24));
pass.setText("");
pass.setBounds(new Rectangle(139, 90, 176, 24));
pass2.setText("");
pass2.setBounds(new Rectangle(139, 125, 176, 24));
nick.setText(System.getProperty("user.name"));
nick.setBounds(new Rectangle(139, 20, 176, 24));
jLabel1.setText("* Repeat Password");
jLabel1.setBounds(new Rectangle(27, 127, 113, 22));
jLabel2.setText("* E-mail Address");
jLabel2.setBounds(new Rectangle(30, 54, 113, 22));
phone.setText("");
phone.setBounds(new Rectangle(139, 265, 176, 24));
this.setHorizontalAlignment(SwingConstants.TRAILING);
this.setIcon(img1);
this.setVerticalAlignment(SwingConstants.BOTTOM);
picbtn.setBounds(new Rectangle(323, 20, 91, 23));
picbtn.setText("Add Picture");
picbtn.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
picbtn_actionPerformed(e);
}
});
picLb.setBounds(new Rectangle(322, 53, 98, 112));
this.add(nick, null);
this.add(mail, null);
this.add(pass, null);
this.add(pass2, null);
this.add(jLabel2, null);
this.add(jLabel4, null);
this.add(jLabel1, null);
this.add(jLabel3, null);
this.add(city, null);
this.add(jLabel5, null);
this.add(country, null);
this.add(language, null);
this.add(phone);
this.add(jLabel6, null);
this.add(jLabel7, null);
this.add(jLabel8, null);
this.add(picbtn);
this.add(picLb);
this.setBackground(Color.white);
this.setInputVerifier(null);
this.setLayout(null);
if (update) {
pass.setEnabled(false);
pass2.setEnabled(false);
jLabel1.setVisible(false);
pass2.setVisible(false);
loadProfile();
picLb.setIcon(new ImageIcon(System.getProperty(
"JXTA_HOME") + File.separator +
"MyImg.jpg"));
}
}
private void loadProfile() {
FileInputStream is = null;
StructuredDocument doc = null;
try {
is = new FileInputStream(System.getProperty(
"JXTA_HOME") + File.separator +
"ProfileAdv.adv");
} catch (FileNotFoundException ex) {
}
try {
doc = StructuredDocumentFactory.
newStructuredDocument(new MimeMediaType(
"text", "xml"), is);
} catch (IOException ex1) {
}
XMLElement element = (XMLElement) doc.getParent();
Element elem = (Element) element.getChildren("name").nextElement();
if (elem != null && elem.getValue() != null) {
nick.setText(elem.getValue().toString());
}
/*elem = (Element) element.getChildren(speedKey).nextElement();
if (elem != null && elem.getValue() != null) {
adv.setSpeed(elem.getValue().toString());
}*/
/* elem = (Element) element.getChildren(mobilityKey).nextElement();
if (elem != null && elem.getValue() != null) {
adv.setMobility(elem.getValue().toString());
}*/
elem = (Element) element.getChildren("countery").nextElement();
if (elem != null && elem.getValue() != null) {
country.setSelectedItem("elem.getValue().toString()");
}
elem = (Element) element.getChildren("language").nextElement();
if (elem != null && elem.getValue() != null) {
language.setSelectedItem(elem.getValue().toString());
}
elem = (Element) element.getChildren("city").nextElement();
if (elem != null && elem.getValue() != null) {
city.setText(elem.getValue().toString());
}
elem = (Element) element.getChildren("other").nextElement();
if (elem != null && elem.getValue() != null) {
phone.setText(elem.getValue().toString());
}
elem = (Element) element.getChildren("email").nextElement();
if (elem != null && elem.getValue() != null) {
mail.setText(elem.getValue().toString());
}
}
public String getNick() {
return nick.getText();
}
public String getMail() {
return mail.getText();
}
public String getPass() {
return new String(pass.getPassword());
}
public String getPass2() {
return new String(pass2.getPassword());
}
public String getCountry() {
return country.getSelectedItem().toString();
}
public String getCity() {
return city.getText();
}
public String getLanguage() {
return language.getSelectedItem().toString();
}
public String getPhone() {
return phone.getText();
}
public RenderedImage getPic() {
return Utils.getBufferedImage(img);
}
public boolean isPicChanged() {
return picChanged;
}
public void picbtn_actionPerformed(ActionEvent e) {
//Set up the file chooser.
if (fc == null) {
fc = new JFileChooser();
//Add a custom file filter and disable the default
//(Accept All) file filter.
fc.addChoosableFileFilter(new ImageFilter());
fc.setAcceptAllFileFilterUsed(false);
//Add custom icons for file types.
// fc.setFileView(new ImageFileView());
//Add the preview pane.
fc.setAccessory(new ImagePreview(fc));
}
//Show it.
int returnVal = fc.showDialog(UserInfoP.this,
"Attach");
//Process the results.
if (returnVal == JFileChooser.APPROVE_OPTION) {
File file = fc.getSelectedFile();
img = new ImageIcon(file.getAbsolutePath());
img = Utils.getThumbNail(img);
picLb.setIcon(img);
picChanged = true;
} else {
}
//Reset the file chooser for the next time it's shown.
fc.setSelectedFile(null);
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -