| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 828 人关注过本帖
标题:十万火急啊,明天交作业啊,有关背景图片不显示的,拜托各路神仙了
只看楼主 加入收藏
icanbestrong
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:100
专家分:138
注 册:2013-3-13
结帖率:50%
收藏
已结贴  问题点数:20 回复次数:5 
十万火急啊,明天交作业啊,有关背景图片不显示的,拜托各路神仙了
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
class MyButton extends Button{
Container con;
MyButton(){
this.con=con;
setVisible(true);
setSize(20,15);
}
}
class MyPanel extends JPanel implements MouseListener{
GridLayout grid;
int i,j;
int number=1;
Panel panel1,panel2;
Color a;
Color c;
Label label;
YourPanel yourpanel;
MyButton mybutton[][];
MyPanel(){
yourpanel=new YourPanel();
label=new Label("Have a try,maybe you just have one chance,however,that's game!",Label.CENTER);
label.setSize(450,120);
c=new Color(3,131,199);
label.setBackground(c);
Font font=new Font("default",Font.PLAIN+Font.ITALIC,15);
label.setFont(font);
panel1=new Panel();
panel2=new panel();
panel2.add(label);
grid=new GridLayout(6,9);
panel1.setLayout(grid);
mybutton=new MyButton[6][9];
for(i=0;i<6;i++)
for(j=0;j<9;j++){
mybutton[i][j]=new MyButton();
panel1.add(mybutton[i][j]);
mybutton[i][j].addMouseListener(this);
}
add(panel2);
add(panel1);
a=new Color(217,19,128);
setSize(225,90);
setVisible(true);
}
public void mousePressed(MouseEvent e){
if(number==26) {
remove(panel1);
remove(panel2);
add(yourpanel);
}
if(mybutton[0][1]==e.getSource())
{if(mybutton[0][1].getBackground()!=a)
{mybutton[0][1].setBackground(a);
++number;
}
}
else if(mybutton[0][2]==e.getSource())
{if(mybutton[0][2].getBackground()!=a)
{mybutton[0][2].setBackground(a);
++number;
}
}
 else if(mybutton[0][5]==e.getSource())
{if(mybutton[0][5].getBackground()!=a)
{mybutton[0][5].setBackground(a);
++number;
}
}
else if(mybutton[0][8]==e.getSource())
{if(mybutton[0][8].getBackground()!=a)
{mybutton[0][8].setBackground(a);
++number;
}
}
else if(mybutton[1][0]==e.getSource())
{if(mybutton[1][0].getBackground()!=a)
{mybutton[1][0].setBackground(a);
++number;
}
}
else if(mybutton[1][4]==e.getSource())
{if(mybutton[1][4].getBackground()!=a)
{mybutton[1][4].setBackground(a);
++number;
}
}
else if(mybutton[1][6]==e.getSource())
{if(mybutton[1][6].getBackground()!=a)
{mybutton[1][6].setBackground(a);
++number;
}
}
else if(mybutton[1][8]==e.getSource())
{if(mybutton[1][8].getBackground()!=a)
{mybutton[1][8].setBackground(a);
++number;
}
}
else if(mybutton[2][0]==e.getSource())
{if(mybutton[2][0].getBackground()!=a)
{mybutton[2][0].setBackground(a);
++number;
}
}
else if(mybutton[2][4]==e.getSource())
{if(mybutton[2][4].getBackground()!=a)
{mybutton[2][4].setBackground(a);
++number;
}
}
else if(mybutton[2][6]==e.getSource())
{if(mybutton[2][6].getBackground()!=a)
{mybutton[2][6].setBackground(a);
++number;
}
}
else if(mybutton[2][8]==e.getSource())
{if(mybutton[2][8].getBackground()!=a)
{mybutton[2][8].setBackground(a);
++number;
}
}
else if(mybutton[3][0]==e.getSource())
{if(mybutton[3][0].getBackground()!=a)
{mybutton[3][0].setBackground(a);
++number;
}
}
else if(mybutton[3][4]==e.getSource())
{if(mybutton[3][4].getBackground()!=a)
{mybutton[3][4].setBackground(a);
++number;
}
}
else if(mybutton[3][5]==e.getSource())
{if(mybutton[3][5].getBackground()!=a)
{mybutton[3][5].setBackground(a);
++number;
}
}
else if(mybutton[3][6]==e.getSource())
{if(mybutton[3][6].getBackground()!=a)
{mybutton[3][6].setBackground(a);
++number;
}
}
else if(mybutton[3][8]==e.getSource())
{if(mybutton[3][8].getBackground()!=a)
{mybutton[3][8].setBackground(a);
++number;
}
}
else if(mybutton[4][0]==e.getSource())
{if(mybutton[4][0].getBackground()!=a)
{mybutton[4][0].setBackground(a);
++number;
}
}
else if(mybutton[4][4]==e.getSource())
{if(mybutton[4][4].getBackground()!=a)
{mybutton[4][4].setBackground(a);
++number;
}
}
else if(mybutton[4][6]==e.getSource())
{if(mybutton[4][6].getBackground()!=a)
{mybutton[4][6].setBackground(a);
++number;
}
}
else if(mybutton[4][8]==e.getSource())
{if(mybutton[4][8].getBackground()!=a)
{mybutton[4][8].setBackground(a);
++number;
}
}
else if(mybutton[5][1]==e.getSource())
{if(mybutton[5][1].getBackground()!=a)
{mybutton[5][1].setBackground(a);
++number;
}
}
else if(mybutton[5][2]==e.getSource())
{if(mybutton[5][2].getBackground()!=a)
{mybutton[5][2].setBackground(a);
++number;
}
}
else if(mybutton[5][4]==e.getSource())
{if(mybutton[5][4].getBackground()!=a)
{mybutton[5][4].setBackground(a);
++number;
}
}
else if(mybutton[5][6]==e.getSource())
{if(mybutton[5][6].getBackground()!=a)
{mybutton[5][6].setBackground(a);
++number;
}
}
else if(mybutton[5][8]==e.getSource())
{if(mybutton[5][8].getBackground()!=a)
{mybutton[5][8].setBackground(a);
++number;
}
}
else {
System.exit(2);}
}
public void mouseReleased(MouseEvent e){}
public void mouseEntered(MouseEvent e){}
public void mouseExited(MouseEvent e){}
public void mouseClicked(MouseEvent e){
if(e.getClickCount()>=2)
{System.exit(1);
}
}
}
class YourPanel extends JPanel{
YourPanel() {
setLayout(null);
setVisible(true);
}
public void paintComponent(Graphics g) {
super.paintComponent(g);
ImageIcon yourpanel = new ImageIcon("D:\\1.png");
g.drawImage(yourpanel.getImage(), 200, 250, 300, 400, this);
}
}
public class MyFrame extends JFrame{
MyPanel mypanel;
Label label;
MyFrame(String s){
super(s);
mypanel=new MyPanel();
setBounds(200,100,450,380);
add(mypanel);
setVisible(true);
setDefaultCloseOperation(EXIT_ON_CLOSE);
}
public static void main(String args[]){
new MyFrame("Je t'amine");
}
}
大哥大姐们,我又来了,为何我设置的背景图片不显示啊,图片麻烦大神自己定义个,
搜索更多相关主题的帖子: however 背景图片 number import 
2013-06-19 19:35
yuccn
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:何方
等 级:版主
威 望:167
帖 子:6815
专家分:42393
注 册:2010-12-16
收藏
得分:4 
神仙为了瞪分而来

我行我乐
公众号:逻辑客栈
我的博客:
https://blog.yuccn. net
2013-06-19 21:38
我叫沃恩
Rank: 12Rank: 12Rank: 12
来 自:Asia
等 级:贵宾
威 望:10
帖 子:1234
专家分:3865
注 册:2013-3-29
收藏
得分:4 
呵呵!!

因为我是菜鸟,所以应该被骂! 细节+坚持=成功!
2013-06-19 21:40
hhwz
Rank: 13Rank: 13Rank: 13Rank: 13
等 级:贵宾
威 望:87
帖 子:687
专家分:4502
注 册:2011-5-22
收藏
得分:4 
最好断点调试下
2013-06-19 23:24
joy2
Rank: 2
等 级:论坛游民
帖 子:5
专家分:47
注 册:2013-6-18
收藏
得分:4 
看迷了眼...
-----------------------
斗破乾坤 http://www.
2013-06-20 16:12
Kingbox_tang
Rank: 7Rank: 7Rank: 7
来 自:天津师范大学
等 级:黑侠
威 望:3
帖 子:146
专家分:677
注 册:2012-11-27
收藏
得分:4 
你的color直接 写setBackground(Color.red);
这样应该就行了



旨在提高编程水平,学有所用,学有所成,学有所为。
2013-06-21 01:19
快速回复:十万火急啊,明天交作业啊,有关背景图片不显示的,拜托各路神仙了
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.029864 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved