码迷,mamicode.com
首页 > 其他好文 > 详细

实验二

时间:2015-04-09 19:23:11      阅读:187      评论:0      收藏:0      [点我收藏+]

标签:

技术分享import java.awt.BorderLayout;


public class sizeyunsuan extends JFrame {

    private JPanel contentPane;
    int t,r3;//,r1,r2
    private JTable table;
    static Random r = new Random();
    String str="",str3="";
    int []zi=new int[20];
    int[] sum=new int[20];
    private JTextField []textField=new JTextField[20];
    int fenshu=0;
    int cushu[]=new int [20];
    int r1[]=new int [20];
    int r2[]=new int [20];
    public static void main(String[] args) {
        EventQueue.invokeLater(new Runnable() {
            public void run() {
                try {
                    sizeyunsuan frame = new sizeyunsuan();
                    frame.setVisible(true);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        });
    }

    /**
     * Create the frame.
     */
    public sizeyunsuan() {
        for(t=0;t<20;t++)
        {
            cushu[t]=-1;
        }t=0;
        setTitle("\u5C0F\u5B66\u56DB\u5219\u8FD0\u7B97");
        setIconImage(Toolkit.getDefaultToolkit().getImage("C:\\Users\\Administrator\\Pictures\\2013-10-15\\2013110506500553.jpg"));
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setBounds(100, 100, 458, 480);
        contentPane = new JPanel();
        contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
        setContentPane(contentPane);
        contentPane.setBackground(Color.green);
        contentPane.setLayout(null);
        JButton button_1 = new JButton("\u51FA\u9898");
        button_1.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
        
        
        
                     for(int i=0;i<20;i++){
                         r1[i] = r.nextInt(100);
                         r2[i] = r.nextInt(100);
                         r3 = 42+r.nextInt(6);
                        while(r3==46)
                        {
                         r3 = 42+r.nextInt(6);
                        }
                        if(r3==44)
                        {
                            r2[i] = 2+r.nextInt(8);
                        }
int b=i+1; switch(r3){ case 42: zi[i]=r1[i]*r2[i]; str=str+b+""+r1[i]+"*"+r2[i]+"=?"+"\n"; break; case 43: zi[i]=r1[i]+r2[i]; str=str+b+""+r1[i]+"+"+r2[i]+"=?"+"\n"; break; case 44: zi[i]=1; for(int j=r2[i];j>0;j--) { zi[i]=zi[i]*j; } str=str+b+":"+r2[i]+"!"+"=?"+"\n"; break; case 45: zi[i]=r1[i]-r2[i]; str=str+b+""+r1[i]+"-"+r2[i]+"=?"+"\n"; break; case 47: cushu[t]=i; t++; str=str+b+""+r1[i]+"/"+r2[i]+"=?"+"\n"; //zi[i]=r1/r2; int j=r1[i]>r2[i]?r2[i]:r1[i]; for(;j>1;j--) { if(r1[i]%j==0&&r2[i]%j==0) { r1[i]=r1[i]/j; r2[i]=r2[i]/j; } } break; } } JTextPane textPane = new JTextPane(); textPane.setBounds(5, 54, 172, 365); contentPane.add(textPane); textPane.setText(str); } }); button_1.setBounds(5, 21, 93, 23); contentPane.add(button_1); JLabel lblNewLabel_1 = new JLabel("1"); lblNewLabel_1.setBounds(188, 57, 54, 15); contentPane.add(lblNewLabel_1); JLabel lblNewLabel_2 = new JLabel("2"); lblNewLabel_2.setBounds(188, 82, 54, 15); contentPane.add(lblNewLabel_2); JLabel lblNewLabel_3 = new JLabel("3"); lblNewLabel_3.setBounds(187, 107, 54, 15); contentPane.add(lblNewLabel_3); JLabel lblNewLabel_4 = new JLabel("4"); lblNewLabel_4.setBounds(187, 132, 54, 15); contentPane.add(lblNewLabel_4); JLabel lblNewLabel_5 = new JLabel("5"); lblNewLabel_5.setBounds(187, 157, 54, 15); contentPane.add(lblNewLabel_5); JLabel lblNewLabel_6 = new JLabel("6"); lblNewLabel_6.setBounds(187, 182, 54, 15); contentPane.add(lblNewLabel_6); JLabel lblNewLabel_7 = new JLabel("7"); lblNewLabel_7.setBounds(187, 207, 54, 15); contentPane.add(lblNewLabel_7); JLabel lblNewLabel_8 = new JLabel("8"); lblNewLabel_8.setBounds(187, 235, 54, 15); contentPane.add(lblNewLabel_8); JLabel lblNewLabel_9 = new JLabel("9"); lblNewLabel_9.setBounds(187, 263, 54, 15); contentPane.add(lblNewLabel_9); JLabel lblNewLabel_10 = new JLabel("10"); lblNewLabel_10.setBounds(187, 288, 54, 15); contentPane.add(lblNewLabel_10); JLabel lblNewLabel_11 = new JLabel("11"); lblNewLabel_11.setBounds(297, 57, 54, 15); contentPane.add(lblNewLabel_11); textField[0] = new JTextField(); textField[0].setBounds(208, 54, 66, 21); contentPane.add(textField[0]); textField[0].setColumns(10); textField[1] = new JTextField(); textField[1].setBounds(208, 79, 66, 21); contentPane.add(textField[1]); textField[1].setColumns(10); textField[2] = new JTextField(); textField[2].setBounds(208, 104, 66, 21); contentPane.add(textField[2]); textField[2].setColumns(10); textField[3] = new JTextField(); textField[3].setBounds(208, 129, 66, 21); contentPane.add(textField[3]); textField[3].setColumns(10); textField[4] = new JTextField(); textField[4].setBounds(208, 154, 66, 21); contentPane.add(textField[4]); textField[4].setColumns(10); textField[5] = new JTextField(); textField[5].setBounds(208, 179, 66, 21); contentPane.add(textField[5]); textField[5].setColumns(10); textField[6] = new JTextField(); textField[6].setBounds(208, 204, 66, 21); contentPane.add(textField[6]); textField[6].setColumns(10); textField[7] = new JTextField(); textField[7].setBounds(208, 232, 66, 21); contentPane.add(textField[7]); textField[7].setColumns(10); textField[8] = new JTextField(); textField[8].setBounds(208, 260, 66, 21); contentPane.add(textField[8]); textField[8].setColumns(10); textField[9] = new JTextField(); textField[9].setBounds(208, 285, 66, 21); contentPane.add(textField[9]); textField[9].setColumns(10); textField[10] = new JTextField(); textField[10].setBounds(321, 54, 66, 21); contentPane.add(textField[10]); textField[10].setColumns(10); JLabel lblNewLabel_12 = new JLabel("12"); lblNewLabel_12.setBounds(297, 82, 54, 15); contentPane.add(lblNewLabel_12); JLabel label_1 = new JLabel("13"); label_1.setBounds(297, 107, 54, 15); contentPane.add(label_1); JLabel label_2 = new JLabel("14"); label_2.setBounds(297, 132, 54, 15); contentPane.add(label_2); JLabel label_3 = new JLabel("15"); label_3.setBounds(297, 157, 54, 15); contentPane.add(label_3); textField[11] = new JTextField(); textField[11].setBounds(321, 179, 66, 21); contentPane.add(textField[11]); textField[11].setColumns(10); JLabel label_4 = new JLabel("16"); label_4.setBounds(297, 182, 54, 15); contentPane.add(label_4); JLabel label_5 = new JLabel("17"); label_5.setBounds(297, 207, 54, 15); contentPane.add(label_5); JLabel label_6 = new JLabel("18"); label_6.setBounds(297, 235, 54, 15); contentPane.add(label_6); JLabel label_7 = new JLabel("19"); label_7.setBounds(297, 263, 54, 15); contentPane.add(label_7); JLabel label_8 = new JLabel("20"); label_8.setBounds(297, 288, 54, 15); contentPane.add(label_8); textField[12] = new JTextField(); textField[12].setBounds(321, 104, 66, 21); contentPane.add(textField[12]); textField[12].setColumns(10); textField[13] = new JTextField(); textField[13].setBounds(321, 79, 66, 21); contentPane.add(textField[13]); textField[13].setColumns(10); textField[14] = new JTextField(); textField[14].setBounds(321, 129, 66, 21); contentPane.add(textField[14]); textField[14].setColumns(10); textField[15] = new JTextField(); textField[15].setBounds(321, 154, 66, 21); contentPane.add(textField[15]); textField[15].setColumns(10); textField[16] = new JTextField(); textField[16].setBounds(321, 285, 66, 21); contentPane.add(textField[16]); textField[16].setColumns(10); textField[17] = new JTextField(); textField[17].setBounds(321, 204, 66, 21); contentPane.add(textField[17]); textField[17].setColumns(10); textField[18] = new JTextField(); textField[18].setBounds(321, 232, 66, 21); contentPane.add(textField[18]); textField[18].setColumns(10); textField[19] = new JTextField(); textField[19].setBounds(321, 260, 66, 21); contentPane.add(textField[19]); textField[19].setColumns(10); JButton button_2 = new JButton("\u5B8C\u6210"); button_2.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { int h=0;String str1="", str2="1"; for(int i=0;i<20;i++) { str1=""; str2="1";h=0; for(int j=0;j<20;j++) { if(i!=cushu[j]){h++;} }System.out.println(r1[i]+" "+r2[i]+h); if(h==20){String s=textField[i].getText(); sum[i]=Integer.parseInt(s); if(sum[i]==zi[i]) fenshu+=5; } else{ String s=textField[i].getText(); char ch[]=s.toCharArray(); System.out.println("\""+ch.length+"\""); for(int j=0;j<ch.length;j++) { if(ch[j]>0&&ch[j]<9) { str1=str1+ch[j];System.out.println(str1); } else{ str2=str1; } }
int cs=Integer.parseInt(str1); int bcs=Integer.parseInt(str2); str2="1"; if(cs==r2[i]&&bcs==r1[i]) {fenshu+=5; } } } str3="正确"+fenshu/5+"题\n"+"得分为"+String.valueOf(fenshu); JOptionPane sm=new JOptionPane(); sm.showMessageDialog(sm, str3, "温馨提示", 1); } }); button_2.setBounds(240, 361, 93, 23); contentPane.add(button_2); JButton button = new JButton("\u51FA\u9898"); } }

技术分享

技术分享

开发环境:Eclipse

我们是从:程序可以出单个整数阶乘的题目:如:4!=24程序可以设置皮肤功能,可以改变界面的颜色即可

我的同伴是黎文衷,学号是201306114330 链接:http://home.cnblogs.com/u/734881/

在这个程序里我做了界面功能和代码的嵌入,同伴是主要代码的实现。

感悟:想要把代码嵌入界面是非常困难的,在我个人认为写主要功能的实现是需要自己的思想,而代码的嵌入是固定框架的。如不熟悉是很困难的。在以上是图片是我们的工作照,是在工作中叫同学拍的

 

实验二

标签:

原文地址:http://www.cnblogs.com/shishaotao/p/4410513.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!