C# 程式設計工藝大師:http://tccnchsu.blogspot.tw/
2015年5月29日 星期五
2015年5月9日 星期六
智慧推盤 完成品
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.Random;
class Test
{
public static int num[] = new int[42];
public static int numl = 16;
public static int chosenum[] = new int[2];
public static int chosenumno = 0;
public static int chosebtID = 0;
public static int chose = 0;
public static Boolean first = false;
public static void main(String[] args)
{
JFrame jtfMainFrame = new JFrame("Which Button Demo");
jtfMainFrame.setSize(450, 150);
JPanel jplPanel = new JPanel();
int i;
int num1 , num2;
//if(first == false){
for( i = 0 ;i<16;i++){
num[i] = i+1;
}
//first = true;
//}
JButton jbnButton[] = new JButton[16];
int buttonNum[] = new int[16];
jplPanel.setLayout (new GridLayout(4, 4));
for(i = 0;i<=15;i++){
Random ran = new Random();
chose = ran.nextInt(numl);
if(num[chose] == 16)
jbnButton[i]=new JButton("");
else
jbnButton[i]=new JButton(""+num[chose]);
buttonNum[i] = num[chose];
jplPanel.add(jbnButton[i]);
for(int j = chose ;j<numl;j++){
num[j] = num[j+1];
}
numl--;
System.out.println(numl);
jbnButton[i].addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
int i;
Boolean canmove = false;
Boolean GameOver = false;
int canmoveID = 0;
for( i=0; i<jbnButton.length; i++){
if(e.getSource() == jbnButton[i]){
/*if(chosenumno == 0){
chosenum[chosenumno] = buttonNum[i];
chosebtID = i;
chosenumno++;
}
else{
chosenum[chosenumno] = buttonNum[i];
buttonNum[chosebtID] = chosenum[chosenumno];
buttonNum[i] = chosenum[chosenumno-1];
if(buttonNum[i] == 16)
jbnButton[i].setText("");
else
jbnButton[i].setText(""+buttonNum[i]);
if(buttonNum[chosebtID] == 16)
jbnButton[chosebtID].setText("");
else
jbnButton[chosebtID].setText(""+buttonNum[chosebtID]);
chosenumno = 0;
}*/
if(i-1>=0 && canmove == false){
if(buttonNum[i-1] == 16){
buttonNum[i-1] = buttonNum[i];
buttonNum[i] = 16;
jbnButton[i-1].setText(""+buttonNum[i-1]);
jbnButton[i].setText("");
canmove = true;
}
}
if(i-4>=0 && canmove == false){
if(buttonNum[i-4] == 16){
buttonNum[i-4] = buttonNum[i];
buttonNum[i] = 16;
jbnButton[i-4].setText(""+buttonNum[i-4]);
jbnButton[i].setText("");
canmove = true;
}
}
if(i+1<=15 && canmove == false){
if(buttonNum[i+1] == 16){
buttonNum[i+1] = buttonNum[i];
buttonNum[i] = 16;
jbnButton[i+1].setText(""+buttonNum[i+1]);
jbnButton[i].setText("");
canmove = true;
}
}
if(i+4>=0 && canmove == false){
if(buttonNum[i+4] == 16){
buttonNum[i+4] = buttonNum[i];
buttonNum[i] = 16;
jbnButton[i+4].setText(""+buttonNum[i+4]);
jbnButton[i].setText("");
canmove = true;
}
}
for(int j = 0 ; j<16; j++){
if(buttonNum[j] != j+1)
break;
else if(j == 15 && buttonNum[j] == 16){
JFrame jtfMainFrame1 = new JFrame("WIN");
jtfMainFrame1.setSize(450, 150);
JPanel jplPanel1 = new JPanel();
jtfMainFrame1.getContentPane().add(jplPanel1, BorderLayout.CENTER);
jtfMainFrame1.setVisible(true);
}
}
canmove = false;
}
}
}
});
}
jtfMainFrame.getContentPane().add(jplPanel, BorderLayout.CENTER);
jtfMainFrame.setVisible(true);
//System.out.print("Yang");
}
}
import java.awt.event.*;
import javax.swing.*;
import java.util.Random;
class Test
{
public static int num[] = new int[42];
public static int numl = 16;
public static int chosenum[] = new int[2];
public static int chosenumno = 0;
public static int chosebtID = 0;
public static int chose = 0;
public static Boolean first = false;
public static void main(String[] args)
{
JFrame jtfMainFrame = new JFrame("Which Button Demo");
jtfMainFrame.setSize(450, 150);
JPanel jplPanel = new JPanel();
int i;
int num1 , num2;
//if(first == false){
for( i = 0 ;i<16;i++){
num[i] = i+1;
}
//first = true;
//}
JButton jbnButton[] = new JButton[16];
int buttonNum[] = new int[16];
jplPanel.setLayout (new GridLayout(4, 4));
for(i = 0;i<=15;i++){
Random ran = new Random();
chose = ran.nextInt(numl);
if(num[chose] == 16)
jbnButton[i]=new JButton("");
else
jbnButton[i]=new JButton(""+num[chose]);
buttonNum[i] = num[chose];
jplPanel.add(jbnButton[i]);
for(int j = chose ;j<numl;j++){
num[j] = num[j+1];
}
numl--;
System.out.println(numl);
jbnButton[i].addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
int i;
Boolean canmove = false;
Boolean GameOver = false;
int canmoveID = 0;
for( i=0; i<jbnButton.length; i++){
if(e.getSource() == jbnButton[i]){
/*if(chosenumno == 0){
chosenum[chosenumno] = buttonNum[i];
chosebtID = i;
chosenumno++;
}
else{
chosenum[chosenumno] = buttonNum[i];
buttonNum[chosebtID] = chosenum[chosenumno];
buttonNum[i] = chosenum[chosenumno-1];
if(buttonNum[i] == 16)
jbnButton[i].setText("");
else
jbnButton[i].setText(""+buttonNum[i]);
if(buttonNum[chosebtID] == 16)
jbnButton[chosebtID].setText("");
else
jbnButton[chosebtID].setText(""+buttonNum[chosebtID]);
chosenumno = 0;
}*/
if(i-1>=0 && canmove == false){
if(buttonNum[i-1] == 16){
buttonNum[i-1] = buttonNum[i];
buttonNum[i] = 16;
jbnButton[i-1].setText(""+buttonNum[i-1]);
jbnButton[i].setText("");
canmove = true;
}
}
if(i-4>=0 && canmove == false){
if(buttonNum[i-4] == 16){
buttonNum[i-4] = buttonNum[i];
buttonNum[i] = 16;
jbnButton[i-4].setText(""+buttonNum[i-4]);
jbnButton[i].setText("");
canmove = true;
}
}
if(i+1<=15 && canmove == false){
if(buttonNum[i+1] == 16){
buttonNum[i+1] = buttonNum[i];
buttonNum[i] = 16;
jbnButton[i+1].setText(""+buttonNum[i+1]);
jbnButton[i].setText("");
canmove = true;
}
}
if(i+4>=0 && canmove == false){
if(buttonNum[i+4] == 16){
buttonNum[i+4] = buttonNum[i];
buttonNum[i] = 16;
jbnButton[i+4].setText(""+buttonNum[i+4]);
jbnButton[i].setText("");
canmove = true;
}
}
for(int j = 0 ; j<16; j++){
if(buttonNum[j] != j+1)
break;
else if(j == 15 && buttonNum[j] == 16){
JFrame jtfMainFrame1 = new JFrame("WIN");
jtfMainFrame1.setSize(450, 150);
JPanel jplPanel1 = new JPanel();
jtfMainFrame1.getContentPane().add(jplPanel1, BorderLayout.CENTER);
jtfMainFrame1.setVisible(true);
}
}
canmove = false;
}
}
}
});
}
jtfMainFrame.getContentPane().add(jplPanel, BorderLayout.CENTER);
jtfMainFrame.setVisible(true);
//System.out.print("Yang");
}
}
2015年5月8日 星期五
第七周 按鈕名稱亂數不重複
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.Random;
class Test
{
public static int num[] = new int[42];
public static int numl = 16;
public static int numno = 0;
public static int chose = 0;
public static Boolean first = false;
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;
//if(first == false){
for( i = 0 ;i<16;i++){
num[i] = i+1;
}
//first = true;
//}
JButton jbnButton[] = new JButton[16];
JButton changeButton[] = new JButton[2];
jplPanel.setLayout (new GridLayout(4, 4));
for(i = 0;i<=15;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) {
Random ran = new Random();
chose = ran.nextInt(numl);
System.out.println(chose);
int i;
for( i=0; i<jbnButton.length; i++){
if(e.getSource() == jbnButton[i]){
jbnButton[i].setText(""+num[chose]);
}
}
for(i = chose ;i<numl;i++){
num[i] = num[i+1];
//System.out.println(num[chose]);
}
numl--;
System.out.println(numl);
for(i = 0 ;i<numl;i++){
//System.out.println(num[i]);
}
}
});
}
jtfMainFrame.getContentPane().add(jplPanel, BorderLayout.CENTER);
jtfMainFrame.setVisible(true);
System.out.print("Yang");
}
}
import java.awt.event.*;
import javax.swing.*;
import java.util.Random;
class Test
{
public static int num[] = new int[42];
public static int numl = 16;
public static int numno = 0;
public static int chose = 0;
public static Boolean first = false;
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;
//if(first == false){
for( i = 0 ;i<16;i++){
num[i] = i+1;
}
//first = true;
//}
JButton jbnButton[] = new JButton[16];
JButton changeButton[] = new JButton[2];
jplPanel.setLayout (new GridLayout(4, 4));
for(i = 0;i<=15;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) {
Random ran = new Random();
chose = ran.nextInt(numl);
System.out.println(chose);
int i;
for( i=0; i<jbnButton.length; i++){
if(e.getSource() == jbnButton[i]){
jbnButton[i].setText(""+num[chose]);
}
}
for(i = chose ;i<numl;i++){
num[i] = num[i+1];
//System.out.println(num[chose]);
}
numl--;
System.out.println(numl);
for(i = 0 ;i<numl;i++){
//System.out.println(num[i]);
}
}
});
}
jtfMainFrame.getContentPane().add(jplPanel, BorderLayout.CENTER);
jtfMainFrame.setVisible(true);
System.out.print("Yang");
}
}
2015年4月24日 星期五
第六周
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[16];
JButton changeButton[] = new JButton[2];
jplPanel.setLayout (new GridLayout(4, 4));
for(i = 0;i<=15;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) {
System.out.println("Button"+s);
}
});
}
jtfMainFrame.getContentPane().add(jplPanel, BorderLayout.CENTER);
jtfMainFrame.setVisible(true);
System.out.print("Yang");
}
}
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[16];
JButton changeButton[] = new JButton[2];
jplPanel.setLayout (new GridLayout(4, 4));
for(i = 0;i<=15;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) {
System.out.println("Button"+s);
}
});
}
jtfMainFrame.getContentPane().add(jplPanel, BorderLayout.CENTER);
jtfMainFrame.setVisible(true);
System.out.print("Yang");
}
}
2015年4月17日 星期五
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;
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");
}
}
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月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>
訂閱:
文章 (Atom)