用swing 做个增加用户界面 想用swing做一个比较漂亮的增加用户/修改用户的界面。需要增加的属性就我自己定了。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 觉得java自身不擅长于编写界面。在没有美工支持下,更难做出漂亮的界面。 布局做出来美观整洁就不错了。 ls 定义的是界面风格。 整体的布局还是自己写写吧。只有自己才知道想要怎么样的效果。如果不会使用布局管理器,就将布局管理器设置为null,然后自己设置组件的大小和位置。可以使用netbean或者jbuilder进行swing界面的编写,因为可以直接拖动组件会比较方便。 SWING很难做漂亮的!用setLookAndFeel方法是可行的!用SWT/JFACE吧!!!!!!! 想好看,用用swing的ui框架,例如swingX等等 myeclipse中有swing的图形编辑窗口,编辑好直接有代码。。 O'Reilly:Java Swing(第二版)Java Swing,Second Edition 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); }} 这只是没修饰过的界面,如果图片做的好,界面就可以很漂亮。可以把图片路径塞给上面代码里的File构造函数。 swing漂亮到挺郁闷你看oracle的界面 难看死了!哎 悲哀! 关键字 native 一段java代码,编译能行,但是运行的时候就出现一些问题代码。把鼠标点击事件里的循环注掉就没事。请各位好心大侠指导下,谢谢 关于计算机 维护 书籍 如何去掉JButton文字周围的线框 请前辈 指点 如何知道某个函数被调用了! 关于servlet连接数据库的问题 求救~两长整型日期求相差多少天~ 想了一天一夜也想不明白。高手指教!!! java 做服务器时,可以向C SOCKET发送,也可以接收C来的数据,但C做服务器时,不行 初学socket,客户端不能接收到服务端的消息 匹配固定字符开头,固定字符结尾的正则表达式写法
布局做出来美观整洁就不错了。
整体的布局还是自己写写吧。只有自己才知道想要怎么样的效果。
如果不会使用布局管理器,就将布局管理器设置为null,然后自己设置组件的大小和位置。
可以使用netbean或者jbuilder进行swing界面的编写,因为可以直接拖动组件会比较方便。
用SWT/JFACE吧!!!!!!!
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);
}
}
你看oracle的界面 难看死了!
哎 悲哀!