返回信息流本人不会java,
但是现在急需写一个手机java小程序,
于是求高人来了
程序很简单,
两个输入框,输入M的值,和H的值
然后显示结果=m/(h^2)
谢谢高手了。
这是一条镜像帖。来源:北邮人论坛 / java / #20547同步于 2011/10/26
该镜像源已超过 30 天没有更新,可能在源站已被删除。
Java机器人发帖
求高人写一手机java小程序
yyff
2011/10/26镜像同步7 回复
订阅后,新回复会通过你的通知中心匿名送达。
7 条回复
作业贴?
【 在 yyff (yf) 的大作中提到: 】
: 本人不会java,
: 但是现在急需写一个手机java小程序,
: 于是求高人来了
: ...................
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class Phone implements ActionListener{
private static final int WINDOW_WIDTH=250;
private static final int WINDOW_HEIGHT=240;
private static final int fIELD_WIDTH=20;
private static final FlowLayout LAYOUT_STYLE=new FlowLayout();
private JFrame window=new JFrame("Calculator");
private JLabel mLabel=new JLabel("m ");
private JTextField mText=new JTextField(fIELD_WIDTH);
private JLabel hLabel=new JLabel("h ");
private JTextField hText=new JTextField(fIELD_WIDTH);
private JLabel rLabel=new JLabel("result");
private JTextField rText=new JTextField(fIELD_WIDTH);
private JButton button=new JButton("calculate");
public Phone(){
window.setSize(WINDOW_WIDTH, WINDOW_HEIGHT);
window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
rText.setEditable(false);
rText.setBackground(Color.WHITE);
button.addActionListener(this);
Container c=window.getContentPane();
c.setLayout(LAYOUT_STYLE);
c.add(mLabel);
c.add(mText);
c.add(hLabel);
c.add(hText);
c.add(rLabel);
c.add(rText);
c.add(button);
window.setVisible(true);
}
public void actionPerformed(ActionEvent e){
String response1=mText.getText();
double m=Double.parseDouble(response1);
String response2=hText.getText();
double h=Double.parseDouble(response2);
double result=m/(h*h);
String output=String.valueOf(result);
rText.setText(output);
}
//main():
public static void main(String[] args){
Phone gui=new Phone();
}
}