電腦端主控頁面

import lejos.pc.comm.*;
import java.io.*;
import java.awt.Button;
import java.awt.Choice;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.*;
import java.awt.event.*;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.AbstractButton;

class test3 extends JFrame implements ItemListener,ActionListener {
    static Choice redball,blueball,choi,cho,cho1,cho2,cho3,cho4,cho5,cho6,cho7;
     static Button btn,btn1,btn2,ball;
     static JLabel btForward,abc,btBackward,btLeft,btRight,btopen,btclose,btslowf,btslowl,btslowb,btslowr;
     static int red,blue,a,b,c,d,x;
     static int afactories1,afactories2,afactories3;
     static int bfactories1,bfactories2,bfactories3;
    static int cfactories1,cfactories2,cfactories3;
    static NXTCommOutputStream dataOut;
     static NXTConnector conn;
     static NXTCommOutputStream dataOut2;
     static NXTConnector conn2;
     static NXTCommOutputStream dataOut3;
     static NXTConnector conn3;
     static NXTCommOutputStream dataOut4;
     static NXTConnector conn4;
    public void itemStateChanged(ItemEvent e) {
    }
   public void actionPerformed(ActionEvent e) {



        try{
           if (e.getSource() == ball)
            {
                a=1;
                red=redball.getSelectedIndex()-1;
                blue=blueball.getSelectedIndex()-1;

                 if(red<0||blue<0)
                {
                JOptionPane.showMessageDialog(null, "請選擇籃球,紅球數量", "取料區", JOptionPane.ERROR_MESSAGE);
                }
                else
                {
                dataOut.write(a);
                dataOut.write(red);
                dataOut.write(blue); //送出命令
                }
            }
                dataOut.flush();
            if (e.getSource()==btn)
            {
                b=1;
                afactories1=choi.getSelectedIndex()-1;
                afactories2=cho.getSelectedIndex()-1;
                afactories3=cho1.getSelectedIndex()-1;
                if(afactories1<0||afactories2<0||afactories3<0)
                {
                JOptionPane.showMessageDialog(null, "請選擇籃球,紅球數量", "Error", JOptionPane.ERROR_MESSAGE);
                }
                else
                {
                dataOut2.write(b);
                dataOut2.write(afactories1);
                dataOut2.write(afactories2);
                dataOut2.write(afactories3);
                }
            }
            dataOut2.flush();
        if (e.getSource()==btn1)
            {
                c=1;
                bfactories1=cho2.getSelectedIndex()-1;
                bfactories2=cho3.getSelectedIndex()-1;
                bfactories3=cho4.getSelectedIndex()-1;
                if(bfactories1<0||bfactories2<0||bfactories3<0)
                {
                JOptionPane.showMessageDialog(null, "請選擇籃球,紅球數量", "Error", JOptionPane.ERROR_MESSAGE);
                }
                else
                {
                dataOut3.write(c);
                dataOut3.write(bfactories1);
                dataOut3.write(bfactories2);
                dataOut3.write(bfactories3);
                }
            }
            dataOut3.flush();
        } catch(IOException i) {
            JOptionPane.showMessageDialog(null, "Communication disconnected",
                  "Error", JOptionPane.ERROR_MESSAGE); //斷線錯誤
            System.exit(1);
        }
      }
    public test3() {

       conn = new NXTConnector();
if(!conn.connectTo("BMW", "", NXTCommFactory.BLUETOOTH))
{
        JOptionPane.showMessageDialog(null, "尚未連接曲料區", "曲料區", JOptionPane.ERROR_MESSAGE);
        System.exit(1);
}
        dataOut = new NXTCommOutputStream(conn.getNXTComm()); //取得輸出串流

       conn2 = new NXTConnector();
if(!conn2.connectTo("NXT", "", NXTCommFactory.BLUETOOTH))
{
        JOptionPane.showMessageDialog(null, "尚未連接A車", "A車", JOptionPane.ERROR_MESSAGE);
        System.exit(1);
}
        dataOut2 = new NXTCommOutputStream(conn2.getNXTComm()); //取得輸出串流

       conn3 = new NXTConnector();
if(!conn3.connectTo("NXT2", "", NXTCommFactory.BLUETOOTH))
{
        JOptionPane.showMessageDialog(null, "尚未連接B車", "B車", JOptionPane.ERROR_MESSAGE);
        System.exit(1);
}
        dataOut3 = new NXTCommOutputStream(conn3.getNXTComm()); //取得輸出串流

        this.getContentPane().setLayout( new FlowLayout());
        setTitle("RBM物流中心");
        choi  = new Choice();
        choi.addItemListener(this);
        choi.addItem("請選擇");
        choi.addItem("零顆球");
        choi.addItem("一顆球");
        choi.addItem("兩顆球");
        choi.addItem("三顆球");
        choi.addItem("四顆球");
        choi.addItem("五顆球");
        choi.addItem("六顆球");
        choi.addItem("七顆球");

        cho =new Choice();
        cho.addItemListener(this);
        cho.addItem("請選擇");
        cho.addItem("零顆球");
        cho.addItem("一顆球");
        cho.addItem("兩顆球");
        cho.addItem("三顆球");
        cho.addItem("四顆球");
        cho.addItem("五顆球");
        cho.addItem("六顆球");
        cho.addItem("七顆球");

        cho1 =new Choice();
        cho1.addItemListener(this);
        cho1.addItem("請選擇");
        cho1.addItem("零顆球");
        cho1.addItem("一顆球");
        cho1.addItem("兩顆球");
        cho1.addItem("三顆球");
        cho1.addItem("四顆球");
        cho1.addItem("五顆球");
        cho1.addItem("六顆球");
        cho1.addItem("七顆球");

        cho2 =new Choice();
        cho2.addItemListener(this);
        cho2.addItem("請選擇");
        cho2.addItem("零顆球");
        cho2.addItem("一顆球");
        cho2.addItem("兩顆球");
        cho2.addItem("三顆球");
        cho2.addItem("四顆球");
        cho2.addItem("五顆球");
        cho2.addItem("六顆球");
        cho2.addItem("七顆球");

        cho3 =new Choice();
        cho3.addItemListener(this);
        cho3.addItem("請選擇");
        cho3.addItem("零顆球");
        cho3.addItem("一顆球");
        cho3.addItem("兩顆球");
        cho3.addItem("三顆球");
        cho3.addItem("四顆球");
        cho3.addItem("五顆球");
        cho3.addItem("六顆球");
        cho3.addItem("七顆球");

        cho4 =new Choice();
        cho4.addItemListener(this);
        cho4.addItem("請選擇");
        cho4.addItem("零顆球");
        cho4.addItem("一顆球");
        cho4.addItem("兩顆球");
        cho4.addItem("三顆球");
        cho4.addItem("四顆球");
        cho4.addItem("五顆球");
        cho4.addItem("六顆球");
        cho4.addItem("七顆球");

        cho5 =new Choice();
        cho5.addItemListener(this);
        cho5.addItem("請選擇");
        cho5.addItem("零顆球");
        cho5.addItem("一顆球");
        cho5.addItem("兩顆球");
        cho5.addItem("三顆球");
        cho5.addItem("四顆球");
        cho5.addItem("五顆球");
        cho5.addItem("六顆球");
        cho5.addItem("七顆球");

        cho6 =new Choice();
        cho6.addItemListener(this);
        cho6.addItem("請選擇");
        cho6.addItem("零顆球");
        cho6.addItem("一顆球");
        cho6.addItem("兩顆球");
        cho6.addItem("三顆球");
        cho6.addItem("四顆球");
        cho6.addItem("五顆球");
        cho6.addItem("六顆球");
        cho6.addItem("七顆球");

        cho7 =new Choice();
        cho7.addItemListener(this);
        cho7.addItem("請選擇");
        cho7.addItem("零顆球");
        cho7.addItem("一顆球");
        cho7.addItem("兩顆球");
        cho7.addItem("三顆球");
        cho7.addItem("四顆球");
        cho7.addItem("五顆球");
        cho7.addItem("六顆球");
        cho7.addItem("七顆球");

        redball =new Choice();
        redball.addItemListener(this);
        redball.addItem("請選擇");
        redball.addItem("零顆球");
        redball.addItem("一顆球");
        redball.addItem("兩顆球");
        redball.addItem("三顆球");
        redball.addItem("四顆球");
        redball.addItem("五顆球");
        redball.addItem("六顆球");
        redball.addItem("七顆球");

        blueball =new Choice();
        blueball.addItemListener(this);
        blueball.addItem("請選擇");
        blueball.addItem("零顆球");
        blueball.addItem("一顆球");
        blueball.addItem("兩顆球");
        blueball.addItem("三顆球");
        blueball.addItem("四顆球");
        blueball.addItem("五顆球");
        blueball.addItem("六顆球");
        blueball.addItem("七顆球");

        ball=new Button("確認");
        ball.setActionCommand("確認");
        ball.addActionListener(this);

        btn=new Button("確認");
        btn.setActionCommand("確認");
        btn.addActionListener(this);

        btn1=new Button("確認");
        btn1.setActionCommand("確認");
        btn1.addActionListener(this);

        btn2=new Button("確認");
        btn2.setActionCommand("確認");
        btn2.addActionListener(this);

        setBounds(400,300,700,300);
        this.setVisible(true);
//-----------------------------取料區
        btclose = new JLabel("   取料區   ");
        getContentPane().add(btclose);

        abc = new JLabel("   紅球數量    ");
        getContentPane().add(abc);

        getContentPane().add(redball);

        btslowf = new JLabel("   藍球數量    ");
        getContentPane().add(btslowf);

        getContentPane().add(blueball);

        btBackward = new JLabel("     ");
        getContentPane().add(btBackward);

        getContentPane().add(ball);
//----------------------------------------------------------欄位
        btclose = new JLabel("  車種 ");
        getContentPane().add(btclose);
        abc = new JLabel(" 一號工作站 ");
        getContentPane().add(abc);

          btopen = new JLabel(" 數量 ");
        getContentPane().add(btopen);

        btslowf = new JLabel(" 二號工作站 ");
        getContentPane().add(btslowf);

        btLeft = new JLabel("  數量  ");
        getContentPane().add(btLeft);

        btBackward = new JLabel(" 三號工作站 ");
        getContentPane().add(btBackward);

        btRight = new JLabel("  數量  ");
        getContentPane().add(btRight);

        btslowl = new JLabel(" 確認 ");
        getContentPane().add(btslowl);
//------------------------------------------------------------------ 第一排a車
        btslowb = new JLabel("  物流車(A)  ");
        getContentPane().add(btslowb);

        btopen = new JLabel("     ");
        getContentPane().add(btopen);

        getContentPane().add(choi);

        btLeft = new JLabel("        ");
        getContentPane().add(btLeft);

        getContentPane().add(cho);

        btRight = new JLabel("         ");
        getContentPane().add(btRight);

        getContentPane().add(cho1);

        getContentPane().add(btn);
        btslowb = new JLabel("      ");
        getContentPane().add(btslowb);
//-------------------------------------------------------第二排B車
        btslowb = new JLabel("  物流車(B)  ");
        getContentPane().add(btslowb);

        btopen = new JLabel("     ");
        getContentPane().add(btopen);

        getContentPane().add(cho2);

        btLeft = new JLabel("        ");
        getContentPane().add(btLeft);

        getContentPane().add(cho3);

        btRight = new JLabel("         ");
        getContentPane().add(btRight);

        getContentPane().add(cho4);

        getContentPane().add(btn1);

        btslowb = new JLabel("      ");
        getContentPane().add(btslowb);
//-------------------------------------------------------------第三排C車
        btslowb = new JLabel("  物流車(C)  ");
        getContentPane().add(btslowb);

        btopen = new JLabel("     ");
        getContentPane().add(btopen);

        getContentPane().add(cho5);

        btLeft = new JLabel("        ");
        getContentPane().add(btLeft);

        getContentPane().add(cho6);

        btRight = new JLabel("         ");
        getContentPane().add(btRight);

        getContentPane().add(cho7);

        getContentPane().add(btn2);

        btslowb = new JLabel("      ");
        getContentPane().add(btslowb);
        setResizable(false);
        addWindowListener(new WindowAdapter() {
            public void windowClosing(WindowEvent e) {
                System.exit(0);
            }
        });
    }

    public static void main(String[] args) {
        new test3();
    }
}

results matching ""

    No results matching ""