两个textfield t1,t2,一个按钮b.要求在t1内随便输入一个数n,然后按下b,就会在t2内出现一个数m=2n.这要什么样的语句才能转换啊,请好心人教我,感激!
解决方案 »
- 多线程问题
- java gui 图片切换
- java 每次访问sql sever 2000数据库后 需要结束进程么?
- 一个数组小练习编译通过,运行出错!
- 达人来帮我看一下产生随机数的问题
- 关于JTable第一列加组件的问题???求助?
- 为什么我编的含有applet的网页,applet都显示不出来?
- JAVA小知识
- 一个零件由一个厂家生产,一个厂家生产多种零件,画出E-R图
- 请问从哪里能下到java的详细的帮助~
- java联接sqlserver2005,为什么联接不上?急急!!(在线等)
- 奇怪!为什么我import MyPackage.MainSubClass;程序能编译通过,而import MyPackage.*;程序编译就不能通过呢?(我分快没了)
String t2 = "";try{
t2 = ""+ (Integer.parseInt(t1)*2);
}catch(Exception e){
System.out.println("请输入数字");
}
import java.awt.*;public class a extends Applet{
private Label l1,l2;
private TextField t1,t2;
private Button b;
public void init(){
l1=new Label("华氏温度:");
t1=new TextField();
b=new Button("转换>>");
l2=new Label("摄氏温度:");
t2=new TextField();
add(l1);add(t1);add(b);add(l2);add(t2);
}
public boolean action(Event e,Object o)
{
String s;
if(e.target==b){
???
}
}
}
请问,问号里面怎么写?
String t2 = "" ;
BigDecimal t1temp = new BigDecimal(t1);
BigDecimal t2temp = new BigDecimal("2");
t2 = t1temp.multiply(t2temp).toString ;
问题2: new BigDecimal(t1);
new BigDecimal("2");后面括号里是不是t2?
问题3:要是t2=(t1-32)*5/9,怎么写公式呢
NO2.后面括号里的是乘以的那个2,要计算精确的话最好用BigDemical;
NO3.将所有数据转成BigDemical类型,然后进行,加减乘除,用BigDemical类型,分别为:add,subtract,multiply,divide进行运算
double d2=(d1-32)*5/9;t2.setText(""+d2);//或者t2.setText(String.valueOf(d2));
我不知道 TextField();怎么接收数据,谁能说一下吗?就是在事件触发那里不懂
event.getActionCommand();是什么意思?
NO1:t1是你随便输入的数字,我的那个是虚拟了一个数字;
--------------------------------------------------
不明白~~~啊~~~~!!!
怎么搞个随便输入接收的TextField();?
事件中的
完整的是
if(event.getActionCommand()=="转换>>");
意思是说 当监听器接受到 或者触及到 "转换>>" 时 自己调用事件我这里有几个事件的例子
供给自己参考import java.awt.*;
import java.awt.event.*;class text extends Frame
{
Button b1 = new Button("红色");
Button b2 = new Button("黄色");
Button b3 = new Button("蓝色");
Button b4 = new Button("绿色");
Button b5 = new Button("紫色");
boolean l ;
text(String s)
{
super(s);
setLayout(new FlowLayout());
l = false;
add(b1);
add(b2);
add(b3);
add(b4);
add(b5);
text1 a1 = new text1(Color.red);
text1 a2 = new text1(Color.orange);
text1 a3 = new text1(Color.blue);
text1 a4 = new text1(Color.green);
text1 a5 = new text1(Color.cyan);
b1.addActionListener(a1);
b2.addActionListener(a2); b3.addActionListener(a3);
b4.addActionListener(a4);
b5.addActionListener(a5); addWindowListener(new text2());
}
private class text1 implements ActionListener
{ private Color c;
text1(Color c1) {
c= c1;
}
public void actionPerformed(ActionEvent a)
{
setBackground(c);
}
}
private class text2 extends WindowAdapter
{
public void windowClosing(WindowEvent a1)
{
if(l)
dispose();
else
System.exit(0);
}
}
public static void main(String agrs[])
{
text t = new text("坏蛋");
t.setSize(300,200);
t.setVisible(true);
}
}
import java.awt.*;import java.awt.event.*;class MyMulticast
{
public static void main(String args[])
{
MulticastFrame frame = new MulticastFrame();
frame.show();
}
}class MulticastFrame extends Frame
{
public MulticastFrame()
{
setTitle("nihao");
setSize(300,200);
MulticastPanel panel = new MulticastPanel();
add(panel);
addWindowListener(new MyWindowAdapter());
}
private class MyWindowAdapter extends WindowAdapter
{
public void windowClosing(WindowEvent wevent)
{
System.exit(0);
}
}
}class MulticastPanel extends Panel
{
public MulticastPanel()
{
Button newbutton = new Button("新建");
add(newbutton);
ActionListener newlistener = new ActionListener()
{
public void actionPerformed(ActionEvent event)
{
makeNewFrame();
}
};
newbutton.addActionListener(newlistener);
closeAllButton = new Button("关闭全部");
add(closeAllButton);
}
private void makeNewFrame()
{
final BlankFrame frame = new BlankFrame();
frame.show();
ActionListener closeAllListener = new ActionListener()
{
public void actionPerformed(ActionEvent event)
{
frame.dispose();
}
};
closeAllButton.addActionListener(closeAllListener);
}
private Button closeAllButton;
}
class BlankFrame extends Frame
{
public BlankFrame()
{
counter++;
setTitle("窗体"+counter);
setSize(200,150);
setLocation(30*counter,30*counter);
}
private static int counter;
}import java.awt.*;
import java.awt.event.*;
class ButtonControl extends Frame implements ActionListener
{
Button b = new Button("显示消息") ;
Label l = new Label("");
boolean w;
ButtonControl(String s)
{
super(s);
// setLayout(new FlowLayout());
add(b,BorderLayout.NORTH);
add(l,BorderLayout.CENTER);
b.addActionListener(this);
this.addWindowListener(new my());
}
public void actionPerformed(ActionEvent a)
{
if(a.getActionCommand().equals("显示消息"))
{
b.setLabel("隐藏消息");
l.setText("哇!我出现了");
}
else if(a.getActionCommand().equals("隐藏消息"))
{
b.setLabel("显示消息");
l.setText("");
}
}
private class my extends WindowAdapter
{
public void windowClosing(WindowEvent e)
{
if(w)
dispose();
else
System.exit(0);
}
}
public static void main(String agrs[])
{
ButtonControl c =new ButtonControl("练习1");
c.setSize(300,200);
c.setVisible(true);
}
}