我想用JAVA做一个不规则的登陆界面,JAVA默认出现的窗口都是矩形?能不能改啊。请给出详细的方法哈
展开全部
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);
}
}
注意有个图片的路径啊,我是我本地的,你要用自己的图片,还有就是按钮的问题,按钮你需要加上两个图片,你那个确定取消都是很花哨只能是用图片,我的控件位置可能会偏差,这个需要你自己再去调整了。
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版本。
展开全部
你是说使用border的时候都是显示的矩形框?这个不能改啊,这样页面上的东西才会是一块一块的吗。你这个界面效果一样可以达到啊,一个一个图片拼起来就行了啊。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
使用 层div?
自己画边框,默认的都是方形
不规则图形的话,应该用图片自己拼
自己画边框,默认的都是方形
不规则图形的话,应该用图片自己拼
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
用PNG图片,一个个的拼起来。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询