use a great layout or a form framework is a better choice. please take a look at http://www.jgoodies.com/ http://forms.dev.java.net/ i like all write by hand.
强烈推荐NetBeansIDE 3.4或Forte for java.分别在www.netbeans.org和www.sun.com上有下载.告诉我你的邮箱,我把我做的swing界面给你看看,用netBeans做的. 楼上的我不大同意那是"一场恶梦",要看是使用什么工具了,用JB那才真是一场恶梦
以下是用netBeans生成的的JFrame代码,大家看看吧: /* * test.java * * Created on 2003年6月11日, 下午9:27 */package com.Sky.yunjiu.main;import javax.swing.JInternalFrame; import javax.swing.plaf.basic.BasicInternalFrameUI; import javax.swing.JComponent; import java.awt.Color; import javax.swing.BorderFactory; import javax.swing.JDesktopPane;/** * * @author sky */ public class test extends javax.swing.JFrame {
/** Creates new form test */ ItfWastPane wp; InternalFrameUI ifu; public test () { initComponents (); ItfNEastPane neastPane = new ItfNEastPane(); InfoPaneTitleBarUI neast = new InfoPaneTitleBarUI(neastPane); neastPane.setUI (neast); p1.add(neastPane, JDesktopPane.MODAL_LAYER); neastPane.setVisible(true); neastPane.setLocation (0,0); }
/** This method is called from within the constructor to * initialize the form. * WARNING: Do NOT modify this code. The content of this method is * always regenerated by the Form Editor. */ private void initComponents() { p1 = new javax.swing.JDesktopPane(); jButton1 = new javax.swing.JButton(); lb = new javax.swing.JLabel(); cb = new javax.swing.JComboBox(); getContentPane().setLayout(null); addWindowListener(new java.awt.event.WindowAdapter() { public void windowOpened(java.awt.event.WindowEvent evt) { formWindowOpened(evt); } public void windowClosing(java.awt.event.WindowEvent evt) { exitForm(evt); } }); getContentPane().add(p1); p1.setBounds(0, 0, 570, 340); jButton1.setText("jButton1"); jButton1.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton1ActionPerformed(evt); } }); getContentPane().add(jButton1); jButton1.setBounds(60, 400, 83, 28); pack(); java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize(); setSize(new java.awt.Dimension(570, 445)); setLocation((screenSize.width-570)/2,(screenSize.height-445)/2); } private void formWindowOpened (java.awt.event.WindowEvent evt) { } private void jButton1ActionPerformed (java.awt.event.ActionEvent evt) { }
/** * @param args the command line arguments */ public static void main (String args[]) { // System.out.println(javax.swing.UIManager.getString("InternalFrameTitlePane.sizeButtonText")); new test ().show (); }
// Variables declaration - do not modify private javax.swing.JButton jButton1; private javax.swing.JDesktopPane p1; private javax.swing.JLabel lb; private javax.swing.JComboBox cb; // End of variables declaration
please take a look at
http://www.jgoodies.com/
http://forms.dev.java.net/
i like all write by hand.
用这些GUI的设计工具生成的代码确实比较难读。
现在发现其实根本没有必要去经常看那些代码,只要你控件命名比较规范
可读性不是问题,毕竟项目中效率第一.
不过用Swing开发图形界面真是一场恶梦啊.....
楼上的我不大同意那是"一场恶梦",要看是使用什么工具了,用JB那才真是一场恶梦
/*
* test.java
*
* Created on 2003年6月11日, 下午9:27
*/package com.Sky.yunjiu.main;import javax.swing.JInternalFrame;
import javax.swing.plaf.basic.BasicInternalFrameUI;
import javax.swing.JComponent;
import java.awt.Color;
import javax.swing.BorderFactory;
import javax.swing.JDesktopPane;/**
*
* @author sky
*/
public class test extends javax.swing.JFrame
{
/** Creates new form test */
ItfWastPane wp;
InternalFrameUI ifu; public test ()
{
initComponents ();
ItfNEastPane neastPane = new ItfNEastPane();
InfoPaneTitleBarUI neast = new InfoPaneTitleBarUI(neastPane);
neastPane.setUI (neast);
p1.add(neastPane, JDesktopPane.MODAL_LAYER);
neastPane.setVisible(true);
neastPane.setLocation (0,0);
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
private void initComponents()
{
p1 = new javax.swing.JDesktopPane();
jButton1 = new javax.swing.JButton();
lb = new javax.swing.JLabel();
cb = new javax.swing.JComboBox(); getContentPane().setLayout(null); addWindowListener(new java.awt.event.WindowAdapter()
{
public void windowOpened(java.awt.event.WindowEvent evt)
{
formWindowOpened(evt);
}
public void windowClosing(java.awt.event.WindowEvent evt)
{
exitForm(evt);
}
}); getContentPane().add(p1);
p1.setBounds(0, 0, 570, 340); jButton1.setText("jButton1");
jButton1.addActionListener(new java.awt.event.ActionListener()
{
public void actionPerformed(java.awt.event.ActionEvent evt)
{
jButton1ActionPerformed(evt);
}
}); getContentPane().add(jButton1);
jButton1.setBounds(60, 400, 83, 28); pack();
java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
setSize(new java.awt.Dimension(570, 445));
setLocation((screenSize.width-570)/2,(screenSize.height-445)/2);
} private void formWindowOpened (java.awt.event.WindowEvent evt)
{ } private void jButton1ActionPerformed (java.awt.event.ActionEvent evt)
{ }
/** Exit the Application */
private void exitForm (java.awt.event.WindowEvent evt)
{
System.exit (0);
}
/**
* @param args the command line arguments
*/
public static void main (String args[])
{
// System.out.println(javax.swing.UIManager.getString("InternalFrameTitlePane.sizeButtonText"));
new test ().show ();
}
// Variables declaration - do not modify
private javax.swing.JButton jButton1;
private javax.swing.JDesktopPane p1;
private javax.swing.JLabel lb;
private javax.swing.JComboBox cb;
// End of variables declaration
}在该环境下一目了然,不信可下载来试试.免费的啊-:)
[email protected]
找到窍门做UI小菜啊 :) ,
然后又想设置按钮大小,找了老半天没找到,放弃,然后又将刚才的按钮所在Panele 的Layout为Null,按钮消失后在控件列表中点击该按钮,界面一点反应也没有,而JB会显示出按钮的可拖动边框...感觉易用性和直观性稍差.至于Mac界面似乎是Look&Feel范畴了,实时加背景在项目进行中也没大用.生成的界面美观与否
更要看设计者的素质.到了生成类的问题比较简单,在事件较多的界面中维护那么多的类就是一场恶梦. 以上观点敬请指正,由于时间不多没有来得及体会Netbean的优点还请见谅.
JB也可以用点的,你没试过吗??点在左下角的控件列表栏里。
呵呵不过去试用了一下netbeans,觉得是比较好,以后有不懂的要教我啊。
按钮直接就不见了,且从控件列表选中也看不见。
另外我们做UI是很复杂的,一般都是用XYLayout来做界面雏形,然
后转为GridbagLayout再做精细调整,如果象上面这种情形就很困难了。
还有就是控件对齐功能,这点JB还是很体贴的。
不知道netbean还有什么体贴的特性?
其实jb做界面还可以,不过我不喜欢它生成的代码,太乱!你觉得呢?
Delphi 界面好看是与具体的平台有关。