中科健康产业集团 骗:学习JAVA碰到的问题

来源:百度文库 编辑:查人人中国名人网 时间:2024/04/29 14:05:21
从命令行输入两个整数,计算这两个整数的商和余数,并输出结果(注意:除数不允许为0)。

写一个程序,使用边界布局管理器:上(一个标签,显示“在下面输入内容"),
中(一个单行文本框),下(一个按钮,显示”确定“)。当点击按钮时,弹出一个
消息对话框,显示在中部的单行文本框输入的内容。

public class Test
{
public static void main(String[] args)
{
System.out.println("商是"+Integer.parseInt(args[0])/Integer.parseInt(args[1]));
System.out.println("余数是"+Integer.parseInt(args[0])%Integer.parseInt(args[1]));

}
}
另一个是程序:
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;

public class Test extends JFrame implements ActionListener
{
JTextField titleText;
JButton button;
String ss = null;
Test(String s)
{
super(s);
titleText = new JTextField(10);
button = new JButton("确定");
button.addActionListener(this);
Container con = getContentPane();
con.setLayout(new FlowLayout());
con.add(titleText);
con.add(button);
setBounds(100,100,150,150);
setVisible(true);
validate();
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public static void main(String[] args)
{
Test test = new Test ("请在下面输入内容");
}
public void actionPerformed(ActionEvent e) {
if(e.getSource()==button)
{
JOptionPane.showMessageDialog(null,titleText.getText(),"显示",JOptionPane.INFORMATION_MESSAGE);
}
}
}