java按钮背景
Ⅰ java里面如何中创建了一个按钮button,如何设置这个按钮的背景呢 不是背景颜色,是拿一张图片来作为button
很多人提交表单时都喜欢用一个图片来作为提交按钮,大多数人可能用JS去操作表单的提交,即当用户点击这个图片时响应一个JS来提交表单.其实还有一种方法,就是直接设置SUBMIT按钮的图片背景.设置它的图片背景有二种方法,一是直接在按钮中设置,如下:
<input type="submit" name="submit_button" value="" style="background:url(imagepath) no-repeat" />
这种设置方法在FF下可见,但是在IE下不可见,不知道为什么.反正我测试时IE下是不可见的,换成这样也不行:background-image\backgroundimage;
另一种方法就是用CSS来设置,实现方法如下:
<style type="text/css">
.submitStyle {background:url(imagpath);border:0px}
</style>
这种方法是比较好的,因为在IE或FF下都能正常显示.
Ⅱ java Button背景图片的设置
import javax.swing.ImageIcom;
ImageIcon icon = new ImageIcon("图片路径");
jbutton.setIcon(icon);
Ⅲ java点击按钮换背景颜色
改了一下:
packagemethod2;
importjava.awt.Button;
importjava.awt.Color;
importjava.awt.FlowLayout;
importjava.awt.Frame;
importjava.awt.Panel;
importjava.awt.event.MouseAdapter;
importjava.awt.event.MouseEvent;
{
Framef=newFrame();//f应声明为属性,才能在mousePressed()中可见
PanelP1=newPanel();//P1应声明为属性,才能在mousePressed()中可见
PanelP2=newPanel();//P2应声明为属性,才能在mousePressed()中可见
PanelP3=newPanel();//P3应声明为属性,才能在mousePressed()中可见
Buttonb1=newButton("红色");//b1应声明为属性,才能在mousePressed()中可见
Buttonb2=newButton("蓝色");//b2应声明为属性,才能在mousePressed()中可见
Buttonb3=newButton("黄色");//b3应声明为属性,才能在mousePressed()中可见
publicstaticvoidmain(Stringargs[]){
Changecolorct=newChangecolor();
ct.init();
}
publicvoidinit(){
//Framef=newFrame();
f.setLayout(newFlowLayout());
//PanelP1=newPanel();
//PanelP2=newPanel();
//PanelP3=newPanel();
//Buttonb1=newButton("红色");
//Buttonb2=newButton("蓝色");
//Buttonb3=newButton("黄色");
f.add(b1);
f.add(b2);
f.add(b3);
P1.setBackground(Color.red);
P2.setBackground(Color.blue);
P3.setBackground(Color.yellow);
P1.setVisible(true);
P2.setVisible(true);
P3.setVisible(true);
b1.addMouseListener(this);
b2.addMouseListener(this);
b3.addMouseListener(this);
f.setSize(300,300);
f.setVisible(true);
}//缺了个括号
publicvoidmousePressed(MouseEvente2){
if(e2.getSource()==b1){//b1应声明为属性才可见
f.setBackground(Color.red);//f应声明为属性才可见。源代码f.add(P1);给f添加一个背景色为红色的Panel;根据原意,应设置f的背景色为红色
}
if(e2.getSource()==b2){//b2应声明为属性才可见
f.add(P2);//f应声明为属性才可见
f.doLayout();//要让添加的组件起作用,应该再调用doLayout()方法,因为f的layout变了
}
if(e2.getSource()==b3){//b3应声明为属性才可见
f.add(P3);
f.doLayout();//要让添加的组件起作用,应该再调用doLayout()方法,因为f的layout变了
}
}
}
Ⅳ Java中如何做到单击按钮后更换背景图片
function mychange(num){ document.getElementById("div1").style.backgroundImage="url("+num+".jpg)"; document.getElementById("div2").style.backgroundImage="url("+num+".jpg)"; }
Ⅳ 在java中如何设置按钮背景颜色
setBackground();加这句就好了
JButton jbutton=new JButton();
jbutton.setBackground(Color.blue);