我想用JAVA做一个不规则的登陆界面,JAVA默认出现的窗口都是矩形?能不能改啊。请给出详细的方法哈

答案好的话,追加高分哈~
我说的是,不象QQ的登陆界面一样是个矩形,我想要那种多边形的

public class OpaqueFrame extends JFrame {

OpaqueFrame() {
setDefaultCloseOperation(3);
setUndecorated(true);
final ImageIcon image = new javax.swing.ImageIcon("C:\\Documents and Settings\\admin\\桌面\\c2cec3fd57d8b810d7887d54.jpg");
JLabel label = new JLabel() {

@Override
public void paint(Graphics g) {
image.paintIcon(this, g, 0, 0);
super.paint(g);
}
};
this.init(label);
label.setSize(image.getIconWidth(), image.getIconHeight());
label.setOpaque(false);
getContentPane().add(label, BorderLayout.CENTER);
setSize(image.getIconWidth(), image.getIconHeight());
AWTUtilities.setWindowOpaque(this, false);
setLocationRelativeTo(null);
}

private void init(JComponent com) {
java.awt.GridBagConstraints gridBagConstraints;

JLabel jLabel1 = new javax.swing.JLabel();
JTextField jTextField1 = new javax.swing.JTextField();
JLabel jLabel2 = new javax.swing.JLabel();
JPasswordField jPasswordField1 = new javax.swing.JPasswordField();
JButton jButton1 = new javax.swing.JButton();
JButton jButton2 = new javax.swing.JButton();

com.setName("Form"); // NOI18N
com.setLayout(new java.awt.GridBagLayout());

jLabel1.setText("用户名");
jLabel1.setName("jLabel1"); // NOI18N
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 0;
gridBagConstraints.gridy = 0;
gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
com.add(jLabel1, gridBagConstraints);

jTextField1.setText(""); // NOI18N
jTextField1.setName("jTextField1"); // NOI18N
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 1;
gridBagConstraints.gridy = 0;
gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
com.add(jTextField1, gridBagConstraints);

jLabel2.setText("密码");
jLabel2.setName("jLabel2"); // NOI18N
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 0;
gridBagConstraints.gridy = 1;
gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
com.add(jLabel2, gridBagConstraints);

jPasswordField1.setText(""); // NOI18N
jPasswordField1.setName("jPasswordField1"); // NOI18N
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 1;
gridBagConstraints.gridy = 1;
gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
com.add(jPasswordField1, gridBagConstraints);

jButton1.setText("确定"); // NOI18N
jButton1.setOpaque(false);
jButton1.setName("jButton1"); // NOI18N
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 0;
gridBagConstraints.gridy = 2;
gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
com.add(jButton1, gridBagConstraints);

jButton2.setText("取消"); // NOI18N
jButton2.setOpaque(false);
jButton2.setName("jButton2"); // NOI18N
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 1;
gridBagConstraints.gridy = 2;
gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
com.add(jButton2, gridBagConstraints);
}

public static void main(String[] args) {
new OpaqueFrame().setVisible(true);
}
}
注意有个图片的路径啊,我是我本地的,你要用自己的图片,还有就是按钮的问题,按钮你需要加上两个图片,你那个确定取消都是很花哨只能是用图片,我的控件位置可能会偏差,这个需要你自己再去调整了。追问

运行的时候报这个错诶~图片的路径我改了哈~

追答

jdk版本。

温馨提示:答案为网友推荐,仅供参考
第1个回答  2011-03-17
你是说使用border的时候都是显示的矩形框?这个不能改啊,这样页面上的东西才会是一块一块的吗。你这个界面效果一样可以达到啊,一个一个图片拼起来就行了啊。
第2个回答  2011-03-18
使用 层div?
自己画边框,默认的都是方形

不规则图形的话,应该用图片自己拼
第3个回答  2011-03-17
用PNG图片,一个个的拼起来。

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网