📄 viewfrienddialog.java
字号:
/* * @(#) ViewFriendDialog.java * Copyright 2004 HWStudio. All rights reserved. */package hws.item.smart.dialog;//导入核心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;//导入自定义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; /*------------------------------------------------------------------------* * 构造函数 * *------------------------------------------------------------------------*/ /** * 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); //设置对话框 setSize(600, 450); setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); PopToolkit.makeWindowCenter(this); } /*------------------------------------------------------------------------* * 实现方法 * *------------------------------------------------------------------------*/ /** * 实现接口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); } /*------------------------------------------------------------------------* * 内部类 * *------------------------------------------------------------------------*/ /** * 工具栏面板 */ 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); //关闭 button = new JButton("关闭", ImageShop.CANCEL_IMAGEICON); button.addActionListener(this); add(button); } /** * 实现接口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(); } } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -