按鈕排列
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);
JPanel jplPanel = new JPanel();
int i;
int j=1;
int num1 , num2;
JButton jbnButton[] = new JButton[9];
JButton changeButton[] = new JButton[2];
jplPanel.setLayout (new GridLayout(3, 3));
for(i = 0;i<=8;i++){
jbnButton[i]=new JButton("Button"+(i+1));
jplPanel.add(jbnButton[i]);
String s = Integer.toString(i+1);
jbnButton[i].addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
/*if(j<2){
changeButton[j] = jbnButton[i];
num1 = i;
j++;
}
else if(j==2){
changeButton[j]=jbnButton[i];
jbnButton[num1] = changeButton[j];
jbnButton[i] = changeButton[j-1];
j=1;
}*/
//j++;
//JButton btn = (JButton[i])e.getSourec();
//lab.setText(btn.getLabel+".");
System.out.println("Button"+s);
}
});
}
jtfMainFrame.getContentPane().add(jplPanel, BorderLayout.CENTER);
jtfMainFrame.setVisible(true);
System.out.print("chih-yu hsu");
}
}
2015年4月17日 星期五
2015年4月10日 星期五
java 第四章 迴圈製作按鍵
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);
JPanel jplPanel = new JPanel();
int i;
int j=1;
JButton jbnButton[] = new JButton[9];
for(i = 0;i<=8;i++){
//JButton jbnButton1 = new JButton("Button 1")
//jbnButton[i] = new JButton();
jbnButton[i]=new JButton("Button"+(i+1));
jplPanel.add(jbnButton[i]);
String s = Integer.toString(i+1);
jbnButton[i].addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
System.out.println("Button"+s);
}
});
}
jtfMainFrame.getContentPane().add(jplPanel, BorderLayout.CENTER);
jtfMainFrame.setVisible(true);
System.out.print("chih-yu hsu");
}
}
2015年3月19日 星期四
java第三周上課內容
excel vba forloop 展示1~10
java 展示 1~10
程式碼
class ForDemo1 {
public static void main(String[] args) {
int i;
for (i = 1; i <= 10; i++) {
System.out.println(i);
}
}
}
java 展示 1~10
程式碼
class ForDemo1 {
public static void main(String[] args) {
int i;
for (i = 1; i <= 10; i++) {
System.out.println(i);
}
}
}
javascript 展示 1~10
程式碼
<HTML>
<HEAD>
</HEAD>
<BODY>
<script language="JavaScript">
for (i=1; i<=10; i=i+1)
{
document.write(i );
}
</SCRIPT>
</BODY>
</HTML>
2015年3月12日 星期四
java第二周上課內容
超連結:http://taiwantc.com/js/js_tut_a1.htm
打開wordpad 複製以下內容
<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>
儲存名稱 firstjava.html
使用google chrome開啟 IE不可
打開wordpad 複製以下內容
<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>
儲存名稱 firstjava.html
使用google chrome開啟 IE不可
java檢查ip
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"); } } }
javascript 查ip
<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>
2015年3月5日 星期四
java 第一周上課內容
1.為何why要選修這門課?(動機)
A:學習Java
2.希忘從這門課獲得那些知識?(目標)
A:Java相關知識
3.我要如何修習這一門課?(態度與方法)
A:認真(應該)
環境變數
class Test
{
public static void main(String[] args)
{
System.out.println("_____*_____");
System.out.println("____***____");
System.out.println("___*****___");
System.out.println("__*******__");
System.out.println("_____*_____");
System.out.println("_____*_____");
}
}
A:學習Java
2.希忘從這門課獲得那些知識?(目標)
A:Java相關知識
3.我要如何修習這一門課?(態度與方法)
A:認真(應該)
環境變數
第一周實作
class Test
{
public static void main(String[] args)
{
System.out.println("_____*_____");
System.out.println("____***____");
System.out.println("___*****___");
System.out.println("__*******__");
System.out.println("_____*_____");
System.out.println("_____*_____");
}
}
2014年12月12日 星期五
16X16
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[5, 5];
int i, j, sum, rn, rn1;
int[] a = new int[17], b = new int[17];
bool a1 = false, b1 = false;
string cho1, cho2;
int ch1i, ch1j, ch2i, ch2j,ch1,ch2;
bool onechoice = false;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
for (i = 1; i <= 16; i++)
{
a[i] = i;
}
for (i = 1; i <= 16; i++)
{
Random rn = new Random();
rn1 = rn.Next(1, 17 - i);
b[i] = a[rn1];
for (j = rn1; j <= 16 - i; j++)
{
a[j] = a[j + 1];
}
}
for (i = 1; i <= 4; i++)
{
for (j = 1; j <= 4; j++)
{
sum += 1;
buttons[i, j] = new Button();
buttons[i, j].TabIndex = sum;
buttons[i, j].Text = Convert.ToString(b[sum]);
if (b[sum] == 16)
{
buttons[i, j].Text = null;
}
buttons[i, j].Location = new Point(i * 50, j * 50);
buttons[i, j].Size = new Size(50, 50);
this.Controls.Add(buttons[i, j]);
buttons[i, j].Click += new EventHandler(buttons_Click);
}
}
}
private void buttons_Click(object sender, EventArgs e)
{
Button temp = (Button)sender;
label1.Text = temp.Text;
//MessageBox.Show(onechoice.ToString());
if (a1 == false)
{
cho1 = temp.Text;
a1 = true;
//MessageBox.Show(temp.Text);
}
else if (b1 == false && a1 == true)
{
//MessageBox.Show("2");
cho2 = temp.Text;
a1 = false;
}
for (int i = 1; i < 5; i++)
{
for (int j = 1; j <5 ; j++)
{
//MessageBox.Show(onechoice.ToString());
if (onechoice.ToString() == "False")
{
if (buttons[i,j].Text==cho1)
{
ch1i = i;
ch1j = j;
cho1 = temp.Text;
//MessageBox.Show(ch1i+","+ch1j);
onechoice = true;
}
}
else if(onechoice==true)
{
//onechoice = false;
if (temp.Text == buttons[i, j].Text)
{
//MessageBox.Show("1");
onechoice = false;
ch2i = i;
ch2j = j;
cho2 = temp.Text;
buttons[ch1i, ch1j].Text = cho2;
buttons[ch2i, ch2j].Text = cho1;
for (i = 1; i <= 4; i++)
{
for (j = 1; j <= 4; j++)
{
sum += 1;
buttons[i, j] = new Button();
buttons[i, j].TabIndex = sum;
//buttons[i, j].Text = Convert.ToString(b[sum]);
/*if (b[sum] == 16)
{
buttons[i, j].Text = null;
}*/
buttons[i, j].Location = new Point(i * 50, j * 50);
buttons[i, j].Size = new Size(50, 50);
this.Controls.Add(buttons[i, j]);
//buttons[i, j].Click += new EventHandler(buttons_Click);
}
}
}
}
}
}
}
}
}
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[5, 5];
int i, j, sum, rn, rn1;
int[] a = new int[17], b = new int[17];
bool a1 = false, b1 = false;
string cho1, cho2;
int ch1i, ch1j, ch2i, ch2j,ch1,ch2;
bool onechoice = false;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
for (i = 1; i <= 16; i++)
{
a[i] = i;
}
for (i = 1; i <= 16; i++)
{
Random rn = new Random();
rn1 = rn.Next(1, 17 - i);
b[i] = a[rn1];
for (j = rn1; j <= 16 - i; j++)
{
a[j] = a[j + 1];
}
}
for (i = 1; i <= 4; i++)
{
for (j = 1; j <= 4; j++)
{
sum += 1;
buttons[i, j] = new Button();
buttons[i, j].TabIndex = sum;
buttons[i, j].Text = Convert.ToString(b[sum]);
if (b[sum] == 16)
{
buttons[i, j].Text = null;
}
buttons[i, j].Location = new Point(i * 50, j * 50);
buttons[i, j].Size = new Size(50, 50);
this.Controls.Add(buttons[i, j]);
buttons[i, j].Click += new EventHandler(buttons_Click);
}
}
}
private void buttons_Click(object sender, EventArgs e)
{
Button temp = (Button)sender;
label1.Text = temp.Text;
//MessageBox.Show(onechoice.ToString());
if (a1 == false)
{
cho1 = temp.Text;
a1 = true;
//MessageBox.Show(temp.Text);
}
else if (b1 == false && a1 == true)
{
//MessageBox.Show("2");
cho2 = temp.Text;
a1 = false;
}
for (int i = 1; i < 5; i++)
{
for (int j = 1; j <5 ; j++)
{
//MessageBox.Show(onechoice.ToString());
if (onechoice.ToString() == "False")
{
if (buttons[i,j].Text==cho1)
{
ch1i = i;
ch1j = j;
cho1 = temp.Text;
//MessageBox.Show(ch1i+","+ch1j);
onechoice = true;
}
}
else if(onechoice==true)
{
//onechoice = false;
if (temp.Text == buttons[i, j].Text)
{
//MessageBox.Show("1");
onechoice = false;
ch2i = i;
ch2j = j;
cho2 = temp.Text;
buttons[ch1i, ch1j].Text = cho2;
buttons[ch2i, ch2j].Text = cho1;
for (i = 1; i <= 4; i++)
{
for (j = 1; j <= 4; j++)
{
sum += 1;
buttons[i, j] = new Button();
buttons[i, j].TabIndex = sum;
//buttons[i, j].Text = Convert.ToString(b[sum]);
/*if (b[sum] == 16)
{
buttons[i, j].Text = null;
}*/
buttons[i, j].Location = new Point(i * 50, j * 50);
buttons[i, j].Size = new Size(50, 50);
this.Controls.Add(buttons[i, j]);
//buttons[i, j].Click += new EventHandler(buttons_Click);
}
}
}
}
}
}
}
}
}
2014年11月13日 星期四
9X9
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
{
Button[,] buttons = new Button[10, 10];
int i, j,sum;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
for (i = 1; i <= 9; i++)
{
for (j = 1; j <= 9; j++)
{
sum=i*j;
buttons[i, j] = new Button();
buttons[i, j].Text = Convert.ToString(sum);
buttons[i, j].Location = new Point( i*50, j*50);
buttons[i, j].Size = new Size(50, 50);
this.Controls.Add(buttons[i, j]);
}
}
label1.Text = Convert.ToString(buttons[1, 1].Name);
/*Button1 = new System.Windows.Forms.Button();
Button1.Location = new Point(100, 100);
Button1.Size = new Size(100, 100);
this.Controls.Add(Button1);
Button[] btuArray = new Button[3];
Button1.Click += new EventHandler(button1_Click);*/
}
}
}
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
{
Button[,] buttons = new Button[10, 10];
int i, j,sum;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
for (i = 1; i <= 9; i++)
{
for (j = 1; j <= 9; j++)
{
sum=i*j;
buttons[i, j] = new Button();
buttons[i, j].Text = Convert.ToString(sum);
buttons[i, j].Location = new Point( i*50, j*50);
buttons[i, j].Size = new Size(50, 50);
this.Controls.Add(buttons[i, j]);
}
}
label1.Text = Convert.ToString(buttons[1, 1].Name);
/*Button1 = new System.Windows.Forms.Button();
Button1.Location = new Point(100, 100);
Button1.Size = new Size(100, 100);
this.Controls.Add(Button1);
Button[] btuArray = new Button[3];
Button1.Click += new EventHandler(button1_Click);*/
}
}
}
訂閱:
文章 (Atom)