有没有大神能帮忙加个背景图片啊?拜托拜托
新手,不会加背景图片,勉强加了个丑炸了的背景颜色,拜托各位大神了。给个方法也行啊!下附代码(小白,写的很粗糙,望各位见谅)。package Login;
import Login.Logincd;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class Login extends JFrame
{
private JPanel panel=new JPanel();
private JPanel panel1=new JPanel();
private JPanel panel2=new JPanel();
private JPanel panel3=new JPanel();
private JLabel l1=new JLabel("登录名");
private JLabel l2=new JLabel("密码");
private JTextField f1=new JTextField(11);
private JTextField f2=new JTextField(11);
private JButton jbtBack=new JButton("重置");
private JButton jbtOK=new JButton("登录");
private JButton jbtCancel=new JButton("取消");
public Login()
{
setLayout(new BorderLayout(5,8));
add(panel1,BorderLayout.NORTH);
add(panel2,BorderLayout.CENTER);
add(panel3,BorderLayout.SOUTH);
panel1.add(l1);
panel1.add(f1);
panel2.add(l2);
panel2.add(f2);
panel3.add(jbtOK);
panel3.add(jbtBack);
panel3.add(jbtCancel);
panel.add(panel1);
panel.add(panel2);
panel.add(panel3);
add( panel);
panel.setBackground(new Color(255,182,193));
panel1.setBackground(new Color(255,182,193));
panel2.setBackground(new Color(255,182,193));
panel3.setBackground(new Color(255,182,193));
jbtOK.addActionListener(new Enter());
jbtBack.addActionListener(new ReWrite() );
jbtCancel.addActionListener(new Close());
}
public static void main (String[] args)
{
Login frame=new Login();
frame.setTitle("登录框");
frame.setSize(250,230);
frame.setLocationRelativeTo(null);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
class Enter implements ActionListener{
public void actionPerformed(ActionEvent e)
{
if((f1.getText()).equals("abc")&&(f2.getText()).equals("123"))
{
JOptionPane.showMessageDialog( null,"登录成功,管理员登录!");
Login.this.setVisible(false);
Logincd.initGUI();
}
else if ((f1.getText()).equals("ABC") && (f2.getText()).equals("123456")) {
JOptionPane.showMessageDialog(null, "登录成功,用户登录!");
Login.this.setVisible(false);
Logincd.initGUI();
}
else JOptionPane.showMessageDialog(null, "登录失败,请重新登录!");
}
}
class ReWrite implements ActionListener{
public void actionPerformed(ActionEvent e)
{
f1.setText("");
f2.setText("");
f1.requestFocus();
}
}
class Close implements ActionListener{
public void actionPerformed(ActionEvent e)
{
JButton bt=(JButton)e.getSource();
if(bt.equals(jbtCancel));
System.exit(0);
}
}
}