java網誌設計
2015年12月25日 星期五
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 WindowsFormsApplication2
{
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)
{
}
}
}
2015年6月11日 星期四
作業8
- JUN 05FRI 2015
作業8
程式碼
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();
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);
}
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");
int a=0,c=0;
for (int i = 0; i < 16; i++)
{
if(array[i]==16)
{
a=i;
}
}
if(a>3&&a<16)
{
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<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;
}
}
}
}
);
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.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;
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]));
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;
}
}
if(a>3&&a<16)
{
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<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;
}
}
}
}
);
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.awt.*;
import java.awt.event.*;
import javax.swing.*;
class Button
{
public static void main(String[] args)
{
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");
JPanel jplPanel = new JPanel();
JFrame jtfMainFrame = new JFrame("Which Button Demo");
jtfMainFrame.setSize(600, 600);
jbnButton1.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
System.out.println("1");
}});
import java.awt.event.*;
import javax.swing.*;
class Button
{
public static void main(String[] args)
{
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");
JPanel jplPanel = new JPanel();
JFrame jtfMainFrame = new JFrame("Which Button Demo");
jtfMainFrame.setSize(600, 600);
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");
}});
jplPanel.setLayout(new FlowLayout());
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.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
jtfMainFrame.pack();
jtfMainFrame.setVisible(true);
System.out.print("chih-yu hsu");
}
}
{
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");
}});
jplPanel.setLayout(new FlowLayout());
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.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
jtfMainFrame.pack();
jtfMainFrame.setVisible(true);
System.out.print("chih-yu hsu");
}
}
作業4
實作
程式碼:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
class button
{
import java.awt.event.*;
import javax.swing.*;
class button
{
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");
JTextField jtfInput = new JTextField(20);
JPanel jplPanel = new JPanel();
jbnButton1.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
jtfInput.setText("Button 1!");
}});
jbnButton2.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
jtfInput.setText("Button 2!");
}});
{
public void actionPerformed(ActionEvent e)
{
jtfInput.setText("Button 2!");
}});
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);
System.out.print("chih-yu hsu");
}
}
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);
System.out.print("chih-yu hsu");
}
}
2015年3月12日 星期四
訂閱:
文章 (Atom)