import java.awt.Color;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.GridLayout;
import java.awt.LayoutManager;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JLayeredPane;
import javax.swing.JPanel;
import javax.swing.JTextField;
public class UIinterface extends JFrame {
JLayeredPane pane = new JLayeredPane();//分层网格
JLabel label;
JPanel panel1 = new JPanel();
JPanel panel2 = new JPanel();
JPanel panel3 = new JPanel();
JTextField field1 = new JTextField("账号");
JTextField field2 = new JTextField("密码");
JButton Land = new JButton("登陆");
JButton register = new JButton("注册");
ImageIcon image;
/**
*
*/
public UIinterface() {
image = new ImageIcon("jpp/蜘蛛侠.jpg");
//设置字体格式和大小
field1.setFont(new Font("宋体",Font.PLAIN,30));
//设置字体颜色
field1.setForeground(Color.BLUE);
field2.setFont(new Font("宋体",Font.PLAIN,30));
field2.setForeground(Color.BLUE);
Land.setFont(new Font("宋体",Font.PLAIN,20));
Land.setForeground(Color.darkGray);
register.setFont(new Font("宋体",Font.PLAIN,20));
register.setForeground(Color.darkGray);
//设置组件透明
field1.setOpaque(false);
field2.setOpaque(false);
Land.setOpaque(false);
register.setOpaque(false);
panel1.setOpaque(false);
panel2.setOpaque(false);
panel3.setOpaque(false);
label = new JLabel(image); //把背景图片添加到标签里
panel1.setBounds(0, 0, image.getIconWidth(), image.getIconHeight()); //把标签设置为和图片等高等宽
panel1 = (JPanel)this.getContentPane(); //把我的面板设置为内容面板
panel1.add(label);
panel2.setLayout(new GridLayout(2,1));
panel2.setBounds(50, 100, 350, 80);
panel2.add(field1);
panel2.add(field2);
panel3.setBounds(50,250,350,40);
panel3.add(Land);
panel3.add(register);
Land.setSize(20,30);
register.setSize(20,30);
pane.add(panel1,JLayeredPane.DEFAULT_LAYER);//带有标签的面板放在最底层
pane.add(panel2,JLayeredPane.DRAG_LAYER);
pane.add(panel3,JLayeredPane.POPUP_LAYER);
this.setTitle("QQ");
this.setBounds(100,100,image.getIconWidth(), image.getIconHeight());
this.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
this.setLayeredPane(pane);
this.setVisible(true);
}
}
比较丑的一个页面,主要在于学习新内容。