Topic: 美化窗体

  Print this page

1.美化窗体 Copy to clipboard
Posted by: 305457157
Posted on: 2007-10-28 12:55

package teachman;

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.awt.Image;

public class Frame1 extends JFrame {
JPanel contentPane;
JLabel jLabel2 = new JLabel();
JTextField jTextField1 = new JTextField();
JLabel jLabel1 = new JLabel();
JLabel jLabel3 = new JLabel();
JPasswordField jPasswordField1 = new JPasswordField();
JComboBox jbcomb1 = new JComboBox();
JButton jButton1 = new JButton();
JButton jButton2 = new JButton();
JLabel jLabel4 = new JLabel();

//Construct the frame
public Frame1() {
enableEvents(AWTEvent.WINDOW_EVENT_MASK);
try {
jbInit();
}
catch(Exception e) {
e.printStackTrace();
}
}
//Component initialization
private void jbInit() throws Exception {

contentPane = (JPanel)this.getContentPane();
jLabel2.setFont(new java.awt.Font("宋体", 0, 14));
jLabel2.setText("用户名:");
jLabel2.setBounds(new Rectangle(109, 57, 60, 24));

contentPane.setLayout(null);
this.getContentPane().setBackground(SystemColor.control);
this.setSize(new Dimension(400, 320));
this.setResizable(false);//禁用窗口标题栏上的最大化按钮

this.setTitle("登 录");
this.getWindowStateListeners();
// this.setUndecorated(truententPane); //不能拖动
jTextField1.setBounds(new Rectangle(172, 57, 112, 25));
jLabel1.setEnabled(true);
jLabel1.setFont(new java.awt.Font("宋体", 0, 14));
jLabel1.setText("密 码:");
jLabel1.setBounds(new Rectangle(109, 95, 61, 21));
jLabel3.setFont(new java.awt.Font("Dialog", 0, 14));
jLabel3.setText("登录类型:");
jLabel3.setBounds(new Rectangle(100, 132, 74, 23));
jPasswordField1.setText("");
jPasswordField1.setBounds(new Rectangle(172, 89, 111, 27));
jbcomb1.setBounds(new Rectangle(172, 126, 116, 26));

jButton1.setBounds(new Rectangle(101, 187, 73, 25));
jButton1.setFont(new java.awt.Font("Dialog", 0, 14));
jButton1.setSelected(true);
jButton1.setText("登录");
jButton2.setBounds(new Rectangle(205, 190, 73, 25));
jButton2.setFont(new java.awt.Font("Dialog", 0, 14));
jButton2.setToolTipText("");
jButton2.setActionCommand("重置");
jButton2.setContentAreaFilled(true);
jButton2.setText("重置");
jButton2.setVerticalAlignment(SwingConstants.CENTER);
jLabel4.setBackground(Color.lightGray);
jLabel4.setEnabled(true);
jLabel4.setFont(new java.awt.Font("Dialog", 0, 14));
jLabel4.setForeground(Color.red);
jLabel4.setText("新教师请注册");
jLabel4.setBounds(new Rectangle(239, 235, 98, 16));

contentPane.add(jTextField1, null);
contentPane.add(jLabel2, null);
contentPane.add(jPasswordField1, null);
contentPane.add(jLabel1, null);
contentPane.add(jLabel3, null);
contentPane.add(jbcomb1, null);
contentPane.add(jButton1, null);
contentPane.add(jButton2, null);
contentPane.add(jLabel4, null);

}
//Overridden so we can exit when window is closed
protected void processWindowEvent(WindowEvent e) {
super.processWindowEventEnvelope;
if (e.getID() == WindowEvent.WINDOW_CLOSING) {
System.exit(0);
}
}

}

怎么为这个程序窗体上加一个背景图片,,,,,,,,标题栏左边的图标也换了,

这些图片放在什么地方可以用相对路径

2.Re:美化窗体 [Re: 305457157] Copy to clipboard
Posted by: javafriend
Posted on: 2007-11-04 11:42

要添加背景图可以试试用JLabel来实现,可以把图添到JLabel里,然后再加到窗体,但要注意,JLabel要最后加入窗体。具体怎样,自去试试。用Eclipse工具可以很方便的。


   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923