JAVA 在 JFrame中加个背景图片的问题 急
这是我写的一段代码,只是个框架。比如我图片在E盘如何加载背景图片,怎么弄??麻烦写的详细点(写的详细可用加分50)importjava.awt.BorderLayout;...
这是我写的一段代码,只是个框架。比如我图片在E盘如何加载背景图片,怎么弄??麻烦写的详细点(写的详细可用加分50)
import java.awt.BorderLayout;
import javax.swing.JPanel;
import javax.swing.JFrame;
public class 出院结算 extends JFrame {
private static final long serialVersionUID = 1L;
private JPanel jContentPane = null;
public 出院结算() {
super();
initialize();
}
private void initialize() {
this.setSize(300, 200);
this.setContentPane(getJContentPane());
this.setTitle("JFrame");
}
private JPanel getJContentPane() {
if (jContentPane == null) {
jContentPane = new JPanel();
jContentPane.setLayout(null);
}
return jContentPane;
}
} 展开
import java.awt.BorderLayout;
import javax.swing.JPanel;
import javax.swing.JFrame;
public class 出院结算 extends JFrame {
private static final long serialVersionUID = 1L;
private JPanel jContentPane = null;
public 出院结算() {
super();
initialize();
}
private void initialize() {
this.setSize(300, 200);
this.setContentPane(getJContentPane());
this.setTitle("JFrame");
}
private JPanel getJContentPane() {
if (jContentPane == null) {
jContentPane = new JPanel();
jContentPane.setLayout(null);
}
return jContentPane;
}
} 展开
2个回答
展开全部
1楼的很不错。。建议采用。。
我给你写详细点。。
package 娱乐;
import java.awt.Container;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
public class Test extends JFrame {
public Test() {
setBak(); //调用背景方法
Container c = getContentPane(); //获取JFrame面板
JPanel jp = new JPanel(); //创建个JPanel
jp.setOpaque(false); //把JPanel设置为透明 这样就不会遮住后面的背景 这样你就能在JPanel随意加组件了
c.add(jp);
setSize(540, 450);
setVisible(true);
}
public void setBak(){
((JPanel)this.getContentPane()).setOpaque(false);
ImageIcon img = new ImageIcon("c://Sunset.jpg");
JLabel background = new JLabel(img);this.getLayeredPane().add(background, new Integer(Integer.MIN_VALUE));
background.setBounds(0, 0, img.getIconWidth(), img.getIconHeight());
}
public static void main(String[] args) {
Test s = new Test();
s.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
我给你写详细点。。
package 娱乐;
import java.awt.Container;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
public class Test extends JFrame {
public Test() {
setBak(); //调用背景方法
Container c = getContentPane(); //获取JFrame面板
JPanel jp = new JPanel(); //创建个JPanel
jp.setOpaque(false); //把JPanel设置为透明 这样就不会遮住后面的背景 这样你就能在JPanel随意加组件了
c.add(jp);
setSize(540, 450);
setVisible(true);
}
public void setBak(){
((JPanel)this.getContentPane()).setOpaque(false);
ImageIcon img = new ImageIcon("c://Sunset.jpg");
JLabel background = new JLabel(img);this.getLayeredPane().add(background, new Integer(Integer.MIN_VALUE));
background.setBounds(0, 0, img.getIconWidth(), img.getIconHeight());
}
public static void main(String[] args) {
Test s = new Test();
s.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
展开全部
public void setBak(){
((JPanel)this.getContentPane()).setOpaque(false);ImageIcon img = new ImageIcon("img/icon.gif");
JLabel background = new JLabel(img);this.getLayeredPane().add(background, new Integer(Integer.MIN_VALUE));
background.setBounds(0, 0, img.getIconWidth(), img.getIconHeight());
}
((JPanel)this.getContentPane()).setOpaque(false);ImageIcon img = new ImageIcon("img/icon.gif");
JLabel background = new JLabel(img);this.getLayeredPane().add(background, new Integer(Integer.MIN_VALUE));
background.setBounds(0, 0, img.getIconWidth(), img.getIconHeight());
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询