2015年4月10日 星期五

4/10 按鈕反應

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
class Test
{

public static void main(String[] args)
{
JFrame jtfMainFrame = new JFrame("Which Button Demo");
jtfMainFrame.setSize(450, 150);
JButton jbnButton1 = new JButton("Button 1");
JButton jbnButton2 = new JButton("Button 2");
JButton jbnButton3 = new JButton("Button 3");
JButton jbnButton4 = new JButton("Button 4");
JButton jbnButton5 = new JButton("Button 5");
JButton jbnButton6 = new JButton("Button 6");
JButton jbnButton7 = new JButton("Button 7");
JButton jbnButton8 = new JButton("Button 8");
JButton jbnButton9 = new JButton("Button 9");
jbnButton1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
System.out.println("1");
}
});
jbnButton2.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
System.out.println("2");
}
});
jbnButton3.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
System.out.println("3");
}
});
jbnButton4.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
System.out.println("4");
}
});
jbnButton5.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
System.out.println("5");
}
});
jbnButton6.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
System.out.println("6");
}
});
jbnButton7.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
System.out.println("7");
}
});
jbnButton8.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
System.out.println("8");
}
});
jbnButton9.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
System.out.println("9");
}
});

JPanel jplPanel = new JPanel();
jplPanel.add(jbnButton1);
jplPanel.add(jbnButton2);
jplPanel.add(jbnButton3);
jplPanel.add(jbnButton4);
jplPanel.add(jbnButton5);
jplPanel.add(jbnButton6);
jplPanel.add(jbnButton7);
jplPanel.add(jbnButton8);
jplPanel.add(jbnButton9);
jtfMainFrame.getContentPane().add(jplPanel, BorderLayout.CENTER);
jtfMainFrame.setVisible(true);
System.out.print("chih-yu hsu");
}
}

12312313  

2015年3月27日 星期五

3/27 簡單按鈕 JAVA

class test
{
public static void main(String[] args)
{
;
}
}
45456456  


import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class JButtonDemo2 {
JFrame jtfMainFrame;
JButton jbnButton1, jbnButton2;
JTextField jtfInput;
JPanel jplPanel;
public JButtonDemo2() {
jtfMainFrame = new JFrame("Frame1");
jtfMainFrame.setSize(50, 50);
jbnButton1 = new JButton("Button 1");
jbnButton2 = new JButton("Button 2");
jtfInput = new JTextField(20);
jplPanel = new JPanel();
jbnButton1.setMnemonic(KeyEvent.VK_I);
jbnButton1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
jtfInput.setText("Hello!");
}
});
jbnButton2.setMnemonic(KeyEvent.VK_I);
jbnButton2.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
jtfInput.setText("Hey!");
}
});
jplPanel.setLayout(new FlowLayout());
jplPanel.add(jtfInput);
jplPanel.add(jbnButton1);
jplPanel.add(jbnButton2);
jtfMainFrame.getContentPane().add(jplPanel, BorderLayout.CENTER);
jtfMainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
jtfMainFrame.pack();
jtfMainFrame.setVisible(true);
}
public static void main(String[] args) {
try {
UIManager.setLookAndFeel(UIManager
.getCrossPlatformLookAndFeelClassName());
} catch (Exception e) {
}
JButtonDemo2 application = new JButtonDemo2();
}
}
7879897456

2015年3月19日 星期四

3/20 JAVA 迴圈



----------------------------------------------------------------------------------------------------


class Test
{
public static void main(String[] args)
{
for (int i = 10; i > 0; i--) {
    System.out.println(i);
}
}
}

2015年3月13日 星期五

3/13 第二週

<html>
<head>
<title> The First Example: Hello, World </title>
</head>
<body>
<h2> This line is HTML </h2>
<script language="JavaScript">
<!--
document.write("Hello, 仁豪.This sentence is written using JavaScript.");
// Text on the right of 2 slashes is comment
/* This is comment
that occur more than 1 line
*/
//-->
</script>
<noscript>
Sorry, but your browser doesn't run JavaScript.
</noscript>
<h2> This line is HTML </h2>
</body>
</html>
java hello  

JAVA第二周
/**
 * The HelloWorldApp class implements an application that
 * simply prints "Hello World!" to standard output.
 */
class HelloWorldApp {
    public static void main(String[] args) {
        System.out.println("Hello World!"); // Display the string.
    }
}
hw2
IP
java
import java.net.*;
public class TestInet1 {
public static void main(String argv[])
{
try {
InetAddress myip = InetAddress.getLocalHost();
System.out.println(myip.getHostName());
System.out.println(myip.getHostAddress());
} catch (UnknownHostException e) {
System.out.println("Error: unable to resolve localhost");
}
}
}
hw3  
html
<html>
<head>
<title> The First Example: Hello, World </title>
</head>
<body>
<h2> This line is ID </h2>
<script language="JavaScript">
VIH_BackColor = "palegreen";
VIH_ForeColor = "navy";
VIH_FontPix = "16";
VIH_DisplayFormat = "You are visiting from:<br>IP Address: %%IP%%<br>Host: %%HOST%%";
VIH_DisplayOnPage = "yes";
</script>
<script language="JavaScript" src="http://scripts.hashemian.com/js/visitorIPHOST.js.php"></script>
<h2> This line is ID </h2>
</body>
</html>

2015年3月5日 星期四

JAVA

-------------------------------------------------------------------------------------------

1.為何修這堂課:激勵人心
2.希望從這們課得到什麼知識:JAVA
3.我要如何修習這門課:上課聽課

2015年1月8日 星期四

4X4亂數

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 WindowsFormsApplication12
{
    public partial class Form1 : Form
    {
        public System.Windows.Forms.Button Button1;
        public System.Windows.Forms.Button Button2;
        Random rand = new Random();
        Button[,] buttons = new Button[5, 5];
        public Form1()
        {
            InitializeComponent();
        }
        private void Form1_Load(object sender, EventArgs e)
        {
            Button1 = new System.Windows.Forms.Button();
            Button1.Location = new Point(300, 30);
            Button1.Size = new Size(100, 30);
            Button1.Click += new EventHandler(Button1_Click);
            Button1.Text = "change";
            this.Controls.Add(Button1);
            /*Button2 = new System.Windows.Forms.Button();
            Button2.Location = new Point(200, 50);
            Button2.Size = new Size(100, 30);
            Button2.Text = "Change";
            Button2.Click += new EventHandler(Button2_Click);
            this.Controls.Add(Button2);
             */
            for (int j = 1; j < 5; j++)
            {
                for (int i = 1; i < 5; i++)
                {
                    buttons[i, j] = new Button();
                    buttons[i, j].Location = new Point(  i * 50,  j * 50);
                    buttons[i, j].Size = new Size(50, 50);
                    this.Controls.Add(buttons[i, j]);
                }
            }
        }
        protected void Button1_Click(object sender, EventArgs e)
        {
            int x, y, a;
            int[] myarray = { 0, 1, 2, 3, 4, 5, 6, 7, 8,9,10,11,12,13,14,15 };
            for (int i = 15; i > 1; i--)
            {
                x = rand.Next(0, i);
                y = myarray[x];
                myarray[x] = myarray[i];
                myarray[i] = y;
            }
            for (int j = 1; j < 5; j++)
            {
                for (int i = 1; i < 5; i++)
                {
                    a = myarray[(j - 1) * 4 + (i - 1)];
                    buttons[i, j].Text = Convert.ToString(a);
                    this.Controls.Add(buttons[i, j]);
                }
            }
        }
        protected void Button2_Click(object sender, EventArgs e)
        {

        }
    }
}

2014年12月12日 星期五

隨機亂數不重複C#







----------------------------------------------------------------------------------------------




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 WindowsFormsApplication9
{
    public partial class Form1 : Form
    {
        Button[,] buttons = new Button[10, 10];宣告一個10乘10的按鈕
        int[] array = new int[10];宣告有1到10的變數
        public Form1()
        {
            InitializeComponent();
        }

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



            for (int i = 1; i < 10; 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 i = 0; i < 3; i++)
            {
                for (int j = 0; j < 3; j++)
                {
                    buttons[i, j] = new Button();
                    buttons[i, j].Location = new Point(i * 50, j * 50);
                    buttons[i,j].Text = j.ToString();
                    this.Controls.Add(buttons[i, j]);
                }
            }

            */

        }

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

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


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

            //buttons[1, 1].Text = array[1].ToString();

         
            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]);
            }
         

           label2.Text= array[d1].ToString();

        }
    }
}

2014年12月11日 星期四

EXCEL亂數換色(1到9)









----------------------------------------------------------------------------------------------






_Private Sub CommandButton1_Click()


For i = 1 To 9
Cells(1, i) = i
Cells(1, 1).Font.ColorIndex = 0

Next
myrnd = (Fix(Rnd() * 9) + 1)

Cells(3, 3) = myrnd

Cells(1, myrnd).Font.ColorIndex = 5

tmp = Cells(1, myrnd)

Cells(1, myrnd) = Cells(1, 9)

Cells(1, 9) = tmp

myrnd = (Fix(Rnd() * 8) + 1)

tmp = Cells(1, myrnd)

Cells(1, myrnd) = Cells(1, 8)


Cells(1, 8) = tmp


End Sub

2014年11月27日 星期四

世界勵志大使 梁凱恩

世界勵志大使 梁凱恩

今天這部勵志的短片給我最大的啟發就是他所述說那八個創造奇蹟的關鍵;其中我覺得最讓我震撼的一個關鍵點就是"人活著就是為了改變這個世界"。我覺得這句話就是創造奇蹟的起點,沒有改變,就沒有過程;沒有過程,就沒有成功。人因夢想而偉大,因改變而成功。

2014年11月20日 星期四

99乘法表

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 WindowsFormsApplication6
{
public partial class Form1 : Form
{
Button[,] buttons = new Button[10, 10];
public Form1()
{
InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)
{
for (int i = 1; i < 10; i++)
{
for (int j = 1; j < 10; j++)
{
buttons[i, j] = new Button();
buttons[i, j].Location = new Point(i * 30, j * 30);
buttons[i, j].Size = new Size(30, 30);
buttons[i, j].Text = Convert.ToString(i * j);

this.Controls.Add(buttons[i, j]);
}

}
}
}
}

2014年11月13日 星期四

99乘法表格子







----------------------------------------------------------------------------------------------------------------


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 WindowsFormsApplication2
{
    public partial class Form1 : Form
    {
        System.Windows.Forms.Button button1;
        System.Windows.Forms.Button[] buttons;
        Button[,] button = new Button[9, 9];
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            for (int i = 0; i < 9; i++)
            {
                for (int j = 0; j < 9; j++)
                {
                    button[i, j] = new Button();
                 
                    button[i, j].Location = new Point(i * 20, j * 20);
                    this.Controls.Add(button[i, j]);
                }
            }
        }
    }
}

2014年10月31日 星期五

圈圈叉叉 (判斷)

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 WindowsFormsApplication5
{
    public partial class Form1 : Form
    {
        int c = 0;
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            c = c + 1;
            int r;
            r = c % 2;

            if (r == 0)
            {
                button1.Text = "O";
            }
            else
            {
                button1.Text = "x";
            }
            textBox1.Text = Convert.ToString(r);
            button1.Enabled = false;
            judge();
           
        }

        private void button2_Click(object sender, EventArgs e)
        {
            c = c + 1;
            int r;
            r = c % 2;

            if (r == 0)
            {
                button2.Text = "O";
            }
            else
            {
                button2.Text = "x";
            }
            textBox1.Text = Convert.ToString(r);
            button2.Enabled = false;
            judge();
        }

        private void button3_Click(object sender, EventArgs e)
        {
            c = c + 1;
            int r;
            r = c % 2;

            if (r == 0)
            {
                button3.Text = "O";
            }
            else
            {
                button3.Text = "x";
            }
            textBox1.Text = Convert.ToString(r);
            button3.Enabled = false;
            judge();
        }

        private void button4_Click(object sender, EventArgs e)
        {
            c = c + 1;
            int r;
            r = c % 2;

            if (r == 0)
            {
                button4.Text = "O";
            }
            else
            {
                button4.Text = "x";
            }
            textBox1.Text = Convert.ToString(r);
            button4.Enabled = false;
            judge();
        }

        private void button5_Click(object sender, EventArgs e)
        {
            c = c + 1;
            int r;
            r = c % 2;

            if (r == 0)
            {
                button5.Text = "O";
            }
            else
            {
                button5.Text = "x";
            }
            textBox1.Text = Convert.ToString(r);
            button5.Enabled = false;
            judge();
        }

        private void button6_Click(object sender, EventArgs e)
        {
            c = c + 1;
            int r;
            r = c % 2;

            if (r == 0)
            {
                button6.Text = "O";
            }
            else
            {
                button6.Text = "x";
            }
            textBox1.Text = Convert.ToString(r);
            button6.Enabled = false;
            judge();
        }

        private void button7_Click(object sender, EventArgs e)
        {
            c = c + 1;
            int r;
            r = c % 2;

            if (r == 0)
            {
                button7.Text = "O";
            }
            else
            {
                button7.Text = "x";
            }
            textBox1.Text = Convert.ToString(r);
            button7.Enabled = false;
            judge();
        }

        private void button8_Click(object sender, EventArgs e)
        {
            c = c + 1;
            int r;
            r = c % 2;

            if (r == 0)
            {
                button8.Text = "O";
            }
            else
            {
                button8.Text = "x";
            }
            textBox1.Text = Convert.ToString(r);
            button8.Enabled = false;
            judge();
        }

        private void button9_Click(object sender, EventArgs e)
        {
            c = c + 1;
            int r;
            r = c % 2;

            if (r == 0)
            {
                button9.Text = "O";
            }
            else
            {
                button9.Text = "x";
            }
            textBox1.Text = Convert.ToString(r);
            button9.Enabled = false;
            judge();
        }
        private void judge()
        {
            if(button1.Text==("x") && button2.Text==("x") && button3.Text==("x"))
            {
            MessageBox.Show("X好棒棒!");
            }
                if(button4.Text==("x") && button5.Text==("x") && button6.Text==("x"))
                {
                    MessageBox.Show("X好棒棒!");
                }
                if(button7.Text==("x") && button8.Text==("x") && button9.Text==("x"))
                {
            MessageBox.Show("X好棒棒!");
                }
                if(button1.Text==("x") && button4.Text==("x") && button7.Text==("x"))
                {
            MessageBox.Show("X好棒棒!");
                }
                if(button2.Text==("x") && button5.Text==("x") && button8.Text==("x"))
                {
            MessageBox.Show("X好棒棒!");
                }
                if(button3.Text==("x") && button6.Text==("x") && button9.Text==("x"))
                {
            MessageBox.Show("X好棒棒!");
                }
                if(button1.Text==("x") && button5.Text==("x") && button9.Text==("x"))
                {
            MessageBox.Show("X好棒棒!");
                }
                if (button3.Text == ("x") && button5.Text == ("x") && button7.Text == ("x"))
                {
                    MessageBox.Show("X好棒棒!");
}
}
}

2014年10月24日 星期五

圈圈叉叉



======================================================================




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 WindowsFormsApplication2
{
    public partial class Form1 : Form
    {
        int c = 0;宣告一個變數C
        public Form1()
        {
            InitializeComponent();
        }

        private void button3_Click(object sender, EventArgs e)
        {
            c = c + 1;
            int r; 設一個變數r
            r = c % 2; 設r為變數c除以2的餘數

            if (r == 0)假設r=0
            {
                button3.Text = "O";則按鈕顯示為"O"
            }
            else否則為"X"
            {
                button3.Text = "x";
            }
            textBox1.Text = Convert.ToString(r);
            button3.Enabled = false;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            c = c + 1;
            int r ;
            r = c % 2;

            if (r == 0)
            {
                button1.Text="O";
            }
            else
            {
                button1.Text="x";
            }
            textBox1.Text=Convert.ToString(r);
            button1.Enabled = false;
        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {
         
        }

        private void button2_Click(object sender, EventArgs e)
        {
            c = c + 1;
            int r;
            r = c % 2;

            if (r == 0)
            {
                button2.Text = "O";
            }
            else
            {
                button2.Text = "x";
            }
            textBox1.Text = Convert.ToString(r);
            button2.Enabled = false;
        }

        private void button4_Click(object sender, EventArgs e)
        {
            c = c + 1;
            int r;
            r = c % 2;

            if (r == 0)
            {
                button4.Text = "O";
            }
            else
            {
                button4.Text = "x";
            }
            textBox1.Text = Convert.ToString(r);
            button4.Enabled = false;
        }

        private void button5_Click(object sender, EventArgs e)
        {
            c = c + 1;
            int r;
            r = c % 2;

            if (r == 0)
            {
                button5.Text = "O";
            }
            else
            {
                button5.Text = "x";
            }
            textBox1.Text = Convert.ToString(r);
            button5.Enabled = false;
        }

        private void button6_Click(object sender, EventArgs e)
        {
            c = c + 1;
            int r;
            r = c % 2;

            if (r == 0)
            {
                button6.Text = "O";
            }
            else
            {
                button6.Text = "x";
            }
            textBox1.Text = Convert.ToString(r);
            button6.Enabled = false;
        }

        private void button7_Click(object sender, EventArgs e)
        {
            c = c + 1;
            int r;
            r = c % 2;

            if (r == 0)
            {
                button7.Text = "O";
            }
            else
            {
                button7.Text = "x";
            }
            textBox1.Text = Convert.ToString(r);
            button7.Enabled = false;
        }

        private void button8_Click(object sender, EventArgs e)
        {
            c = c + 1;
            int r;
            r = c % 2;

            if (r == 0)
            {
                button8.Text = "O";
            }
            else
            {
                button8.Text = "x";
            }
            textBox1.Text = Convert.ToString(r);
            button8.Enabled = false;
        }

        private void button9_Click(object sender, EventArgs e)
        {
            c = c + 1;
            int r;
            r = c % 2;

            if (r == 0)
            {
                button9.Text = "O";
            }
            else
            {
                button9.Text = "x";
            }
            textBox1.Text = Convert.ToString(r);
            button9.Enabled = false;
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }
    }
}

2014年10月23日 星期四

兩批馬亂跑


=======================================================================




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;
using System.Threading;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        int ssum1 = 0;
        int ssum2 = 0;
        public Form1()
        {
         
            InitializeComponent();
        }

        private void label1_Click(object sender, EventArgs e)
        {

        }

        private void label2_Click(object sender, EventArgs e)
        {

        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {
            int d1, d2, dsum;
            Random ir = new Random();
            d1 = ir.Next(1, 7);
            d2 = ir.Next(1, 7);
            label1.Text = Convert.ToString(d1);
            label2.Text = Convert.ToString(d2);
            dsum = d1 + d2;
            for (int i = 1; i <= dsum; i++)
            {
                button2.Left = i + ssum1;
                Thread.Sleep(100); //Delay 1秒
                Application.DoEvents();

            }
                textBox1.Text = Convert.ToString(ssum1);
         
            ssum1 = ssum1 + dsum;
            if (button2.Left >= 100)
            {
                MessageBox.Show  ("馬1獲勝");
            }

        }

        private void button4_Click(object sender, EventArgs e)
        {

        }

        private void button3_Click(object sender, EventArgs e)
        {
            int d1, d2, dsum;
            Random ir = new Random();
            d1 = ir.Next(1, 7);
            d2 = ir.Next(1, 7);
            label1.Text = Convert.ToString(d1);
            label2.Text = Convert.ToString(d2);
            dsum = d1 + d2;
            for (int i = 1; i <= dsum; i++)
            {
                button4.Left = i + ssum2;
                Thread.Sleep(100); //Delay 1秒
                Application.DoEvents();

            }
            textBox1.Text = Convert.ToString(ssum2);

            ssum2 = ssum2 + dsum;
        }

        private void button2_Click(object sender, EventArgs e)
        {

        }
    }
}