java登陆界面怎么加背景图 会的我加你
publicvoiduserInit(){this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);//设置关闭框架的同时结...
public void userInit(){
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);//设置关闭框架的同时结束程序
this.setSize(500,300);//设置框架大小为长500,宽300
this.setResizable(false);//设置框架不可以改变大小
this.setTitle("学生管理系统");//设置框架标题
this.pnluser.setLayout(null);//设置面板布局管理
this.pnluser.setBackground(Color.pink);//设置面板背景颜色
this.lbluserLogIn.setText("学生管理系统");//设置标签标题
this.lbluserLogIn.setFont(new Font("宋体",Font.BOLD | Font.ITALIC,20));//设置标签字体
this.lbluserLogIn.setForeground(Color.RED);//设置标签字体颜色
this.lbluserName.setText("用户名:");
this.lbluserPWD.setText("密 码:");
this.btnSub.setText("登录");
this.btnReset.setText("重置");
this.lbluserLogIn.setBounds(200,15,200,20);//设置标签x坐标120,y坐标15,长60,宽20
this.lbluserName.setBounds(90,55,60,20);
this.lbluserPWD.setBounds(90,85,60,25);
this.txtName.setBounds(160,55,200,20);
this.pwdPwd.setBounds(160,85,200,20);
this.btnSub.setBounds(85,120,60,20);
this.btnSub.addActionListener(new ActionListener()//匿名类实现ActionListener接口
{
public void actionPerformed(ActionEvent e){
btnsub_ActionEvent(e);
}
}
);
this.btnReset.setBounds(155,120,60,20);
this.btnReset.addActionListener(new ActionListener()//匿名类实现ActionListener接口
{
public void actionPerformed(ActionEvent e){
btnreset_ActionEvent(e);
}
} 展开
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);//设置关闭框架的同时结束程序
this.setSize(500,300);//设置框架大小为长500,宽300
this.setResizable(false);//设置框架不可以改变大小
this.setTitle("学生管理系统");//设置框架标题
this.pnluser.setLayout(null);//设置面板布局管理
this.pnluser.setBackground(Color.pink);//设置面板背景颜色
this.lbluserLogIn.setText("学生管理系统");//设置标签标题
this.lbluserLogIn.setFont(new Font("宋体",Font.BOLD | Font.ITALIC,20));//设置标签字体
this.lbluserLogIn.setForeground(Color.RED);//设置标签字体颜色
this.lbluserName.setText("用户名:");
this.lbluserPWD.setText("密 码:");
this.btnSub.setText("登录");
this.btnReset.setText("重置");
this.lbluserLogIn.setBounds(200,15,200,20);//设置标签x坐标120,y坐标15,长60,宽20
this.lbluserName.setBounds(90,55,60,20);
this.lbluserPWD.setBounds(90,85,60,25);
this.txtName.setBounds(160,55,200,20);
this.pwdPwd.setBounds(160,85,200,20);
this.btnSub.setBounds(85,120,60,20);
this.btnSub.addActionListener(new ActionListener()//匿名类实现ActionListener接口
{
public void actionPerformed(ActionEvent e){
btnsub_ActionEvent(e);
}
}
);
this.btnReset.setBounds(155,120,60,20);
this.btnReset.addActionListener(new ActionListener()//匿名类实现ActionListener接口
{
public void actionPerformed(ActionEvent e){
btnreset_ActionEvent(e);
}
} 展开
2个回答
展开全部
我直接给你一个ImagePanel类,你自己改改。
public class ImagePanel extends JPanel {
/**
*
*/
private static final long serialVersionUID = 1L;
protected BufferedImage image;
protected Rectangle rectangle=new Rectangle();
public ImagePanel() {
setLayout(null);
installListeners();
}
private void installListeners() {
}
public void paintComponent(Graphics g) {
super.paintComponent(g);
if(image==null){
return ;
}
g.drawImage(image, 0, 0, null);
if(rectangle.width>=0&&rectangle.height>=0){
Color c = g.getColor();
g.setColor(Color.RED);
g.drawRect(rectangle.x, rectangle.y, rectangle.width, rectangle.height);
g.setColor(c);
}
}
public BufferedImage getImage() {
return image;
}
public void setImage(BufferedImage image) {
this.setImage(image, true);
}
public void setImage(BufferedImage image, boolean repaint) {
this.image = image;
if (image != null) {
Dimension size = new Dimension(image.getWidth(null),image.getHeight(null));
setPreferredSize(size);
setMinimumSize(size);
setMaximumSize(size);
setSize(size);
} else {
}
rectangle=new Rectangle();
if (repaint)
this.repaint();
}
public boolean isDirty() {
return image != null;
}
/*
public void updateCrosshair(int i) {
y=i;
repaint();
}*/
public void updateZooe(Rectangle r) {
this.rectangle=r;
repaint();
}
}
核心代码就是重写paintComponent。再者你的代码习惯不好,布局管理器用的不科学。
public class ImagePanel extends JPanel {
/**
*
*/
private static final long serialVersionUID = 1L;
protected BufferedImage image;
protected Rectangle rectangle=new Rectangle();
public ImagePanel() {
setLayout(null);
installListeners();
}
private void installListeners() {
}
public void paintComponent(Graphics g) {
super.paintComponent(g);
if(image==null){
return ;
}
g.drawImage(image, 0, 0, null);
if(rectangle.width>=0&&rectangle.height>=0){
Color c = g.getColor();
g.setColor(Color.RED);
g.drawRect(rectangle.x, rectangle.y, rectangle.width, rectangle.height);
g.setColor(c);
}
}
public BufferedImage getImage() {
return image;
}
public void setImage(BufferedImage image) {
this.setImage(image, true);
}
public void setImage(BufferedImage image, boolean repaint) {
this.image = image;
if (image != null) {
Dimension size = new Dimension(image.getWidth(null),image.getHeight(null));
setPreferredSize(size);
setMinimumSize(size);
setMaximumSize(size);
setSize(size);
} else {
}
rectangle=new Rectangle();
if (repaint)
this.repaint();
}
public boolean isDirty() {
return image != null;
}
/*
public void updateCrosshair(int i) {
y=i;
repaint();
}*/
public void updateZooe(Rectangle r) {
this.rectangle=r;
repaint();
}
}
核心代码就是重写paintComponent。再者你的代码习惯不好,布局管理器用的不科学。
2014-06-06
展开全部
加我吧,我试试。
追问
qq?
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询