import java.awt.event.*;
import javax.swing.*;
import java.awt.*
public class MyWindow extends JWindow {
JLabel labName = new JLabel();
JLabel labPass = new JLabel();
JTextField txtName = new JTextField();
JPasswordField pass = new JPasswordField();
JButton btnOK = new JButton();
JButton btnExit = new JButton();
public MyWindow() {
DrawPanel bg = new DrawPanel("login1.jpg", 700, 386);//自己写的DrawPanel类继承JPanel实现了画图功能
bg.setLayout(null);
btnExit.setBackground(Color.white);
labPass.setFont(new java.awt.Font("宋体", Font.PLAIN, 13));
labPass.setForeground(Color.white);
labName.setFont(new java.awt.Font("宋体", Font.PLAIN, 13));
labName.setForeground(Color.white);
txtName.setBorder(null);
pass.setBackground(Color.white);
pass.setBorder(null);
this.getContentPane().add(bg);
Toolkit toolkit = Toolkit.getDefaultToolkit(); //抽象的不能new 默认的工具包
Dimension screenSize = toolkit.getScreenSize(); //获得屏幕大小 返回的是Dimension类型
this.setBounds((screenSize.width - 700) / 2,
(screenSize.height - 386) / 2, 700, 386);
this.setVisible(true);
labName.setText("操作员");
labName.setBounds(new Rectangle(180, 139, 85, 30));
txtName.setText("t068312");
this.requestFocusInWindow();
bg.requestFocusInWindow();
txtName.requestFocusInWindow();
txtName.setBounds(new Rectangle(233, 146, 109, 20));
pass.setText("123456");
pass.setBounds(new Rectangle(232, 196, 112, 21));
btnOK.setBackground(Color.white);
btnOK.setBounds(new Rectangle(189, 246, 60, 26));
btnOK.setBorder(BorderFactory.createLineBorder(Color.black));
btnOK.setText("登陆");
btnExit.setBounds(new Rectangle(263, 245, 60, 26));
btnExit.setBorder(BorderFactory.createLineBorder(Color.black));
btnExit.setText("取消");
bg.add(labPass);
bg.add(labName);
bg.add(txtName);
bg.add(pass);
bg.add(btnExit);
bg.add(btnOK);
labPass.setText("口 令");
labPass.setBounds(new Rectangle(180, 191, 85, 30));
}
public static void main(String[] args) {
MyWindow my = new MyWindow();
}
}
----------------解决方案--------------------------------------------------------
package first;
//这个是JPanel类
import java.awt.*;
import javax.swing.JPanel;
public class DrawPanel extends JPanel {
String fileName ;
int width,height;
public DrawPanel(String fileName,int width,int height){
this.fileName = fileName;
this.width=width;
this.height=height;
}
public void paintComponent(Graphics g){
super.paintComponent(g);//清除背景
Image img = Toolkit.getDefaultToolkit().getImage(fileName);
g.drawImage(img, 0,0,width,height, this);
}
}
----------------解决方案--------------------------------------------------------
[CODE]import java.awt.event.*;
import javax.swing.*;
import java.awt.*;
public class MyWindow extends JFrame {
JLabel labName = new JLabel();
JLabel labPass = new JLabel();
JTextField txtName = new JTextField();
JPasswordField pass = new JPasswordField();
JButton btnOK = new JButton();
JButton btnExit = new JButton();
public MyWindow() {
DrawPanel bg = new DrawPanel("login1.jpg", 700, 386);//自己写的DrawPanel类继承JPanel实现了画图功能
bg.setLayout(null);
btnExit.setBackground(Color.white);
labPass.setFont(new java.awt.Font("宋体", Font.PLAIN, 13));
labPass.setForeground(Color.white);
labName.setFont(new java.awt.Font("宋体", Font.PLAIN, 13));
labName.setForeground(Color.white);
txtName.setBorder(null);
pass.setBackground(Color.white);
pass.setBorder(null);
Toolkit toolkit = Toolkit.getDefaultToolkit(); //抽象的不能new 默认的工具包
Dimension screenSize = toolkit.getScreenSize(); //获得屏幕大小 返回的是Dimension类型
this.setBounds((screenSize.width - 700) / 2,
(screenSize.height - 386) / 2, 700, 386);
labName.setText("操作员");
labName.setBounds(new Rectangle(180, 139, 85, 30));
txtName.setText("t068312");
txtName.setBounds(new Rectangle(233, 146, 109, 20));
pass.setText("123456");
pass.setBounds(new Rectangle(232, 196, 112, 21));
btnOK.setBackground(Color.white);
btnOK.setBounds(new Rectangle(189, 246, 60, 26));
btnOK.setBorder(BorderFactory.createLineBorder(Color.black));
btnOK.setText("登陆");
btnExit.setBounds(new Rectangle(263, 245, 60, 26));
btnExit.setBorder(BorderFactory.createLineBorder(Color.black));
btnExit.setText("取消");
bg.add(labPass);
bg.add(labName);
bg.add(txtName);
bg.add(pass);
bg.add(btnExit);
bg.add(btnOK);
labPass.setText("口 令");
labPass.setBounds(new Rectangle(180, 191, 85, 30));
this.getContentPane().add(bg);
this.setUndecorated(true);
this.setVisible(true);
}
public static void main(String[] args) {
MyWindow my = new MyWindow();
}
}[/CODE]
----------------解决方案--------------------------------------------------------