setLabel
10年積累的成都網(wǎng)站設(shè)計(jì)、成都做網(wǎng)站、外貿(mào)網(wǎng)站建設(shè)經(jīng)驗(yàn),可以快速應(yīng)對(duì)客戶對(duì)網(wǎng)站的新想法和需求。提供各種問題對(duì)應(yīng)的解決方案。讓選擇我們的客戶得到更好、更有力的網(wǎng)絡(luò)服務(wù)。我雖然不認(rèn)識(shí)你,你也不認(rèn)識(shí)我。但先網(wǎng)站設(shè)計(jì)后付款的網(wǎng)站建設(shè)流程,更有汕城免費(fèi)網(wǎng)站建設(shè)讓你可以放心的選擇與我們合作。
public?void?setLabel(String?label)??將按鈕的標(biāo)簽設(shè)置為指定的字符串
java控件命名規(guī)則如下:
JTextField 文本框 txt開頭
JButton 按鈕 btn開頭
JRadioButton 單選按鈕 rad開頭
JCheckBox 多選按鈕 chk開頭
JTextArea 多行文本編輯框 txa開頭
JPasswordField 密碼框 pwd開頭
JComboBox 下拉列表框 cbo開頭
JLabel 標(biāo)簽 lbl開頭
哈哈 我昨天剛做了這個(gè)作業(yè) 你夠幸運(yùn)
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.math.*;
public class Homework10_3 {
public static void main(String args[]){
MathWindow win=new MathWindow();
}
}
class MathWindow extends JFrame{
JTextField text1,text2,text3;
JPanel ps,pn;
MathWindow(){
text1=new JTextField(10);
text2=new JTextField(10);
text3=new JTextField(10);
JButton button1,button2,button3,button4;
button1=new JButton("加");
button2=new JButton("減");
button3=new JButton("乘");
button4=new JButton("除");
ps=new JPanel();
pn=new JPanel();
pn.add(text1);
pn.add(text2);
pn.add(text3);
ps.add(button1);
ps.add(button2);
ps.add(button3);
ps.add(button4);
add(pn,BorderLayout.CENTER);
add(ps,BorderLayout.SOUTH);
setBounds(100,100,370,150);
setVisible(true);
validate();
button1.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
String s1=text1.getText();
String s2=text2.getText();
try{ BigInteger n1=new BigInteger(s1);
BigInteger n2=new BigInteger(s2);
n2=n1.add(n2);
text3.setText(n2.toString());
}
catch(NumberFormatException ee){
text3.setText("請(qǐng)輸入數(shù)字字符");
text1.setText(null);
text2.setText(null);
}
}
});
button2.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
String s1=text1.getText();
String s2=text2.getText();
try{ BigInteger n1=new BigInteger(s1);
BigInteger n2=new BigInteger(s2);
n2=n1.subtract(n2);
text3.setText(n2.toString());
}
catch(NumberFormatException ee){
text3.setText("請(qǐng)輸入數(shù)字字符");
text1.setText(null);
text2.setText(null);
}
}
});
button3.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
String s1=text1.getText();
String s2=text2.getText();
try{ BigInteger n1=new BigInteger(s1);
BigInteger n2=new BigInteger(s2);
n2=n1.multiply(n2);
text3.setText(n2.toString());
}
catch(NumberFormatException ee){
text3.setText("請(qǐng)輸入數(shù)字字符");
text1.setText(null);
text2.setText(null);
}
}
});
button4.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
String s1=text1.getText();
String s2=text2.getText();
try{ BigInteger n1=new BigInteger(s1);
BigInteger n2=new BigInteger(s2);
if(n2.toString()=="0"){
text3.setText("除數(shù)不能為0");
}
else
{
n2=n1.divide(n2);
text3.setText(n2.toString());
}
}
catch(NumberFormatException ee){
text3.setText("請(qǐng)輸入數(shù)字字符");
text1.setText(null);
text2.setText(null);
}
}
});
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
}
}
把以下代碼拷貝到一個(gè)html文件中,直接運(yùn)行。
然后修改下button的value屬性,就是你想要的效果。
html
head
title改變按鈕的名字/title
/head
body
input type='button' value="哈哈哈哈" id="mybt" onclick="showElseName();"
/body
/html
script
function showElseName(){
document.getElementById('mybt').value="呵呵呵呵";//把“呵呵呵呵”替換成你想改變的值。修改按鈕mybt的value。
}
/script
如果值是動(dòng)態(tài)的話,你得到值后。把它賦值document.getElementById('mybt').value就可以了!
網(wǎng)頁題目:Java給按鈕命名代碼 java設(shè)置按鈕的名字
分享URL:http://muchs.cn/article4/ddcgjie.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供云服務(wù)器、虛擬主機(jī)、域名注冊(cè)、外貿(mào)建站、標(biāo)簽優(yōu)化、動(dòng)態(tài)網(wǎng)站
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)
營(yíng)銷型網(wǎng)站建設(shè)知識(shí)