社区
Java SE
帖子详情
用swing 做个增加用户界面
tangtoyin06
2009-12-29 12:38:34
想用swing做一个比较漂亮的增加用户/修改用户的界面。需要增加的属性就我自己定了。
...全文
352
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)
第七讲
Swing
用户界面
设计
7.1
Swing
简介 7.1.1 简介 第五讲中我们学习了AWT,AWT是
Swing
的基础。
Swing
的产生主要原因就是AWT不能满足图形化
用户界面
发展的需要。AWT设计的初衷是支持开发小应用程序的简单
用户界面
。例如AWT缺少剪贴板、打印支持、键盘导航等特性,而且原来的AWT甚至不包括弹出式菜单或滚动窗格等基本元素。 此外AWT还存在着严重的缺陷,人们使AWT适应基于继承的、具有很大伸
java中 基于
swing
的图形
用户界面
设计_java中基于
swing
的图形
用户界面
设计
java中基于
swing
的图形
用户界面
设计 * 1第 10章 基于
Swing
的图形
用户界面
设计本章导读 AWT组件与
SWING
组件 JFrame窗体、菜单组件、布局设计 中间容器、文本组件 按钮与标签组件、复选框与单选按钮组件 列表组件、表格组件、树组件和进度条组件 窗口事件、鼠标事件、焦点事件和键盘事件 对话框 AWT线程与计时器 MVC设计模式 发布应用程序* 210.1 AWT组件与 ...
如何在Java中实现高效的图形
用户界面
:从
Swing
到JavaFX
对于新的项目,JavaFX是一个更现代和功能丰富的选择,而对于现有的
Swing
项目,逐步迁移到JavaFX可以为应用程序带来更好的用户体验和性能优化。
Swing
是Java Foundation Classes(JFC)的一部分,提供了丰富的GUI组件库,如按钮、文本框、列表等。在这个示例中,我们创建了一个基本的
Swing
窗口,并在窗口中添加了一个按钮。在这个示例中,当用户点击按钮时,将弹出一个信息对话框。将一个
Swing
按钮嵌入到JavaFX应用程序中,这使得从
Swing
到JavaFX的过渡变得更加平滑。
6 Java
Swing
用户界面
组件
由于本节博客是讲Java里面的
Swing
里面的gui编程,但现在gui的环境大家也知道。并且Java本身在gui编程的选择上Java算是已经完全放弃这一块(Java的优势主要在于web开发),就留下了一个比较难用的
Swing
,Python好歹还有pyqt这些大型的qt开发框架。所以本文我们不会对
Swing
做一个过多的详细介绍。只会以一个实际的拼图小游戏项目来简单用用
Swing
的一些常用组件。建议学完Java的字典集合的api使用还有Java文件操作再来看这个。
IDEA如何使用
Swing
构建
用户界面
IntelliJ IDEA的 UI Designer插件使您可以使用
Swing
库组件为您的应用程序创建图形
用户界面
(GUI)。使用 UI Designer,您可以快速创建在顶层容器中使用的对话框和控件组,例如 JFrame。这些元素可以与您直接在 Java 代码中定义的组件共存。在本教程中,您将学习使用 UI Designer 的基础知识,并尝试为示例应用程序创建自己的 GUI 表单。作为练习,我们将构建一个图形
用户界面
表单,用于编辑有关书籍的信息,例如书名、作者、类型和可用状态。
Java SE
62,620
社区成员
307,251
社区内容
发帖
与我相关
我的任务
Java SE
Java 2 Standard Edition
复制链接
扫一扫
分享
社区描述
Java 2 Standard Edition
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
暂无公告
试试用AI创作助手写篇文章吧
+ 用AI写文章