java窗体如何添加背景图片 5
packagejwglxt;importjava.awt.BorderLayout;importjava.awt.Color;importjava.awt.Compone...
package jwglxt;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.Container;
import java.awt.FlowLayout;
import java.awt.Font;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
public class Login1{
JFrame jframe = new JFrame("教务管理系统登陆");
Container con =jframe.getContentPane();
private JTextField username = new JTextField();
private JTextField password = new JTextField();
private JTextField code = new JTextField();
private JButton login = new JButton("登陆");
private JButton reset = new JButton("重置");
public Login1() {
jframe.setBounds(450,300,500,300);
jframe.setLayout(new BorderLayout());
initjframe();
//con.setVisible(false);
jframe.setVisible(true);
jframe.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
}
void initjframe() {
//头 即叫务管理系统
JPanel titleJPanel = new JPanel();
titleJPanel.setLayout(new FlowLayout());
JLabel title =new JLabel("教务管理系统");
title.setFont(new Font("楷体",Font.BOLD,20));
titleJPanel.add(title);
jframe.add(titleJPanel,"North");
//中部即文本区域即用户输入数据
JPanel systemJPanel = new JPanel();
systemJPanel.setLayout(null);
JLabel a = new JLabel("用户名:");
a.setFont(new Font("楷体",Font.BOLD,15));
a.setBounds(100,50,60,20);
JLabel b = new JLabel("密 码:");
b.setFont(new Font("楷体",Font.BOLD,15));
b.setBounds(100,80,60,20);
JLabel c =new JLabel("验证码:");
c.setFont(new Font("楷体",Font.BOLD,15));
c.setBounds(100,110,60,20);
username.setBounds(170,50,150,20);
password.setBounds(170,80,150,20);
code.setBounds(170,110,150,20);
systemJPanel.add(a);
systemJPanel.add(b);
systemJPanel.add(c);
systemJPanel.add(username);
systemJPanel.add(password);
systemJPanel.add(code);
jframe.add(systemJPanel,"Center");
//按钮区域
JPanel buttonJPanel = new JPanel();
buttonJPanel.setLayout(new FlowLayout());
login.setFont(new Font("楷体",Font.BOLD,15));
reset.setFont(new Font("楷体",Font.BOLD,15));
buttonJPanel.add(login);
buttonJPanel.add(reset);
jframe.add(buttonJPanel, "South");
//设置背景
//JPanel bg = new JPanel();
//bg.setBackground(Color.pink);
//jframe.add(bg);
}
public static void main(String[] args) {
new Login1();
}
} 展开
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.Container;
import java.awt.FlowLayout;
import java.awt.Font;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
public class Login1{
JFrame jframe = new JFrame("教务管理系统登陆");
Container con =jframe.getContentPane();
private JTextField username = new JTextField();
private JTextField password = new JTextField();
private JTextField code = new JTextField();
private JButton login = new JButton("登陆");
private JButton reset = new JButton("重置");
public Login1() {
jframe.setBounds(450,300,500,300);
jframe.setLayout(new BorderLayout());
initjframe();
//con.setVisible(false);
jframe.setVisible(true);
jframe.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
}
void initjframe() {
//头 即叫务管理系统
JPanel titleJPanel = new JPanel();
titleJPanel.setLayout(new FlowLayout());
JLabel title =new JLabel("教务管理系统");
title.setFont(new Font("楷体",Font.BOLD,20));
titleJPanel.add(title);
jframe.add(titleJPanel,"North");
//中部即文本区域即用户输入数据
JPanel systemJPanel = new JPanel();
systemJPanel.setLayout(null);
JLabel a = new JLabel("用户名:");
a.setFont(new Font("楷体",Font.BOLD,15));
a.setBounds(100,50,60,20);
JLabel b = new JLabel("密 码:");
b.setFont(new Font("楷体",Font.BOLD,15));
b.setBounds(100,80,60,20);
JLabel c =new JLabel("验证码:");
c.setFont(new Font("楷体",Font.BOLD,15));
c.setBounds(100,110,60,20);
username.setBounds(170,50,150,20);
password.setBounds(170,80,150,20);
code.setBounds(170,110,150,20);
systemJPanel.add(a);
systemJPanel.add(b);
systemJPanel.add(c);
systemJPanel.add(username);
systemJPanel.add(password);
systemJPanel.add(code);
jframe.add(systemJPanel,"Center");
//按钮区域
JPanel buttonJPanel = new JPanel();
buttonJPanel.setLayout(new FlowLayout());
login.setFont(new Font("楷体",Font.BOLD,15));
reset.setFont(new Font("楷体",Font.BOLD,15));
buttonJPanel.add(login);
buttonJPanel.add(reset);
jframe.add(buttonJPanel, "South");
//设置背景
//JPanel bg = new JPanel();
//bg.setBackground(Color.pink);
//jframe.add(bg);
}
public static void main(String[] args) {
new Login1();
}
} 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询