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);