• Jun 12 Fri 2015 14:16
  • 5/22

import java.awt.*; 
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import java.util.Random;

class A3 extends JFrame {

fwcgex1529 發表在 痞客邦 留言(0) 人氣()

import java.awt.*;
import java.awt.event.*;

fwcgex1529 發表在 痞客邦 留言(0) 人氣()

import java.awt.*;
import java.awt.event.*;

fwcgex1529 發表在 痞客邦 留言(0) 人氣()

import java.awt.*;
import java.awt.event.*;

fwcgex1529 發表在 痞客邦 留言(0) 人氣()

import java.awt.*;
import java.awt.event.*;

fwcgex1529 發表在 痞客邦 留言(0) 人氣()

<html>
<head>

fwcgex1529 發表在 痞客邦 留言(0) 人氣()

http://tccnchsu.blogspot.tw/2011 程式設計工藝大師

1.下載並安裝JAVA

fwcgex1529 發表在 痞客邦 留言(0) 人氣()

1.為何why要選修這門課?(動機)

因為想學一些JAVA然後拿個學分

fwcgex1529 發表在 痞客邦 留言(0) 人氣()

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplication24
{
    public partial class Form1 : Form
    {
        Button[,] buttons = new Button[10, 10];
        int[] array = new int[10];

        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            int d1, tmp, k;

            Random irand = new Random();
            d1 = irand.Next(1, 10);
            label1.Text = d1.ToString();


            for (int j = 1; j < 10; j++)
            {
                k = 9 - j + 1;
                tmp = array[d1];
                array[d1] = array[k];
                array[k] = tmp;
            }


            for (int j = 0; j < 3; j++)
            {
                for (int i = 0; i < 3; i++)
                {
                    //buttons[i, j] = new Button();
                    buttons[i, j].Location = new Point(j * 50, i * 50);
                    buttons[i, j].Text = array[i * 3 + j + 1].ToString();
                    this.Controls.Add(buttons[i, j]);
                }

            }
        }
        private void movement(int i, int j, string s) {
            MessageBox.Show("i=" + i + ",j" + j + "" + s);

        }

        private void Form1_Load(object sender, EventArgs e)
        {
            // Instantiating all the buttons in the array



            for (int i = 0; i < 9; i++)
            {
                array[i] = i;
            }


            /*
            for (int j = 1; j < 10; j++)
            {
                buttons[1, j] = new Button();
                buttons[1, j].Location = new Point(50 * j, 50);
                buttons[1, j].Text = array[j].ToString();
                this.Controls.Add(buttons[1, j]);
            }
            */

            for (int j = 0; j < 3; j++)
            {
                for (int i = 0; i < 3; i++)
                {
                    buttons[i, j] = new Button();
                    buttons[i, j].Location = new Point(j * 50, i * 50);
                    buttons[i, j].Text = (j * 3 + i).ToString();
                    this.Controls.Add(buttons[i, j]);
                    buttons[i, j].Click += new EventHandler(Button1_Click);
                }

            }
           
        }
        private void Button1_Click(object sender, EventArgs e)
        {
            for (int i = 0; i < 3; i++)
            {
                for (int j = 0; j < 3; j++)
                {
                    if (buttons[i, j].Text == "0")
                    {
                        MessageBox.Show("i=" + i + ",j=" + j + " " + buttons[i, j].Text);
                    }
                }


            }




            for (int i = 0; i < 3; i++)
            {
                for (int j = 0; j < 3; j++)
                {
                    if (sender == buttons[i, j])
                    {
                        MessageBox.Show("i=" + i + ",j=" + j + " " + buttons[i, j].Text);
                    }
                }


            }




        }
    }
}


fwcgex1529 發表在 痞客邦 留言(0) 人氣()

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplication11
{
    public partial class Form1 : Form
    {    string c;
        int[] a = new int[10];
        Button[,] b = new Button[5, 5];
        int[,] w=new int[5,5];
        Random r1 = new Random();
      
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            for (int j = 0; j < 5; j++)
            {
                for (int i = 0; i < 5; i++)
                {
                    b[i, j] = new System.Windows.Forms.Button();
                    b[i, j].Location = new Point(50 * i, 50 * j);
                    b[i, j].Click += new EventHandler(b_Click);
                    b[i, j].Width = 50;
                    b[i, j].Height = 50;
                    b[i, j].Text = "" + (i + j * 5);
                    w[i, j] = i + j * 5;//w[i,j]可以用來紀錄b[i,j]有關的數值
                    this.Controls.Add(b[i, j]);

                }
            }
            for (int j = 0; j < 25; j++)
            {
                for (int i = 0; i < j; i++)
                {
                    a[0] = r1.Next(0, j);//a[0]從0到j
                    a[1] = a[0] % 5;//a[1],a[2]從0到4
                    a[2] = (a[0] - a[1]) / 5;
                    c = b[a[1], a[2]].Text;
                    b[a[1], a[2]].Text = b[i % 5, i / 5].Text;
                    b[i % 5, i / 5].Text = c;//被隨機到的按鈕與第i個交換名稱

                }
            }
        }
        private void b_Click(object sender, EventArgs e) { }
  private void button1_Click(object sender, EventArgs e)
        {
            for (int j = 0; j < 25; j++)
            {
                for (int i = 0; i < j; i++)
                {
                    a[0] = r1.Next(0, j);
                    a[1] = a[0] % 5;
                    a[2] = (a[0] - a[1]) / 5;
                    c = b[a[1], a[2]].Text;
                    b[a[1], a[2]].Text = b[i % 5, i / 5].Text;
                    b[i % 5, i / 5].Text = c;
                }
            }
        }

fwcgex1529 發表在 痞客邦 留言(0) 人氣()

1 2