社区
Java SE
帖子详情
用swing 做个增加用户界面
tangtoyin06
2009-12-29 12:38:34
想用swing做一个比较漂亮的增加用户/修改用户的界面。需要增加的属性就我自己定了。
...全文
351
23
打赏
收藏
用swing 做个增加用户界面
想用swing做一个比较漂亮的增加用户/修改用户的界面。需要增加的属性就我自己定了。
复制链接
扫一扫
分享
转发到动态
举报
写回复
配置赞助广告
用AI写文章
23 条
回复
切换为时间正序
请发表友善的回复…
发表回复
打赏红包
zhaining522
2009-12-31
打赏
举报
回复
swing漂亮到挺郁闷
你看oracle的界面。。。 难看死了!
哎 悲哀!
py330316117
2009-12-31
打赏
举报
回复
还真不会美化界面
huangwj20042008
2009-12-31
打赏
举报
回复
这只是没修饰过的界面,如果图片做的好,界面就可以很漂亮。可以把图片路径塞给上面代码里的File构造函数。
网站推广优化yetaoaiueo
2009-12-31
打赏
举报
回复
19楼的楼主试试
huangwj20042008
2009-12-31
打赏
举报
回复
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Container;
import java.awt.FlowLayout;
import java.awt.Graphics;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Image;
import java.awt.Insets;
import java.io.File;
import javax.imageio.ImageIO;
import javax.swing.BorderFactory;
import javax.swing.Box;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
public class UserDialog extends JFrame{
private JLabel nameLbl = new JLabel("Name:");
private JLabel passwordLbl = new JLabel("Password:");
private JLabel confirmPwdLbl = new JLabel("Confirm Password:");
private JTextField nameField = new JTextField();
private JTextField passwordField = new JTextField();
private JTextField confirmPwdField = new JTextField();
private JButton confirmBtn = new JButton("Confirm");
private JButton cancelBtn = new JButton("Cancel");
public UserDialog(String title){
super(title);
initComponents();
}
public void initComponents(){
Image backgroundImage = null;
try{
backgroundImage = ImageIO.read(new File(""));
}catch(Exception ex){
}
JPanel mainPanel = new BackgroundPanel(backgroundImage);
Color backgroundColor = this.getBackground();
mainPanel.setBackground(backgroundColor);
mainPanel.setLayout(new BorderLayout());
mainPanel.setBorder(BorderFactory.createEmptyBorder(0,0,0,0));
GridBagLayout gridBagLayout = new GridBagLayout();
GridBagConstraints constraints = new GridBagConstraints();
JPanel centerPanel = new JPanel();
centerPanel.setBackground(backgroundColor);
centerPanel.setLayout(gridBagLayout);
centerPanel.setBorder(BorderFactory.createEmptyBorder(5,10,5,5));
constraints.fill = GridBagConstraints.BOTH;
constraints.insets = new Insets(5,10,5,5);
gridBagLayout.setConstraints(nameLbl, constraints);
centerPanel.add(nameLbl);
constraints.weightx = 1.0;
constraints.gridwidth = GridBagConstraints.REMAINDER;
gridBagLayout.setConstraints(nameField, constraints);
centerPanel.add(nameField);
constraints.gridwidth = GridBagConstraints.RELATIVE;
constraints.weightx = 0.0;
gridBagLayout.setConstraints(passwordLbl, constraints);
centerPanel.add(passwordLbl);
constraints.weightx = 1.0;
constraints.gridwidth = GridBagConstraints.REMAINDER;
gridBagLayout.setConstraints(passwordField, constraints);
centerPanel.add(passwordField);
constraints.gridwidth = GridBagConstraints.RELATIVE;
constraints.weightx = 0.0;
gridBagLayout.setConstraints(confirmPwdLbl, constraints);
centerPanel.add(confirmPwdLbl);
constraints.weightx = 1.0;
constraints.gridwidth = GridBagConstraints.REMAINDER;
gridBagLayout.setConstraints(confirmPwdField, constraints);
centerPanel.add(confirmPwdField);
mainPanel.add(centerPanel,BorderLayout.CENTER);
JPanel southPanel = new JPanel();
southPanel.setBackground(backgroundColor);
southPanel.setLayout(new FlowLayout(FlowLayout.CENTER,0,0));
southPanel.setBorder(BorderFactory.createEmptyBorder(5,10,20,10));
southPanel.add(confirmBtn);
southPanel.add(Box.createHorizontalStrut(30));
southPanel.add(cancelBtn);
mainPanel.add(southPanel,BorderLayout.SOUTH);
Container c = this.getContentPane();
c.setLayout(new BorderLayout());
c.add(mainPanel,BorderLayout.CENTER);
}
class BackgroundPanel extends JPanel{
private Image backgroundImage;
public BackgroundPanel(Image image){
this.backgroundImage = image;
}
public void paintComponent(Graphics g){
int w = this.getWidth();
int h = this.getHeight();
g.setColor(this.getBackground());
g.fillRect(0, 0, w, h);
if(backgroundImage != null){
g.drawImage(backgroundImage, 0, 0, w, h, null);
}
}
}
public static void main(String[] args){
JFrame userDialog = new UserDialog("User Dialog");
userDialog.setBounds(200, 100, 300, 400);
userDialog.setDefaultCloseOperation(JDialog.EXIT_ON_CLOSE);
userDialog.setVisible(true);
}
}
bobo364
2009-12-31
打赏
举报
回复
[Quote=引用 17 楼 nihaozhangchao 的回复:]
O'Reilly:Java Swing(第二版)Java Swing,Second Edition
[/Quote]
顶
SambaGao
2009-12-31
打赏
举报
回复
O'Reilly:Java Swing(第二版)Java Swing,Second Edition
javahuazai
2009-12-31
打赏
举报
回复
做做看!
zhuyouyong
2009-12-31
打赏
举报
回复
怎么才叫漂亮
dajiadebeibei9
2009-12-29
打赏
举报
回复
setLookAndFeel
tangtoyin06
2009-12-29
打赏
举报
回复
只要不是很乱就行...
JamnyXie
2009-12-29
打赏
举报
回复
觉得java自身不擅长于编写界面。在没有美工支持下,更难做出漂亮的界面。
布局做出来美观整洁就不错了。
[Quote=引用 1 楼 healer_kx 的回复:]
怎么算是漂亮啊?
[/Quote]
healer_kx
2009-12-29
打赏
举报
回复
怎么算是漂亮啊?
hwlhwj
2009-12-29
打赏
举报
回复
楼上所说的是最快速的办法了。
teemai
2009-12-29
打赏
举报
回复
myeclipse中有swing的图形编辑窗口,编辑好直接有代码。。
jciv002
2009-12-29
打赏
举报
回复
整洁 点好
realreachard
2009-12-29
打赏
举报
回复
想好看,用用swing的ui框架,例如swingX等等
whereusejava
2009-12-29
打赏
举报
回复
别想啊,动手做吧
luffyke
2009-12-29
打赏
举报
回复
SWING很难做漂亮的!用setLookAndFeel方法是可行的!
用SWT/JFACE吧!!!!!!!
njj0125
2009-12-29
打赏
举报
回复
dingdingdingdingdingdingdingdingding
加载更多回复(3)
JAVA——界面设计
Swing
教程
本文深入探讨了Java
Swing
库在跨平台UI设计中的应用,详细介绍了
Swing
与AWT的区别,以及如何使用
Swing
创建图形
用户界面
,包括窗口创建、布局管理器的使用等关键概念。
第七讲
Swing
用户界面
设计
本文详细介绍了
Swing
作为AWT的扩展,提供轻量级组件和丰富的特性,如MVC架构、可插入外观、键盘操作支持和多样化组件。
Swing
组件以'J'开头,包括按钮、标签等,并支持图标和文本。文章通过代码示例展示了
Swing
组件的使用,如JButton和JLabel,并讲解了
Swing
程序设计的基本规则和组件分类。同时,讨论了
Swing
中的布局管理器,如BoxLayout,以及如何设置和管理组件。
java中 基于
swing
的图形
用户界面
设计_java中基于
swing
的图形
用户界面
设计
本文介绍Java
Swing
库用于创建图形
用户界面
的基本概念和技术细节,包括组件、容器、菜单、事件处理等核心元素。
Java的UI设计——
Swing
组件(基础向)
本文介绍如何使用Java
Swing
组件设计基本的
用户界面
,包括创建JFrame窗口、添加JLabel标签和JButton按钮,并设置布局管理器。
如何在Java中实现高效的图形
用户界面
:从
Swing
到JavaFX
本文探讨如何在Java中实现高效的图形
用户界面
,介绍了
Swing
和JavaFX两种工具。阐述了它们的基本结构、事件处理机制,对比了二者在UI设计、性能、社区和库支持方面的差异,还给出从
Swing
迁移到JavaFX的方法,助开发者按需选择。
Java SE
62,621
社区成员
307,251
社区内容
发帖
与我相关
我的任务
Java SE
Java 2 Standard Edition
复制链接
扫一扫
分享
社区描述
Java 2 Standard Edition
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
暂无公告
试试用AI创作助手写篇文章吧
+ 用AI写文章