编写一个字符界面的JAVA Application程序,接受用户输入的一个浮点数,把它的整数部分和小数部分分别输出
importjava.awt.*;importjava.awt.even.*;publicclassTestInOut{publicstaticvoidmain(Stri...
import java.awt.*;
import java.awt.even.*;
public class TestInOut
{
public static void main(String args[])
{
new FrameInOut();
}
}
class FrameInOut extends Frame implements ActionListerner
{
Label prompt;
TextField input,output1,output2;
FrameInOut()
{
super("图形界面的Java Application程序员");
prompt =new Label("请输入一个浮点数:");
input=new TextField(6);
output1=new TextField(20);
output2=new TextField(20);
btn=new Button("关闭");
setLayout(new FlowLayout());
add(prompt);
add(input);
add(output1);
add(outpurt2);
input.addActionListener(this);
btn.addActionListener(this);
setSize(300,200);
setVisible(true);
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==input)
output1.setText((Integer.parseInt)(input.getText()));
output2.setText(input.getText());
else
}
dispose();
System.exit(0);
}
}
} 展开
import java.awt.even.*;
public class TestInOut
{
public static void main(String args[])
{
new FrameInOut();
}
}
class FrameInOut extends Frame implements ActionListerner
{
Label prompt;
TextField input,output1,output2;
FrameInOut()
{
super("图形界面的Java Application程序员");
prompt =new Label("请输入一个浮点数:");
input=new TextField(6);
output1=new TextField(20);
output2=new TextField(20);
btn=new Button("关闭");
setLayout(new FlowLayout());
add(prompt);
add(input);
add(output1);
add(outpurt2);
input.addActionListener(this);
btn.addActionListener(this);
setSize(300,200);
setVisible(true);
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==input)
output1.setText((Integer.parseInt)(input.getText()));
output2.setText(input.getText());
else
}
dispose();
System.exit(0);
}
}
} 展开
1个回答
展开全部
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class TestInOut
{
public static void main(String args[])
{
new FrameInOut();
}
}
class FrameInOut extends Frame implements ActionListener
{
Label prompt;
TextField output,output1,output2;
Button btn,input;
FrameInOut()
{
super("图形界面的Java Application程序员");
prompt =new Label("请输入一贺谨姿个浮点数:");
input=new Button("计算");
output=new TextField(20);
output1=new TextField(20);
output2=new TextField(20);
btn=new Button("关闭");
setLayout(new FlowLayout());
add(prompt);
add(input);
add(output);
add(output1);
add(output2);
add(btn);
input.addActionListener(this);
btn.addActionListener(this);
setSize(300,200);
setVisible(true);
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==input){
String a=null;
a=output.getText();
String[] resultValue=a.split("\\.");//注禅绝意split方法的转意晌衡方式,默认的事逗号
output1.setText(resultValue[0]);
output2.setText(resultValue[1]);
}
else{
dispose();
System.exit(0);
}
}
}
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class TestInOut
{
public static void main(String args[])
{
new FrameInOut();
}
}
class FrameInOut extends Frame implements ActionListener
{
Label prompt;
TextField output,output1,output2;
Button btn,input;
FrameInOut()
{
super("图形界面的Java Application程序员");
prompt =new Label("请输入一贺谨姿个浮点数:");
input=new Button("计算");
output=new TextField(20);
output1=new TextField(20);
output2=new TextField(20);
btn=new Button("关闭");
setLayout(new FlowLayout());
add(prompt);
add(input);
add(output);
add(output1);
add(output2);
add(btn);
input.addActionListener(this);
btn.addActionListener(this);
setSize(300,200);
setVisible(true);
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==input){
String a=null;
a=output.getText();
String[] resultValue=a.split("\\.");//注禅绝意split方法的转意晌衡方式,默认的事逗号
output1.setText(resultValue[0]);
output2.setText(resultValue[1]);
}
else{
dispose();
System.exit(0);
}
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询