?? viewfrienddialog.java
字號:
/* * @(#) ViewFriendDialog.java * Copyright 2004 HWStudio. All rights reserved. */package hws.item.smart.dialog;//導(dǎo)入核心Java類庫import java.awt.Insets;import java.awt.Container;import java.awt.CardLayout;import java.awt.FlowLayout;import java.awt.GridBagLayout;import java.awt.GridBagConstraints;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import javax.swing.JList;import javax.swing.JPanel;import javax.swing.JButton;import javax.swing.JDialog;import javax.swing.JSplitPane;import javax.swing.JScrollPane;import javax.swing.ListSelectionModel;import javax.swing.event.ListSelectionEvent;import javax.swing.event.ListSelectionListener;//導(dǎo)入自定義Java類庫import hws.item.smart.Smart;import hws.item.smart.misc.ImageShop;import hws.item.smart.misc.PopToolkit;import hws.item.smart.panel.function.chat.misc.BasicInfoPanel;import hws.item.smart.panel.function.chat.misc.OptionalInfoPanel2;import hws.item.smart.utility.chat.UserInfo;/** * 查看好友信息對話框 * * @version 0.1 2005-08-25 * @author Hwerz */public class ViewFriendDialog extends JDialog implements ListSelectionListener { /*------------------------------------------------------------------------* * 屬性定義 * *------------------------------------------------------------------------*/ /** * 基本信息面板 */ private BasicInfoPanel basicInfoPanel; /** * 可選信息面板 */ private OptionalInfoPanel2 optionalInfoPanel; /** * 信息面板 */ private JPanel infoPanel; /** * 信息面板的布局管理器 */ private CardLayout cardLayout; /** * 好友ID */ private String id; /*------------------------------------------------------------------------* * 構(gòu)造函數(shù) * *------------------------------------------------------------------------*/ /** * Create a new instance of this class * * @param user 待查看信息的好友 */ public ViewFriendDialog(UserInfo user) { super(Smart.getInstance(), user.getBasicInfo().getNickname(), true); id = user.getBasicInfo().getID(); Container c = getContentPane(); c.setLayout(new GridBagLayout()); //工具欄面板 GridBagConstraints constraints = new GridBagConstraints( //gridx, gridy 0, 0, //gridwidth, gridheight 1, 1, //weightx, weighty 1.0, 0.0, //anchor GridBagConstraints.NORTH, //fill GridBagConstraints.HORIZONTAL, //insets new Insets(5, 0, 0, 0), //ipadx, ipady 0, 0); c.add(new Toolbar(), constraints); //信息類型列表 String[] types = {"基本信息", "可選信息"}; JList infoTypeList = new JList(types); infoTypeList.setSelectedIndex(0); infoTypeList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); infoTypeList.addListSelectionListener(this); JScrollPane scroller = new JScrollPane(infoTypeList, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); //基本信息面板 basicInfoPanel = new BasicInfoPanel(); basicInfoPanel.setValue(user.getBasicInfo()); //可選信息面板 optionalInfoPanel = new OptionalInfoPanel2(); optionalInfoPanel.setValue(user.getOptionalInfo()); //信息面板 cardLayout = new CardLayout(); infoPanel = new JPanel(cardLayout); infoPanel.add(basicInfoPanel, types[0]); infoPanel.add(optionalInfoPanel, types[1]); //分割條面板 JSplitPane spliter = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, false, scroller, infoPanel); spliter.setOneTouchExpandable(true); spliter.setDividerLocation(150); constraints.gridy = 1; constraints.weighty = 1.0; constraints.fill = GridBagConstraints.BOTH; constraints.insets = new Insets(5, 5, 5, 5); c.add(spliter, constraints); //設(shè)置對話框 setSize(600, 450); setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); PopToolkit.makeWindowCenter(this); } /*------------------------------------------------------------------------* * 實現(xiàn)方法 * *------------------------------------------------------------------------*/ /** * 實現(xiàn)接口ListSelectionListener的方法 * * @param event the event that characterizes the change */ public void valueChanged(ListSelectionEvent event) { String type = ((JList) event.getSource()).getSelectedValue().toString(); cardLayout.show(infoPanel, type); } /*------------------------------------------------------------------------* * 內(nèi)部類 * *------------------------------------------------------------------------*/ /** * 工具欄面板 */ class Toolbar extends JPanel implements ActionListener { /** * Create a new instance of this class */ public Toolbar() { super(new FlowLayout(FlowLayout.CENTER, 5, 0)); //刷新 JButton button = new JButton("刷新", ImageShop.REFRESH_IMAGEICON); button.addActionListener(this); add(button); //關(guān)閉 button = new JButton("關(guān)閉", ImageShop.CANCEL_IMAGEICON); button.addActionListener(this); add(button); } /** * 實現(xiàn)接口ActionListener的方法 * * @param event the event that characterizes the action */ public void actionPerformed(ActionEvent event) { String command = event.getActionCommand(); if (command.equals("刷新") == true) { UserInfo user = UserInfo.getRemoteUserInfo(id); basicInfoPanel.setValue(user.getBasicInfo()); optionalInfoPanel.setValue(user.getOptionalInfo()); } else { ViewFriendDialog.this.dispose(); } } }}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -