java 怎么算乘法
packageCMJqimo;importjava.util.Random;importjava.awt.*;importjava.awt.event.ActionEve...
package CMJqimo;
import java.util.Random;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.swing.*;
import java.awt.event.ActionListener;
public class test {
public static void main(String args[])
{
new test();
}
public test(){
JPanel jp=new JPanel();
JLabel jl=new JLabel();
JTextField jtf;
JFrame jf=new JFrame("Exam of Multiplication");
JButton jb=new JButton();
Container c =jf.getContentPane();
Container contentPane = jf.getContentPane();
contentPane.add(jp);
contentPane.setLayout(new BorderLayout());
jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
jf.setSize(300, 200);
jp.setLayout(new FlowLayout());
jp.setBackground(Color.GREEN);
jp.setSize(1000,1000);
Random r=new Random();
int num1=random_number();
int num2=random_number();
int trueresult=num1*num2;
int a = Integer.parseInt("12");
jp.add(new JLabel(num1+" x "+num2+" ="));
jtf=new JTextField(5);
jp.add(jtf);
jb=new JButton("提交");
jp.add(jb);
String s_input=jtf.getText();
int input =10;
jl=new JLabel(" ");
jp.add(jl);
contentPane.add(jp);
jf.setLocation(400, 200);
jf.setVisible(true);
jb.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{ resetnum(num1,num2);
jp.add(new JLabel(num1+" x "+num2+" ="));
jp.add(jtf);
read_input(jtf.getText());
String s=output_result(trueresult,input);
}
});
}
public static int read_input(String s)
{
return Integer.parseInt(s);
};
public static void resetnum(int num1,int num2){
num1=random_number();
num2=random_number();
}
public static int random_number()
{ Random r=new Random();
int num=r.nextInt(10)+1;
return num;
}
public String output_result(int trueresult,int input)
{ Random r=new Random();
if (input==trueresult)
{
String[] s={"Very good","Excellent","Great job"};
return s[r.nextInt(3)];
}
else
{
return "No, please try again";
}
}}
4.乘法训练器程序。(每组1-2人)
开发一个用以帮助小学生学习乘法运算的应用程序。通过将随机产生的两个1位正整数显示在某个问题当中,如问题:“6乘以7等于多少?”,然后让学生将此问题的答案输入到一个JTextField中。若答案正确,该程序随机从三条信息中(“Very good”, “Excellent”, “Great job”)选出一条信息并显示在一个JLabel中,然后继续下一道问题;如果答案错误,则在JLabel中显示信息“No, please try again”。
我 的点button 按钮弹不出来,为啥? 展开
import java.util.Random;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.swing.*;
import java.awt.event.ActionListener;
public class test {
public static void main(String args[])
{
new test();
}
public test(){
JPanel jp=new JPanel();
JLabel jl=new JLabel();
JTextField jtf;
JFrame jf=new JFrame("Exam of Multiplication");
JButton jb=new JButton();
Container c =jf.getContentPane();
Container contentPane = jf.getContentPane();
contentPane.add(jp);
contentPane.setLayout(new BorderLayout());
jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
jf.setSize(300, 200);
jp.setLayout(new FlowLayout());
jp.setBackground(Color.GREEN);
jp.setSize(1000,1000);
Random r=new Random();
int num1=random_number();
int num2=random_number();
int trueresult=num1*num2;
int a = Integer.parseInt("12");
jp.add(new JLabel(num1+" x "+num2+" ="));
jtf=new JTextField(5);
jp.add(jtf);
jb=new JButton("提交");
jp.add(jb);
String s_input=jtf.getText();
int input =10;
jl=new JLabel(" ");
jp.add(jl);
contentPane.add(jp);
jf.setLocation(400, 200);
jf.setVisible(true);
jb.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{ resetnum(num1,num2);
jp.add(new JLabel(num1+" x "+num2+" ="));
jp.add(jtf);
read_input(jtf.getText());
String s=output_result(trueresult,input);
}
});
}
public static int read_input(String s)
{
return Integer.parseInt(s);
};
public static void resetnum(int num1,int num2){
num1=random_number();
num2=random_number();
}
public static int random_number()
{ Random r=new Random();
int num=r.nextInt(10)+1;
return num;
}
public String output_result(int trueresult,int input)
{ Random r=new Random();
if (input==trueresult)
{
String[] s={"Very good","Excellent","Great job"};
return s[r.nextInt(3)];
}
else
{
return "No, please try again";
}
}}
4.乘法训练器程序。(每组1-2人)
开发一个用以帮助小学生学习乘法运算的应用程序。通过将随机产生的两个1位正整数显示在某个问题当中,如问题:“6乘以7等于多少?”,然后让学生将此问题的答案输入到一个JTextField中。若答案正确,该程序随机从三条信息中(“Very good”, “Excellent”, “Great job”)选出一条信息并显示在一个JLabel中,然后继续下一道问题;如果答案错误,则在JLabel中显示信息“No, please try again”。
我 的点button 按钮弹不出来,为啥? 展开
展开全部
package CMJqimo;
import java.util.Random;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
public class test {
static int trueresult = 0;
public static void main(String args[]) {
new test();
}
public test() {
JPanel jp = new JPanel();
JLabel jl = new JLabel();
JTextField jtf;
JFrame jf = new JFrame("Exam of Multiplication");
JButton jb = new JButton();
Container contentPane = jf.getContentPane();
contentPane.add(jp);
contentPane.setLayout(new BorderLayout());
jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
jf.setSize(300, 200);
jp.setLayout(new FlowLayout());
jp.setBackground(Color.GREEN);
jp.setSize(1000, 1000);
int num1 = random_number();
int num2 = random_number();
trueresult = num1 * num2;
JLabel jll = new JLabel(num1 + " x " + num2 + " =");
jp.add(jll);
jtf = new JTextField(5);
jp.add(jtf);
jb = new JButton("提交");
jp.add(jb);
jl = new JLabel(" ");
jp.add(jl);
contentPane.add(jp);
jf.setLocation(400, 200);
jf.setVisible(true);
jb.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
int input = Integer.valueOf(jtf.getText());
String s = output_result(trueresult, input);
JOptionPane.showMessageDialog(jp, s);
int a = random_number();
int b = random_number();
trueresult = a * b;
jll.setText(a + " x " + b + " =");
jtf.setText("");
}
});
}
public static int read_input(String s) {
return Integer.parseInt(s);
};
public static int random_number() {
Random r = new Random();
int num = r.nextInt(10) + 1;
return num;
}
public String output_result(int trueresult, int input) {
Random r = new Random();
if (input == trueresult) {
String[] s = { "Very good", "Excellent", "Great job" };
return s[r.nextInt(3)];
} else {
return "No, please try again";
}
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询