2015年12月11日 星期五
2015年11月20日 星期五
2015年11月5日 星期四
計算機
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
textBox3.Text = System.Convert.ToString(Double.Parse(textBox1.Text) + Double.Parse(textBox2.Text));
}
private void label2_Click(object sender, EventArgs e)
{
}
private void button2_Click(object sender, EventArgs e)
{
textBox3.Text = System.Convert.ToString(Double.Parse(textBox1.Text) - Double.Parse(textBox2.Text));
}
private void button3_Click(object sender, EventArgs e)
{
textBox3.Text = System.Convert.ToString(Double.Parse(textBox1.Text) * Double.Parse(textBox2.Text));
}
private void button4_Click(object sender, EventArgs e)
{
textBox3.Text = System.Convert.ToString(Double.Parse(textBox1.Text) / Double.Parse(textBox2.Text));
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
}
private void textBox2_TextChanged(object sender, EventArgs e)
{
}
private void label1_Click(object sender, EventArgs e)
{
}
private void textBox3_TextChanged(object sender, EventArgs e)
{
}
private void textBox1_TextChanged_1(object sender, EventArgs e)
{
}
private void button1_Click_1(object sender, EventArgs e)
{
textBox3.Text = System.Convert.ToString(Double.Parse(textBox1.Text) + Double.Parse(textBox2.Text));
}
private void button2_Click_1(object sender, EventArgs e)
{
textBox3.Text = System.Convert.ToString(Double.Parse(textBox1.Text) - Double.Parse(textBox2.Text));
}
private void button3_Click_1(object sender, EventArgs e)
{
textBox3.Text = System.Convert.ToString(Double.Parse(textBox1.Text) * Double.Parse(textBox2.Text));
}
private void button4_Click_1(object sender, EventArgs e)
{
textBox3.Text = System.Convert.ToString(Double.Parse(textBox1.Text) / Double.Parse(textBox2.Text));
}
}
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
textBox3.Text = System.Convert.ToString(Double.Parse(textBox1.Text) + Double.Parse(textBox2.Text));
}
private void label2_Click(object sender, EventArgs e)
{
}
private void button2_Click(object sender, EventArgs e)
{
textBox3.Text = System.Convert.ToString(Double.Parse(textBox1.Text) - Double.Parse(textBox2.Text));
}
private void button3_Click(object sender, EventArgs e)
{
textBox3.Text = System.Convert.ToString(Double.Parse(textBox1.Text) * Double.Parse(textBox2.Text));
}
private void button4_Click(object sender, EventArgs e)
{
textBox3.Text = System.Convert.ToString(Double.Parse(textBox1.Text) / Double.Parse(textBox2.Text));
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
}
private void textBox2_TextChanged(object sender, EventArgs e)
{
}
private void label1_Click(object sender, EventArgs e)
{
}
private void textBox3_TextChanged(object sender, EventArgs e)
{
}
private void textBox1_TextChanged_1(object sender, EventArgs e)
{
}
private void button1_Click_1(object sender, EventArgs e)
{
textBox3.Text = System.Convert.ToString(Double.Parse(textBox1.Text) + Double.Parse(textBox2.Text));
}
private void button2_Click_1(object sender, EventArgs e)
{
textBox3.Text = System.Convert.ToString(Double.Parse(textBox1.Text) - Double.Parse(textBox2.Text));
}
private void button3_Click_1(object sender, EventArgs e)
{
textBox3.Text = System.Convert.ToString(Double.Parse(textBox1.Text) * Double.Parse(textBox2.Text));
}
private void button4_Click_1(object sender, EventArgs e)
{
textBox3.Text = System.Convert.ToString(Double.Parse(textBox1.Text) / Double.Parse(textBox2.Text));
}
}
}
2015年10月30日 星期五
4*4路數不重複
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApplication4
{
public partial class Form1 : Form
{Button[,] Buttons = new System.Windows.Forms.Button[5, 5];
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
for (int i = 1; i < 5; i++ )
{
for (int j = 1; j < 5; j++ )
{
Buttons[i, j] = new Button();
Buttons[i, j].Size = new Size(50, 50);
Buttons[i, j].Location = new Point(i * 50, j * 50);
this.Controls.Add(Buttons[i, j]);//出現在畫面中
}
}
}
private void button1_Click(object sender, EventArgs e)
{
int pro = 0;
for (int i = 1; i < 5; i++)
{
for (int j = 1; j < 5; j++)
{
pro = pro+1 ;
Buttons[i, j].Text = pro.ToString();
}
}
}
}
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApplication4
{
public partial class Form1 : Form
{Button[,] Buttons = new System.Windows.Forms.Button[5, 5];
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
for (int i = 1; i < 5; i++ )
{
for (int j = 1; j < 5; j++ )
{
Buttons[i, j] = new Button();
Buttons[i, j].Size = new Size(50, 50);
Buttons[i, j].Location = new Point(i * 50, j * 50);
this.Controls.Add(Buttons[i, j]);//出現在畫面中
}
}
}
private void button1_Click(object sender, EventArgs e)
{
int pro = 0;
for (int i = 1; i < 5; i++)
{
for (int j = 1; j < 5; j++)
{
pro = pro+1 ;
Buttons[i, j].Text = pro.ToString();
}
}
}
}
}
2015年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.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
int rndmoney1 = 0;
int rndmoney2 = 0;
int rndmoney3 = 0;
int rndmoney4 = 0;
int rndmoney5 = 0;
int rndmoney6 = 0;
int rndmoney7 = 0;
int rndmoney8 = 0;
int rndmoney9 = 0;
public Form1()
{
InitializeComponent();
button1.Enabled = false;
button2.Enabled = false;
button3.Enabled = false;
button4.Enabled = false;
button5.Enabled = false;
button6.Enabled = false;
button7.Enabled = false;
button8.Enabled = false;
button9.Enabled = false;
}
private void button10_Click(object sender, EventArgs e)
{
Random rnd = new Random();
rndmoney1 = rnd.Next(0, 9); // creates a number between 1 and 9
rndmoney2 = rnd.Next(0, 9); // creates a number between 1 and 9
//rndmoney3 = rnd.Next(0, 9); // creates a number between 1 and 9
//rndmoney4 = rnd.Next(0, 10); // creates a number between 1 and 9
//rndmoney5 = rnd.Next(0, 10); // creates a number between 1 and 9
//rndmoney6 = rnd.Next(0, 10); // creates a number between 1 and 9
//rndmoney7 = rnd.Next(0, 10); // creates a number between 1 and 9
//rndmoney8 = rnd.Next(0, 10); // creates a number between 1 and 9
//rndmoney9 = rnd.Next(0, 10); // creates a number between 1 and 9
button1.Text = rndmoney1.ToString();
button2.Text = rndmoney2.ToString();
if (rndmoney1 == rndmoney2)
{
MessageBox.Show("Dot Net Perls is awesome.");
rndmoney2 = rnd.Next(0, 9); // creates a number between 1 and 9
button2.Text = rndmoney2.ToString();
}
//button3.Text = rndmoney3.ToString();
//button4.Text = rndmoney4.ToString();
//button5.Text = rndmoney5.ToString();
//button6.Text = rndmoney6.ToString();
//button7.Text = rndmoney7.ToString();
//button8.Text = rndmoney8.ToString();
//button9.Text = rndmoney9.ToString();
//button10.Enabled = false;
}
}
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
int rndmoney1 = 0;
int rndmoney2 = 0;
int rndmoney3 = 0;
int rndmoney4 = 0;
int rndmoney5 = 0;
int rndmoney6 = 0;
int rndmoney7 = 0;
int rndmoney8 = 0;
int rndmoney9 = 0;
public Form1()
{
InitializeComponent();
button1.Enabled = false;
button2.Enabled = false;
button3.Enabled = false;
button4.Enabled = false;
button5.Enabled = false;
button6.Enabled = false;
button7.Enabled = false;
button8.Enabled = false;
button9.Enabled = false;
}
private void button10_Click(object sender, EventArgs e)
{
Random rnd = new Random();
rndmoney1 = rnd.Next(0, 9); // creates a number between 1 and 9
rndmoney2 = rnd.Next(0, 9); // creates a number between 1 and 9
//rndmoney3 = rnd.Next(0, 9); // creates a number between 1 and 9
//rndmoney4 = rnd.Next(0, 10); // creates a number between 1 and 9
//rndmoney5 = rnd.Next(0, 10); // creates a number between 1 and 9
//rndmoney6 = rnd.Next(0, 10); // creates a number between 1 and 9
//rndmoney7 = rnd.Next(0, 10); // creates a number between 1 and 9
//rndmoney8 = rnd.Next(0, 10); // creates a number between 1 and 9
//rndmoney9 = rnd.Next(0, 10); // creates a number between 1 and 9
button1.Text = rndmoney1.ToString();
button2.Text = rndmoney2.ToString();
if (rndmoney1 == rndmoney2)
{
MessageBox.Show("Dot Net Perls is awesome.");
rndmoney2 = rnd.Next(0, 9); // creates a number between 1 and 9
button2.Text = rndmoney2.ToString();
}
//button3.Text = rndmoney3.ToString();
//button4.Text = rndmoney4.ToString();
//button5.Text = rndmoney5.ToString();
//button6.Text = rndmoney6.ToString();
//button7.Text = rndmoney7.ToString();
//button8.Text = rndmoney8.ToString();
//button9.Text = rndmoney9.ToString();
//button10.Enabled = false;
}
}
}
2015年10月16日 星期五
拉霸
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
int c1 = 0, b1 = 0;
int c2 = 0, b2 = 0;
int c3 = 0, b3 = 0;
int rndmoney1 = 100;
int rndmoney2 = 100;
int rndmoney3 = 100;
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
}
private void timer1_Tick(object sender, EventArgs e)
{
if (c1 >= rndmoney1) timer1.Enabled = false;
{
}
if (b1 == 0)
{
//button1.BackColor = Color.Green;
//button2.BackColor = Color.Black;
//button3.BackColor = Color.Black;
}
else if (b1 == 1)
{
//button1.BackColor = Color.Black;
//button2.BackColor = Color.Yellow;
// button3.BackColor = Color.Black;
}
else if (b1 == 2)
{
//button1.BackColor = Color.Black;
// button2.BackColor = Color.Black;
// button3.BackColor = Color.Red;
}
c1 = c1 + 1;
b1 = c1 % 3;
button1.Text = c1.ToString();
}
private void button4_Click(object sender, EventArgs e)
{
c1 = 0;
c2 = 0;
c3 = 0;
timer1.Enabled = true;
timer2.Enabled = true;
timer3.Enabled = true;
Random rnd = new Random();
rndmoney1 = rnd.Next(1, 10);
rndmoney2 = rnd.Next(1, 10);
rndmoney3 = rnd.Next(1, 10);
button4.Text = rndmoney1.ToString() + rndmoney2.ToString() + rndmoney3.ToString();
}
private void button2_Click(object sender, EventArgs e)
{
}
private void timer2_Tick_1(object sender, EventArgs e)
{
if (c2 >= rndmoney2) timer2.Enabled = false;
{
}
if (b1 == 0)
{
//button1.BackColor = Color.Green;
//button2.BackColor = Color.Black;
//button3.BackColor = Color.Black;
}
else if (b1 == 1)
{
//button1.BackColor = Color.Black;
//button2.BackColor = Color.Yellow;
// button3.BackColor = Color.Black;
}
else if (b1 == 2)
{
//button1.BackColor = Color.Black;
// button2.BackColor = Color.Black;
// button3.BackColor = Color.Red;
}
c2 = c2 + 1;
b2 = c2 % 3;
button2.Text = c2.ToString();
}
private void timer3_Tick_1(object sender, EventArgs e)
{
if (c3 >= rndmoney3) timer3.Enabled = false;
{
}
if (b1 == 0)
{
//button1.BackColor = Color.Green;
//button2.BackColor = Color.Black;
//button3.BackColor = Color.Black;
}
else if (b1 == 1)
{
//button1.BackColor = Color.Black;
//button2.BackColor = Color.Yellow;
// button3.BackColor = Color.Black;
}
else if (b1 == 2)
{
//button1.BackColor = Color.Black;
// button2.BackColor = Color.Black;
// button3.BackColor = Color.Red;
}
c3 = c3 + 1;
b3 = c3 % 3;
button3.Text = c3.ToString();
}
}
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
int c1 = 0, b1 = 0;
int c2 = 0, b2 = 0;
int c3 = 0, b3 = 0;
int rndmoney1 = 100;
int rndmoney2 = 100;
int rndmoney3 = 100;
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
}
private void timer1_Tick(object sender, EventArgs e)
{
if (c1 >= rndmoney1) timer1.Enabled = false;
{
}
if (b1 == 0)
{
//button1.BackColor = Color.Green;
//button2.BackColor = Color.Black;
//button3.BackColor = Color.Black;
}
else if (b1 == 1)
{
//button1.BackColor = Color.Black;
//button2.BackColor = Color.Yellow;
// button3.BackColor = Color.Black;
}
else if (b1 == 2)
{
//button1.BackColor = Color.Black;
// button2.BackColor = Color.Black;
// button3.BackColor = Color.Red;
}
c1 = c1 + 1;
b1 = c1 % 3;
button1.Text = c1.ToString();
}
private void button4_Click(object sender, EventArgs e)
{
c1 = 0;
c2 = 0;
c3 = 0;
timer1.Enabled = true;
timer2.Enabled = true;
timer3.Enabled = true;
Random rnd = new Random();
rndmoney1 = rnd.Next(1, 10);
rndmoney2 = rnd.Next(1, 10);
rndmoney3 = rnd.Next(1, 10);
button4.Text = rndmoney1.ToString() + rndmoney2.ToString() + rndmoney3.ToString();
}
private void button2_Click(object sender, EventArgs e)
{
}
private void timer2_Tick_1(object sender, EventArgs e)
{
if (c2 >= rndmoney2) timer2.Enabled = false;
{
}
if (b1 == 0)
{
//button1.BackColor = Color.Green;
//button2.BackColor = Color.Black;
//button3.BackColor = Color.Black;
}
else if (b1 == 1)
{
//button1.BackColor = Color.Black;
//button2.BackColor = Color.Yellow;
// button3.BackColor = Color.Black;
}
else if (b1 == 2)
{
//button1.BackColor = Color.Black;
// button2.BackColor = Color.Black;
// button3.BackColor = Color.Red;
}
c2 = c2 + 1;
b2 = c2 % 3;
button2.Text = c2.ToString();
}
private void timer3_Tick_1(object sender, EventArgs e)
{
if (c3 >= rndmoney3) timer3.Enabled = false;
{
}
if (b1 == 0)
{
//button1.BackColor = Color.Green;
//button2.BackColor = Color.Black;
//button3.BackColor = Color.Black;
}
else if (b1 == 1)
{
//button1.BackColor = Color.Black;
//button2.BackColor = Color.Yellow;
// button3.BackColor = Color.Black;
}
else if (b1 == 2)
{
//button1.BackColor = Color.Black;
// button2.BackColor = Color.Black;
// button3.BackColor = Color.Red;
}
c3 = c3 + 1;
b3 = c3 % 3;
button3.Text = c3.ToString();
}
}
}
2015年10月2日 星期五
程式設計工藝大師
紅綠燈using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApplication2
{
public partial class Form1 : Form
{
int c = 0, d = 0;
public Form1()
{
InitializeComponent();
}
private void timer1_Tick(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
button1.BackColor = Color.WhiteSmoke;
button2.BackColor = Color.WhiteSmoke;
button3.BackColor = Color.WhiteSmoke;
c++;
d = c % 3;
if (d == 1)
{
button1.BackColor = Color.Red;
button2.BackColor = Color.White;
button3.BackColor = Color.White;
}
else if (d == 2)
{
button1.BackColor = Color.White;
button2.BackColor = Color.Yellow;
button3.BackColor = Color.White;
}
else if (d == 0)
{
button1.BackColor = Color.White;
button2.BackColor = Color.White;
button3.BackColor = Color.Green;
}
//button1.Text = c.ToString() ;
}
private void pictureBox1_Click(object sender, EventArgs e)
{
}
}
}
2015年6月4日 星期四
利用app模擬器製作app
先到http://appinventor.mit.edu/explore/content/windows.html 點選dowmload下載模擬器
然後選擇 3. Start App Inventor 進入畫面
登入google帳號 & 進入此連結 http://beta.appinventor.mit.edu/.
打開模擬器並照以上網址的步驟設計
若要測試模擬器結果 可點選New emulator 再點選 Connect to Device連線5554
若要存成apk檔,回到網頁 點選Package for Phone,再選擇Download to this Computer
可將檔案傳到facebook 再利用手機連線FB 下載,即可使用app
註:限android手機
先到http://appinventor.mit.edu/explore/content/windows.html 點選dowmload下載模擬器
然後選擇 3. Start App Inventor 進入畫面
登入google帳號 & 進入此連結 http://beta.appinventor.mit.edu/.
打開模擬器並照以上網址的步驟設計
若要測試模擬器結果 可點選New emulator 再點選 Connect to Device連線5554
若要存成apk檔,回到網頁 點選Package for Phone,再選擇Download to this Computer
可將檔案傳到facebook 再利用手機連線FB 下載,即可使用app
註:限android手機
2015年5月22日 星期五
推盤製作
交換
import java.awt.*;
import java.awt.event.*;
import java.util.Random;
import javax.swing.*;
public class Calculator extends JFrame implements
ActionListener{
int space;
JButton button[]=new JButton[10];
public static void main(String[]args){
new Calculator();
}
public Calculator()
{
String s;
int myrand;
int[] a = { 0,1, 2, 3, 4, 5, 6, 7, 8 };
int[] aresult;
int temp;
Random ran = new Random();
/*
for (int i = 0; i < 9; i++)
{
System.out.println(a[i]);
}
*/
for (int i = 0; i < 9; i++)
{
myrand=ran.nextInt(9-i);
temp=a[8-i];
a[8-i]=a[myrand];
a[myrand]=temp;
}
for (int i = 0; i < 9; i++)
{
System.out.println(a[i]);
}
JFrame window=new JFrame("Calculator");
window.setDefaultLookAndFeelDecorated(true);
window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
window.setLayout(new GridLayout(3,3));
JPanel jplPanel = new JPanel();
jplPanel.setLayout(new GridLayout(3,3));
//s=Integer.toString(1);
s=String.valueOf(1);
//System.out.println(s);
//s="1";
for (int i = 0; i < 9; i++)
{
button[i] = new JButton();
button[i].setActionCommand(s);
button[i].addActionListener(this);
button[i].setSize(50,50);
button[i].setText(Integer.toString(a[i]));
jplPanel.add(button[i]);
if(Integer.valueOf(button[i].getText())==0)
{
space=i;
System.out.println(i);
}
}
window.getContentPane().add(jplPanel, BorderLayout.CENTER);
window.setSize(500,500);
window.setVisible(true);
}
public void actionPerformed(ActionEvent e) {
for(int i=0; i <= 9; i++)
{
if(e.getSource() == button[i]){
String tempsting;
if(i==space-1)
{
tempsting=button[i].getText();
button[i].setText(button[i+1].getText());
button[i+1].setText(tempsting);
System.out.println(i+button[i].getText());
}
}
}
}
}
交換
import java.awt.*;
import java.awt.event.*;
import java.util.Random;
import javax.swing.*;
public class Calculator extends JFrame implements
ActionListener{
int space;
JButton button[]=new JButton[10];
public static void main(String[]args){
new Calculator();
}
public Calculator()
{
String s;
int myrand;
int[] a = { 0,1, 2, 3, 4, 5, 6, 7, 8 };
int[] aresult;
int temp;
Random ran = new Random();
/*
for (int i = 0; i < 9; i++)
{
System.out.println(a[i]);
}
*/
for (int i = 0; i < 9; i++)
{
myrand=ran.nextInt(9-i);
temp=a[8-i];
a[8-i]=a[myrand];
a[myrand]=temp;
}
for (int i = 0; i < 9; i++)
{
System.out.println(a[i]);
}
JFrame window=new JFrame("Calculator");
window.setDefaultLookAndFeelDecorated(true);
window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
window.setLayout(new GridLayout(3,3));
JPanel jplPanel = new JPanel();
jplPanel.setLayout(new GridLayout(3,3));
//s=Integer.toString(1);
s=String.valueOf(1);
//System.out.println(s);
//s="1";
for (int i = 0; i < 9; i++)
{
button[i] = new JButton();
button[i].setActionCommand(s);
button[i].addActionListener(this);
button[i].setSize(50,50);
button[i].setText(Integer.toString(a[i]));
jplPanel.add(button[i]);
if(Integer.valueOf(button[i].getText())==0)
{
space=i;
System.out.println(i);
}
}
window.getContentPane().add(jplPanel, BorderLayout.CENTER);
window.setSize(500,500);
window.setVisible(true);
}
public void actionPerformed(ActionEvent e) {
for(int i=0; i <= 9; i++)
{
if(e.getSource() == button[i]){
String tempsting;
if(i==space-1)
{
tempsting=button[i].getText();
button[i].setText(button[i+1].getText());
button[i+1].setText(tempsting);
System.out.println(i+button[i].getText());
}
}
}
}
}
推盤遊戲
JFrame window=new JFrame("myButton");
window.setSize(450, 150);
JButton button[]=new JButton[16];
JPanel jplPanel = new JPanel();
jplPanel.setLayout(new GridLayout(4,4,8,8));
}
}
}
}
);
jplPanel.add(button[i]);
}
/*public void win()
{
for(int i=0;i<16;i++)
{
if(array[i]=i)
{
System.out.println("WIN!!!");
}
}
}*/
window.getContentPane().add(jplPanel, BorderLayout.CENTER);
window.setSize(400,400);
window.setVisible(true);
}
import java.util.Random;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class test extends JFrame{
public static void main(String[]args){
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class test extends JFrame{
public static void main(String[]args){
Random random = new Random();
JPanel jjj = new JPanel();
int number = 0;;
int array[] = new int[16];
boolean b;
JPanel jjj = new JPanel();
int number = 0;;
int array[] = new int[16];
boolean b;
for(int i=0;i<16;i++)
{
b = true;
while(b) {
b = false;
number = random.nextInt(16)+1;
for(int j=0;j<array.length;j++) {
if(array[j]==number) {
b = true;
}
}
}
array[i] = number;
System.out.printf("array[%d]=%d\n",i,number);
}
{
b = true;
while(b) {
b = false;
number = random.nextInt(16)+1;
for(int j=0;j<array.length;j++) {
if(array[j]==number) {
b = true;
}
}
}
array[i] = number;
System.out.printf("array[%d]=%d\n",i,number);
}
JFrame window=new JFrame("myButton");
window.setSize(450, 150);
JButton button[]=new JButton[16];
JPanel jplPanel = new JPanel();
jplPanel.setLayout(new GridLayout(4,4,8,8));
for (int i = 0; i < 16; i++){
//button[i]=new JButton(array[16]);
button[i] = new JButton();
button[i].setSize(40,40);
button[i].setText(Integer.toString(array[i]));
if(array[i]==16)
{
button[i].setText("");
System.out.println(i);
}
button[i].addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e)
{
if(array[0]==1&&array[3]==4&&array[4]==5&&array[7]==8&&array[12]==13&&array[6]==7&&array[15]==16&&array[13]==14&&array[14]==15&&array[9]==10){JOptionPane.showMessageDialog(null,"dddddddddd");
}
//JOptionPane.showMessageDialog(null,"ddasdasdasdsads");
//button[i]=new JButton(array[16]);
button[i] = new JButton();
button[i].setSize(40,40);
button[i].setText(Integer.toString(array[i]));
if(array[i]==16)
{
button[i].setText("");
System.out.println(i);
}
button[i].addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e)
{
if(array[0]==1&&array[3]==4&&array[4]==5&&array[7]==8&&array[12]==13&&array[6]==7&&array[15]==16&&array[13]==14&&array[14]==15&&array[9]==10){JOptionPane.showMessageDialog(null,"dddddddddd");
}
//JOptionPane.showMessageDialog(null,"ddasdasdasdsads");
int a=0,c=0;
for (int i = 0; i < 16; i++)
{
if(array[i]==16)
{
a=i;
}
}
for (int i = 0; i < 16; i++)
{
if(array[i]==16)
{
a=i;
}
}
if(a>3&&a<16)
{
if(e.getSource() == button[a-4])
{
{
if(e.getSource() == button[a-4])
{
//按下按鈕後事件
button[a-4].setText("");
button[a].setText(Integer.toString(array[a-4]));
c=array[a];
array[a]=array[a-4];
array[a-4]=c;
}
}
button[a-4].setText("");
button[a].setText(Integer.toString(array[a-4]));
c=array[a];
array[a]=array[a-4];
array[a-4]=c;
}
}
if(a<12&&a>-4)
{
if(e.getSource() == button[a+4])
{ //按下按鈕後事件
button[a+4].setText("");
button[a].setText(Integer.toString(array[a+4]));
c=array[a];
array[a]=array[a+4];
array[a+4]=c;
}
}
if(a>-1&&a<15)
{
if(e.getSource() == button[a+1])
{
//按下按鈕後事件
button[a+1].setText("");
button[a].setText(Integer.toString(array[a+1]));
c=array[a];
array[a]=array[a+1];
array[a+1]=c;
}
}
if(a<16&&a>0)
{
if(e.getSource() == button[a-1])
{
//按下按鈕後事件
button[a-1].setText("");
button[a].setText(Integer.toString(array[a-1]));
c=array[a];
array[a]=array[a-1];
array[a-1]=c;
{
if(e.getSource() == button[a+4])
{ //按下按鈕後事件
button[a+4].setText("");
button[a].setText(Integer.toString(array[a+4]));
c=array[a];
array[a]=array[a+4];
array[a+4]=c;
}
}
if(a>-1&&a<15)
{
if(e.getSource() == button[a+1])
{
//按下按鈕後事件
button[a+1].setText("");
button[a].setText(Integer.toString(array[a+1]));
c=array[a];
array[a]=array[a+1];
array[a+1]=c;
}
}
if(a<16&&a>0)
{
if(e.getSource() == button[a-1])
{
//按下按鈕後事件
button[a-1].setText("");
button[a].setText(Integer.toString(array[a-1]));
c=array[a];
array[a]=array[a-1];
array[a-1]=c;
}
}
}
}
);
jplPanel.add(button[i]);
}
/*public void win()
{
for(int i=0;i<16;i++)
{
if(array[i]=i)
{
System.out.println("WIN!!!");
}
}
}*/
window.getContentPane().add(jplPanel, BorderLayout.CENTER);
window.setSize(400,400);
window.setVisible(true);
}
}
mport java.awt.*;
import java.awt.event.*;
import java.util.Random;
import javax.swing.*;
public class Calculator extends JFrame implements
ActionListener{
JButton button[]=new JButton[10];
public static void main(String[]args){
new Calculator();
}
public Calculator()
{
String s;
int myrand;
int[] a = { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
int[] aresult;
int temp;
Random ran = new Random();
for (int i = 0; i < 9; i++)
{
System.out.println(a[i]);
}
for (int i = 0; i < 9; i++)
{
myrand=ran.nextInt(9-i);
temp=a[8-i];
a[8-i]=a[myrand];
a[myrand]=temp;
}
for (int i = 0; i < 9; i++)
{
System.out.println(a[i]);
}
JFrame window=new JFrame("Calculator");
window.setDefaultLookAndFeelDecorated(true);
window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
window.setLayout(new GridLayout(3,3));
JPanel jplPanel = new JPanel();
jplPanel.setLayout(new GridLayout(3,3));
//s=Integer.toString(1);
s=String.valueOf(1);
//System.out.println(s);
//s="1";
for (int i = 0; i < 9; i++)
{
button[i] = new JButton();
button[i].setActionCommand(s);
button[i].addActionListener(this);
button[i].setSize(50,50);
button[i].setText(Integer.toString(a[i]));
jplPanel.add(button[i]);
}
window.getContentPane().add(jplPanel, BorderLayout.CENTER);
window.setSize(500,500);
window.setVisible(true);
}
public void actionPerformed(ActionEvent e) {
for(int i=1; i <= 9; i++)
{
if(e.getSource() == button[i]){
System.out.println(i);
}
}
}
}
import java.awt.event.*;
import java.util.Random;
import javax.swing.*;
public class Calculator extends JFrame implements
ActionListener{
JButton button[]=new JButton[10];
public static void main(String[]args){
new Calculator();
}
public Calculator()
{
String s;
int myrand;
int[] a = { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
int[] aresult;
int temp;
Random ran = new Random();
for (int i = 0; i < 9; i++)
{
System.out.println(a[i]);
}
for (int i = 0; i < 9; i++)
{
myrand=ran.nextInt(9-i);
temp=a[8-i];
a[8-i]=a[myrand];
a[myrand]=temp;
}
for (int i = 0; i < 9; i++)
{
System.out.println(a[i]);
}
JFrame window=new JFrame("Calculator");
window.setDefaultLookAndFeelDecorated(true);
window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
window.setLayout(new GridLayout(3,3));
JPanel jplPanel = new JPanel();
jplPanel.setLayout(new GridLayout(3,3));
//s=Integer.toString(1);
s=String.valueOf(1);
//System.out.println(s);
//s="1";
for (int i = 0; i < 9; i++)
{
button[i] = new JButton();
button[i].setActionCommand(s);
button[i].addActionListener(this);
button[i].setSize(50,50);
button[i].setText(Integer.toString(a[i]));
jplPanel.add(button[i]);
}
window.getContentPane().add(jplPanel, BorderLayout.CENTER);
window.setSize(500,500);
window.setVisible(true);
}
public void actionPerformed(ActionEvent e) {
for(int i=1; i <= 9; i++)
{
if(e.getSource() == button[i]){
System.out.println(i);
}
}
}
}
2015年5月8日 星期五
3*3 9宮格顯示對的數字
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Calculator extends JFrame implements ActionListener{
JButton button[]=new JButton[10];
public static void main(String[]args){
new Calculator();
}
public Calculator()
{
String s;
JFrame window=new JFrame("Calculator");
window.setDefaultLookAndFeelDecorated(true);
window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
window.setLayout(new GridLayout(3,3));
JPanel jplPanel = new JPanel();
jplPanel.setLayout(new GridLayout(3,3));
//s=Integer.toString(1);
s=String.valueOf(1);
//System.out.println(s);
//s="1";
for (int i = 1; i <= 9; i++)
{
button[i] = new JButton();
button[i].setActionCommand(s);
button[i].addActionListener(this);
button[i].setSize(50,50);
button[i].setText(Integer.toString(i));
jplPanel.add(button[i]);
}
window.getContentPane().add(jplPanel, BorderLayout.CENTER);
window.setSize(500,500);
window.setVisible(true);
}
public void actionPerformed(ActionEvent e) {
for(int i=1; i<button.length; i++){
if(e.getSource() == button[i]){
System.out.println(i);
}
}
}
}
=======================================================================
亂數 4*4 不重複
import java.util.Random;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class test extends JFrame{
public static void main(String[]args){
Random random = new Random();
int number = 0;;
int array[] = new int[16];
boolean b;
for(int i=0;i<16;i++)
{
b = true;
while(b) {
b = false;
number = random.nextInt(16)+1;
for(int j=0;j<array.length;j++) {
if(array[j]==number) {
b = true;
}
}
}
array[i] = number;
System.out.printf("array[%d]=%d\n",i,number);
}
JFrame window=new JFrame("myButton");
window.setSize(450, 150);
JButton button[]=new JButton[16];
JPanel jplPanel = new JPanel();
jplPanel.setLayout(new GridLayout(4,4,8,8));
for (int i = 0; i < 16; i++){
//button[i]=new JButton(""+array[16]);
button[i] = new JButton();
button[i].setSize(40,40);
button[i].setText(Integer.toString(array[i]));
button[i].addActionListener(
new ActionListener() {
public void actionPerformed(ActionEvent e) {
for (int j = 0; j < 16; j++) {
if (e.getSource() == button[j]) {
System.out.println(j+1);
}
}
}
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Calculator extends JFrame implements ActionListener{
JButton button[]=new JButton[10];
public static void main(String[]args){
new Calculator();
}
public Calculator()
{
String s;
JFrame window=new JFrame("Calculator");
window.setDefaultLookAndFeelDecorated(true);
window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
window.setLayout(new GridLayout(3,3));
JPanel jplPanel = new JPanel();
jplPanel.setLayout(new GridLayout(3,3));
//s=Integer.toString(1);
s=String.valueOf(1);
//System.out.println(s);
//s="1";
for (int i = 1; i <= 9; i++)
{
button[i] = new JButton();
button[i].setActionCommand(s);
button[i].addActionListener(this);
button[i].setSize(50,50);
button[i].setText(Integer.toString(i));
jplPanel.add(button[i]);
}
window.getContentPane().add(jplPanel, BorderLayout.CENTER);
window.setSize(500,500);
window.setVisible(true);
}
public void actionPerformed(ActionEvent e) {
for(int i=1; i<button.length; i++){
if(e.getSource() == button[i]){
System.out.println(i);
}
}
}
}
=======================================================================
亂數 4*4 不重複
import java.util.Random;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class test extends JFrame{
public static void main(String[]args){
Random random = new Random();
int number = 0;;
int array[] = new int[16];
boolean b;
for(int i=0;i<16;i++)
{
b = true;
while(b) {
b = false;
number = random.nextInt(16)+1;
for(int j=0;j<array.length;j++) {
if(array[j]==number) {
b = true;
}
}
}
array[i] = number;
System.out.printf("array[%d]=%d\n",i,number);
}
JFrame window=new JFrame("myButton");
window.setSize(450, 150);
JButton button[]=new JButton[16];
JPanel jplPanel = new JPanel();
jplPanel.setLayout(new GridLayout(4,4,8,8));
for (int i = 0; i < 16; i++){
//button[i]=new JButton(""+array[16]);
button[i] = new JButton();
button[i].setSize(40,40);
button[i].setText(Integer.toString(array[i]));
button[i].addActionListener(
new ActionListener() {
public void actionPerformed(ActionEvent e) {
for (int j = 0; j < 16; j++) {
if (e.getSource() == button[j]) {
System.out.println(j+1);
}
}
}
2015年4月23日 星期四
16個按鈕程式碼
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(600, 200);
JPanel jplPanel = new JPanel();
int i;
int j=1;
int num1 , num2;
JButton jbnButton[] = new JButton[16];
JButton changeButton[] = new JButton[3];
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) {
/*if(j<3){
changeButton[j] = jbnButton[i];
num1 = i;
j++;
}
else if(j==3){
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);
}
}
import java.awt.event.*;
import javax.swing.*;
class Test
{
public static void main(String[] args)
{
JFrame jtfMainFrame = new JFrame("Which Button Demo");
jtfMainFrame.setSize(600, 200);
JPanel jplPanel = new JPanel();
int i;
int j=1;
int num1 , num2;
JButton jbnButton[] = new JButton[16];
JButton changeButton[] = new JButton[3];
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) {
/*if(j<3){
changeButton[j] = jbnButton[i];
num1 = i;
j++;
}
else if(j==3){
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);
}
}
=============================================================================================
亂數不重複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;
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
{
Random rand = new Random();
Button[,] buttons = new Button[4, 4];
public Form1()
{
InitializeComponent();
}
{
public partial class Form1 : Form
{
Random rand = new Random();
Button[,] buttons = new Button[4, 4];
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
for (int i = 0; i < 4; i++)
{
for (int j = 0; j < 4; j++)
{
{
for (int j = 0; j < 4; j++)
{
buttons[i, j] = new Button();
buttons[i, j].Size = new Size(80, 80);
buttons[i, j].Location = new Point(i * 85, j * 85);
buttons[i, j].Size = new Size(80, 80);
buttons[i, j].Location = new Point(i * 85, j * 85);
this.Controls.Add(buttons[i, j]);
}
}
}
}
private void button1_Click_1(object sender, EventArgs e)
{
int a, b, x;
int[] array = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 };
for (int i = 15; i > 1; i--)
{
{
a = rand.Next(0, i);
b = array[a];
array[a] = array[i];
array[i] = b;
}
b = array[a];
array[a] = array[i];
array[i] = b;
}
for (int i = 0; i < 4; i++)
{
for (int j = 0; j < 4; j++)
{
x = array[j * 4 + i];
buttons[i, j].Text = Convert.ToString(x);
this.Controls.Add(buttons[i, j]);
}
}
}
}
}
}
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Calculator extends JFrame implements ActionListener{
public static void main(String[]args){
new Calculator();
}
public Calculator()
{
String s;
JFrame window=new JFrame("Calculator");
window.setDefaultLookAndFeelDecorated(true);
window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
window.setLayout(new GridLayout(3,3));
JPanel jplPanel = new JPanel();
jplPanel.setLayout(new GridLayout(3,3));
JButton button[]=new JButton[10];
//s=Integer.toString(1);
s=String.valueOf(1);
//System.out.println(s);
//s="1";
for (int i = 1; i <= 9; i++)
{
button[i] = new JButton();
button[i].setActionCommand(s);
button[i].addActionListener(this);
button[i].setSize(50,50);
button[i].setText(Integer.toString(i));
jplPanel.add(button[i]);
}
window.getContentPane().add(jplPanel, BorderLayout.CENTER);
window.setSize(500,500);
window.setVisible(true);
}
public void actionPerformed(ActionEvent e) {
String cmd = e.getActionCommand();
System.out.println(cmd);
if (cmd == "1") {
System.out.println("Yes....");
}
}
}
訂閱:
文章 (Atom)