當前位置:首頁 » 編程語言 » java按鈕背景

java按鈕背景

發布時間: 2022-06-10 09:19:40

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

熱點內容
節目腳本是什麼 發布:2025-02-08 02:08:54 瀏覽:139
android的自定義屬性 發布:2025-02-08 02:07:27 瀏覽:605
怎麼看電腦的用戶名和密碼 發布:2025-02-08 02:02:48 瀏覽:795
vb動態資料庫 發布:2025-02-08 02:01:53 瀏覽:110
一台存儲可以配幾個擴展櫃 發布:2025-02-08 01:53:22 瀏覽:566
分布式存儲技術優缺點 發布:2025-02-08 01:51:37 瀏覽:245
linuxsuse重啟 發布:2025-02-08 01:49:27 瀏覽:412
java對稱加密 發布:2025-02-08 01:48:04 瀏覽:523
java報表框架 發布:2025-02-08 01:47:59 瀏覽:930
方舟手游怎麼防止踢出伺服器 發布:2025-02-08 01:42:44 瀏覽:690