java在线聊天项目 swt可视化窗口Design 好友列表窗口
熟练使用各种布局方式
FlowLayout 流布局 left center right等
BorderLayout 边框布局 east west sorth north center
AbsoluteLayout 绝对布局或空布局 任意拖拽
可以使用各种布局的嵌套效果,达到需要的目标
布局后可以在基本布局基础上添加新的JPanel,然后设置JPanel新的布局方式
制作好友列表窗口
首先,设置总的布局方式为 BorderLayout
上边放用户的图标,用户名和用户的名言,然后左边添加JLable
JLable lable=new JLable(new ImageIcon("Images/logo.jpg"));
添加图片
label.setPreferredSize(new Dimension(74,74));
设置标签尺寸
先添加一个JPanel,使用BorderLayout
下边放三个按钮,
先添加一个JPanel,使用BorderLayout,然后左边添加JPanel使用FlowLayout布局,右边添加JPanel使用BorderLayout布局
左边布局添加两个按钮,设置axis为left
右边布局添加一个按钮,放到east
中间放一个选项卡
选项卡 JTabbedPane ,然后在其上添加3个JPanel,
分别命名为好友列表 群聊 会话
好友列表窗口效果图如下:

为该窗口设置皮肤
JFrame.setDefaultLookAndFeelDecorated(true);
JDialog.setDefaultLookAndFeelDecorated(true);
UIManager.setLookAndFeel("javax.swing.plaf.nimbus.NimbusLookAndFeel");
该窗口全部代码如下:
package com.swift; import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.EventQueue;
import java.awt.FlowLayout;
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.JPanel;
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) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (InstantiationException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (IllegalAccessException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (UnsupportedLookAndFeelException e1) {
// TODO Auto-generated catch block
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 FlowLayout flowLayout_1 = new FlowLayout();
flowLayout_1.setAlignment(FlowLayout.RIGHT);
} }
java在线聊天项目 swt可视化窗口Design 好友列表窗口的更多相关文章
- java在线聊天项目 swt可视化窗口Design 重新设计好友列表窗口 增加菜单栏
增加的菜单栏效果图如下: eclipse 中调整到 swt的design视图下 控件区域选择Menu Controls 将Menu Bar拖动到窗口标题栏 将Cascaded Menu拖动到Menu ...
- java在线聊天项目 swt可视化窗口Design 登录框注册按钮点击改变窗口大小——出现注册面板 实现打开登录框时屏幕居中
登录框注册按钮点击改变窗口大小——出现注册面板 首先用swt可视化设计登录窗口如下图: 此时窗口高度为578 没点击注册时高度为301(可自己定) 注意:注册用户的Jpanel 的border选择T ...
- java在线聊天项目1.3版 ——设计好友列表框功能
设计好友列表框功能,思路—— 1.当客户端成功登陆后,则客户端把成功登陆信息发送给服务端, 2.由服务端将接收到来自各个成功登陆的客户端的用户信息添加进好友列表, 3.每当有成功登陆的用户就向各个客户 ...
- java在线聊天项目1.3版设计好友列表框功能补充,因只要用户登录就发送一串新列表,导致不同客户端好友列表不同问题
解决完毕后效果图: 好友列表Vector添加的时候进行判断,如果有相同的则不添加 int flag=0; for (int i = 0; i < names.size(); i++) { if ...
- 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在线聊天项目1.1版 ——开启多个客户端,分别实现注册和登录功能,使用客户端与服务端信息request机制,重构线程,将单独的登录和注册线程合并
实现效果图: eclipse项目中初步整合之前的各个客户端和服务端的窗口与工具类,效果如下图: 已将注册服务器线程RegServer功能放到LoginServer中,使用客户端与服务端的request ...
- java在线聊天项目1.2版 ——开启多个客户端,分别实现数据库注册和登录功能后,成功登陆则登录框消失,好友列表窗出现
登录框消失语句 dispose(); 好友列表窗出现 使用new FriendsFrame(phone,s); 登陆对话框代码修改如下: package com.swift.frame; import ...
随机推荐
- PHP保留小数的相关方法
结合一下网上的例子 $num = 10.4567; //第一种:利用round()对浮点数进行四舍五入 但是这个如果没有两位小数也不会"两位精度" echo round($num, ...
- wordcloud 的常规方法
wordcloud 库把词云当作一个WordCloud对象 ——wordcloud.WordCloud() 代表一个文本对应的词云 ——可以根据文本中词语出现的频率等参数绘制词云 ——绘制词云的形状. ...
- SpringBoot | Data Access
https://docs.spring.io/spring-boot/docs/current/reference/html/howto-data-access.html 配置数据源启动器.
- 最短路之Floyd(多源)HDU 1874
#include <iostream> #include <cstdio> #include <cstring> using namespace std; #def ...
- dubbo与springboot的三种整合方式
SpringBoot与dubbo整合的三种方式:1.导入dubbo-starter,在application.properties配置属性,使用@Service暴露服务,使用@Reference引用服 ...
- HDU 5869 Different GCD Subarray Query 树状数组 + 一些数学背景
http://acm.hdu.edu.cn/showproblem.php?pid=5869 题意:给定一个数组,然后给出若干个询问,询问[L, R]中,有多少个子数组的gcd是不同的. 就是[L, ...
- Java方式配置Spring MVC
概述 使用Java方式配置Spring MVC,以及回顾一下Spring MVC的各种用法. Spring MVC简述 关于Spring MVC的介绍网上有很多,这里就不再赘述了,只是要说一下,Spr ...
- WebForm随笔
一般处理程序中获取页面所传的值:int id = Convert.ToInt32(context.Request["id"]); 后台获取页面所传的值:int id = Conve ...
- .aspx IIS发布404.17时候的问题
.aspx IIS发布404.17时候的问题 在发布aspx的时候遇到问题利用网上的cmd加入注册表没有效果 在加入了MIME中加入.aspx和application/.aspx之后却变成了下载文件 ...
- CF1060D Social Circles
思路: 贪心.既然每个人的左边是其他人的右边,每个人的右边是其他人的左边,那么使重叠的部分最多即可. 实现: #include <bits/stdc++.h> using namespac ...