java在线聊天项目 swt可视化窗口Design 重新设计好友列表窗口 增加菜单栏
增加的菜单栏效果图如下:

eclipse 中调整到 swt的design视图下
控件区域选择Menu Controls
将Menu Bar拖动到窗口标题栏
将Cascaded Menu拖动到Menu Bar
依次将多个Menu Item加入到New SubMenu
Separator是分隔符
也可以再放入Cascaded Menu级联菜单
好友列表窗口的代码如下:
package com.swift.frame; import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.EventQueue;
import java.awt.FlowLayout;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent; import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
import javax.swing.JPopupMenu;
import javax.swing.JTabbedPane;
import javax.swing.SwingConstants;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException; public class FriendsDialog extends JDialog { public static void main(String args[]) { JFrame.setDefaultLookAndFeelDecorated(true);
JDialog.setDefaultLookAndFeelDecorated(true); try {
UIManager.setLookAndFeel("javax.swing.plaf.nimbus.NimbusLookAndFeel");
} catch (ClassNotFoundException e1) {
e1.printStackTrace();
} catch (InstantiationException e1) {
e1.printStackTrace();
} catch (IllegalAccessException e1) {
e1.printStackTrace();
} catch (UnsupportedLookAndFeelException e1) {
e1.printStackTrace();
} EventQueue.invokeLater(new Runnable() {
public void run() {
try {
FriendsDialog dialog = new FriendsDialog();
dialog.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
dialog.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
} public FriendsDialog() {
super();
setTitle("飞燕聊天");
setBounds(100, 100, 247, 581); final JPanel panel = new JPanel();
panel.setLayout(new BorderLayout());
getContentPane().add(panel, BorderLayout.NORTH); final JLabel label = new JLabel(new ImageIcon("Images/logo.jpg"));
label.setText("New JLabel");
panel.add(label, BorderLayout.WEST);
label.setPreferredSize(new Dimension(74,74)); final JPanel panel_1 = new JPanel();
panel_1.setLayout(new BorderLayout());
panel.add(panel_1, BorderLayout.CENTER); final JLabel advancingSwiftLabel = new JLabel();
advancingSwiftLabel.setText("Advancing Swift");
panel_1.add(advancingSwiftLabel, BorderLayout.CENTER); final JLabel neverWasterLabel = new JLabel();
neverWasterLabel.setText("Never waste time any more");
panel_1.add(neverWasterLabel, BorderLayout.SOUTH); final JPanel panel_2 = new JPanel();
panel_2.setLayout(new BorderLayout());
getContentPane().add(panel_2, BorderLayout.SOUTH); final JPanel panel_3 = new JPanel();
final FlowLayout flowLayout = new FlowLayout();
flowLayout.setAlignment(FlowLayout.LEFT);
panel_3.setLayout(flowLayout);
panel_2.add(panel_3); final JButton button = new JButton();
panel_3.add(button);
button.setHorizontalTextPosition(SwingConstants.LEFT);
button.setHorizontalAlignment(SwingConstants.LEFT);
button.setText("设置"); final JButton button_1 = new JButton();
panel_3.add(button_1);
button_1.setText("查找"); final JPanel panel_4 = new JPanel();
panel_2.add(panel_4, BorderLayout.EAST); final JButton button_2 = new JButton();
panel_4.add(button_2);
button_2.setText("退出"); final JTabbedPane tabbedPane = new JTabbedPane();
getContentPane().add(tabbedPane, BorderLayout.CENTER); final JPanel panel_5 = new JPanel();
tabbedPane.addTab("好友列表", null, panel_5, null); final JPanel panel_6 = new JPanel();
tabbedPane.addTab("群聊", null, panel_6, null); final JPanel panel_7 = new JPanel();
tabbedPane.addTab("聊天记录", null, panel_7, null); final JMenuBar menuBar = new JMenuBar();
setJMenuBar(menuBar); final JMenu menu = new JMenu();
menu.setText("操作");
menuBar.add(menu); final JMenuItem newItemMenuItem = new JMenuItem();
newItemMenuItem.setText("设置");
menu.add(newItemMenuItem); final JMenuItem newItemMenuItem_1 = new JMenuItem();
newItemMenuItem_1.setText("空间");
menu.add(newItemMenuItem_1); final JMenuItem newItemMenuItem_2 = new JMenuItem();
newItemMenuItem_2.setText("邮箱");
menu.add(newItemMenuItem_2); final JMenu menu_1 = new JMenu();
menu_1.setText("会员");
menu.add(menu_1); final JMenuItem newItemMenuItem_3 = new JMenuItem();
newItemMenuItem_3.setText("会员官网");
menu_1.add(newItemMenuItem_3); final JMenuItem newItemMenuItem_4 = new JMenuItem();
newItemMenuItem_4.setText("会员专区");
menu_1.add(newItemMenuItem_4); menu.addSeparator(); final JMenu menu_2 = new JMenu();
menu_2.setText("安全");
menu.add(menu_2); final JMenuItem newItemMenuItem_5 = new JMenuItem();
newItemMenuItem_5.setText("紧急冻结");
menu_2.add(newItemMenuItem_5); final JMenuItem newItemMenuItem_6 = new JMenuItem();
newItemMenuItem_6.setText("密码保护");
menu_2.add(newItemMenuItem_6); final JMenuItem newItemMenuItem_7 = new JMenuItem();
newItemMenuItem_7.setText("退出");
menu.add(newItemMenuItem_7);
final FlowLayout flowLayout_1 = new FlowLayout();
flowLayout_1.setAlignment(FlowLayout.RIGHT);
} /**
* WindowBuilder generated method.<br>
* Please don't remove this method or its invocations.<br>
* It used by WindowBuilder to associate the {@link javax.swing.JPopupMenu} with parent.
*/
private static void addPopup(Component component, final JPopupMenu popup) {
component.addMouseListener(new MouseAdapter() {
public void mousePressed(MouseEvent e) {
if (e.isPopupTrigger())
showMenu(e);
}
public void mouseReleased(MouseEvent e) {
if (e.isPopupTrigger())
showMenu(e);
}
private void showMenu(MouseEvent e) {
popup.show(e.getComponent(), e.getX(), e.getY());
}
});
}
}
java在线聊天项目 swt可视化窗口Design 重新设计好友列表窗口 增加菜单栏的更多相关文章
- java在线聊天项目 swt可视化窗口Design 好友列表窗口
熟练使用各种布局方式 FlowLayout 流布局 left center right等 BorderLayout 边框布局 east west sorth north center Absolute ...
- java在线聊天项目 swt可视化窗口Design 登录框注册按钮点击改变窗口大小——出现注册面板 实现打开登录框时屏幕居中
登录框注册按钮点击改变窗口大小——出现注册面板 首先用swt可视化设计登录窗口如下图: 此时窗口高度为578 没点击注册时高度为301(可自己定) 注意:注册用户的Jpanel 的border选择T ...
- java在线聊天项目 swt可视化窗口Design 重新设计聊天窗口
设计的聊天窗口如下: 制作过程: 首先,在默认的BorderLayout视图下, 上边也就是North处添加一个JPanel,将Layout调整为BorderLayout,West放一个JLabel用 ...
- java在线聊天项目 实现基本聊天功能后补充的其他功能详细需求分析 及所需要掌握的Java知识基础 SWT的激活方法,swt开发包下载,及破解激活码
补充聊天项目功能,做如下需求分析: 梳理项目开发所需的必要Java知识基础 GUI将使用更快速的swt实现 SWT(Standard Widget Toolkit) Standard Widget T ...
- java在线聊天项目 客户端登陆窗口LoginDialog的注册用户功能 修改注册逻辑 增空用户名密码的反馈 增加showMessageDialog()提示框
LoginDialog类的代码修改如下: package com.swift.frame; import java.awt.EventQueue; import java.awt.event.Acti ...
- java在线聊天项目0.9版 实现把服务端接收到的信息返回给每一个客户端窗口中显示功能之客户端接收
客户端要不断接收服务端发来的信息 与服务端不断接收客户端发来信息相同,使用线程的方法,在线程中循环接收 客户端修改后代码如下: package com.swift; import java.awt.B ...
- java在线聊天项目0.4版本 制作服务端接收连接,客户端连接功能 新增客户端窗口打开时光标指向下边文本域功能,使用WindowListener监听WindowAdapter
建一个服务端类ChatServer,用于设置端口接收连接 package com.swift; import java.io.IOException; import java.net.ServerSo ...
- java在线聊天项目1.1版 ——开启多个客户端,分别实现注册和登录功能,使用客户端与服务端信息request机制,重构线程,将单独的登录和注册线程合并
实现效果图: eclipse项目中初步整合之前的各个客户端和服务端的窗口与工具类,效果如下图: 已将注册服务器线程RegServer功能放到LoginServer中,使用客户端与服务端的request ...
- java在线聊天项目1.3版 ——设计好友列表框功能
设计好友列表框功能,思路—— 1.当客户端成功登陆后,则客户端把成功登陆信息发送给服务端, 2.由服务端将接收到来自各个成功登陆的客户端的用户信息添加进好友列表, 3.每当有成功登陆的用户就向各个客户 ...
随机推荐
- CentOS Linux 7 提示 lsof: 未找到命令
我们常使用 lsof -i:端口号 命令来查看某端口是否开放,如使用下面的命令,查看8080端口: lsof -i: 结果: 提示:lsof:未找到命令 解决办法 使用yum来安装lsof,命令如下: ...
- Levenberg-Marquardt
c++ opencv L-M源码 http://www.shenlejun.cn/article/show.asp?id=97 什么是最优化,可分为几大类? 答:Levenberg-Marquardt ...
- c#二维数组传递与拷贝
定义 string[,] arr = new string[12, 31] 另一种string[][] ary = new string[5][];相当于一维数组 常量二维数组定义, 用readonl ...
- uoj#282. 长度测量鸡(构造)
传送门 打表题--只有\(n\leq 3\)有解否则无解→_→ 或者严格证明的话是这样,因为算上端点一共\(n+1\)个点,共\(\frac{n(n+1)}{2}\)个点对,所以点对之间两两距离不相等 ...
- [Xcode 实际操作]一、博主领进门-(12)代码重构
目录:[Swift]Xcode实际操作 本文将演示如何重构代码. 在项目导航区,打开视图控制器的代码文件[ViewController.swift] [快速更改同名变量或常量] 在代码编辑区域,点击需 ...
- vim 快速定位到文件末尾、头部
gg : 跳转到文件头 Shift+g : 跳转到文件末尾 行数+gg : 跳转到指定行,例跳转到123行:123gg
- ISCC 2018线上赛 writeup
今天有机会去ISCC2018参加了比赛,个人的感受是比赛题目整体难度不高,就是脑洞特别大,flag形式不明确,拿到flag后也要猜测flag格式,贼坑 废话不多说,以下是本人的解题思路 MISC 0x ...
- python异常之ModuleNotFoundError: No module named 'test01inner02'
当我们使用sys.path.append(args) 指令向程序中导入模块时其实本次append操作只是在内存中完成的,如果要永久性的添加需要修改环境变量. 我们发现当我们使用print(sys.pa ...
- 页面嵌套时js失效解决方法
事件:iframe或easyui的dialog嵌套页面时,被嵌套的页面可能js因位置失效; 解决: //动态加载js(根据父级html位置计算) jQuery.getScript("scri ...
- 洛谷 P4092 [HEOI2016/TJOI2016]树 || bzoj4551
https://www.lydsy.com/JudgeOnline/problem.php?id=4551 https://www.luogu.org/problemnew/show/P4092 这当 ...