重庆分公司,新征程启航

为企业提供网站建设、域名注册、服务器等服务

Java给按钮命名代码 java设置按钮的名字

java有什么方法可以改变Button的名字,是Button,不是JButton

setLabel

10年积累的成都网站设计、成都做网站、外贸网站建设经验,可以快速应对客户对网站的新想法和需求。提供各种问题对应的解决方案。让选择我们的客户得到更好、更有力的网络服务。我虽然不认识你,你也不认识我。但先网站设计后付款的网站建设流程,更有汕城免费网站建设让你可以放心的选择与我们合作。

public void setLabel(String label)  将按钮的标签设置为指定的字符串

如何给java控件命名

java控件命名规则如下:

JTextField 文本框 txt开头

JButton 按钮 btn开头

JRadioButton 单选按钮 rad开头

JCheckBox 多选按钮 chk开头

JTextArea 多行文本编辑框 txa开头

JPasswordField 密码框 pwd开头

JComboBox 下拉列表框 cbo开头

JLabel 标签 lbl开头

编写一个Java小应用程序,设计4个按钮,分别命名为“加”、“差”、“积”、“除”以及3个文本框。

哈哈 我昨天刚做了这个作业 你够幸运

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("请输入数字字符");

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("请输入数字字符");

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("请输入数字字符");

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("除数不能为0");

}

else

{

n2=n1.divide(n2);

text3.setText(n2.toString());

}

}

catch(NumberFormatException ee){

text3.setText("请输入数字字符");

text1.setText(null);

text2.setText(null);

}

}

});

setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);

}

}

请问如何修改按钮名字 JAVA

把以下代码拷贝到一个html文件中,直接运行。

然后修改下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

如果值是动态的话,你得到值后。把它赋值document.getElementById('mybt').value就可以了!


当前标题:Java给按钮命名代码 java设置按钮的名字
本文来源:http://cqcxhl.cn/article/ddcgjie.html

其他资讯

在线咨询
服务热线
服务热线:028-86922220
TOP