第二节 如何创建主窗体
一、创建EQ类
在类中创建窗体对象,为窗体添加选项卡面板,并添加用户列表,系统工具,系统设置三个选项卡和状态栏,标签,公共按钮等属性。关键代码如下:
public class EQ extends Dialog {
private JTextField ipEndTField;
private JTextField ipStartTField;
private JTextField userNameTField;
private JPasswordField passwordTField;
private JTextField placardPathTField;
private JTextField updatePathTField;
private JTextField pubPathTField;
public static EQ frame = null;
private ChatTree chatTree;
private JPopupMenu popupMenu;
private JTabbedPane tabbedPane;
private JToggleButton searchUserButton;
private JProgressBar progressBar;
private JList faceList;
private JButton selectInterfaceOKButton;
private DatagramSocket ss;
private final JLabel stateLabel;
private static String user_dir;
private static File localFile;
private static File netFile;
private String netFilePath;
private JButton messageAlertButton;
private Stack
messageStack;
private ImageIcon messageAlertIcon;
private ImageIcon messageAlertNullIcon;
private Rectangle location;
public static TrayIcon trayicon;
private Dao dao;
public final static Preferences preferences = Preferences.systemRoot();;
private JButton userInfoButton;
二、在构造方法中的相关操作
初始化窗体上的控件,数据库操作类,首选项,另外还要为窗体添加事件,监听器。关键代码如下:
public EQ() {
super(new Frame());
frame = this;
dao = Dao.getDao();
location = dao.getLocation();
setTitle("EQ通讯");
setBounds(location);
progressBar = new JProgressBar();
progressBar.setBorder(new BevelBorder(BevelBorder.LOWERED));
tabbedPane = new JTabbedPane();
popupMenu = new JPopupMenu();
chatTree = new ChatTree(this);
user_dir = System.getProperty("user.dir"); // 程序执行路径用于系统更新
localFile = new File(user_dir + File.separator + "EQ.jar");// 本地EQ文件
stateLabel = new JLabel(); // 状态栏标签
addWindowListener(new FrameWindowListener
上一篇:完美版java毕业设计论文
下一篇:雍志祥_基于Ajax的BBS网站_论文正文