import java.awt.*;
import java.awt.event.*;
import java.text.SimpleDateFormat;
import java.util.Date;
import javax.swing.*;
import javax.swing.JOptionPane;
import javax.swing.ScrollPaneConstants;
public class DrawFrame extends JFrame implements ItemListener{
private static DrawFrame drawfrm;
private static JLabel checkLab,dateLab,btLab,otLab,pcNo,ncNo,operateLab;
private static JTextField dateTxt,btTxt,otTxt;
private static JComboBox pcNobox,operatebox,drawbox;
private static JComboBox ncNobox;
    private static JButton NCPowerBt,NCReadyBt,powerBt,HeartBt,SPOnBt,SPReadyBt,
       XOnBt,XReadyBt,YOnBt,YReadyBt,ZOnBt,ZReadyBt,VoltageBt,CurrentBt,WenduBt,ShiduBt;
    private static JTextArea ncShowarea,ncpowerDraw,ncreadyDraw,powerDraw,HeartDraw,SPOnDraw,SPReadyDraw,
    XOnDraw,XReadyDraw,YOnDraw,YReadyDraw,ZOnDraw,ZReadyDraw,VoltageDraw,CurrentDraw,WenduDraw,ShiduDraw;
    private static JPanel drawPane,checkPane,showPane,operatePane,selectPane,blankPane,conPane,areaPane;
    private JScrollPane scrollPane,ncjsp;
    CardLayout cardLO=null;
    private JPanel NCPowerPane=null,NCReadyPane=null,PowerPane=null,HeartPane=null,SPOnPane=null,SPReadyPane=null,XOnPane=null,XReadyPane=null,
YOnPane=null,YReadyPane=null,ZOnPane=null,ZReadyPane=null,VoltagePane=null,CurrentPane=null,WenduPane=null,ShiduPane=null;

/**
 * 构造函数
 */
DrawFrame(int width, int height)
{
super("数据信号绘制系统");
setSize(width,height);
        /*获取系统时间*/
SimpleDateFormat df = new SimpleDateFormat("yyyy/MM/dd,HH:mm:ss");//设置日期格式
String date=df.format(new Date());// new Date()为获取当前系统时间
String temp[] = date.split(",");//将日期和时间分开
//System.out.println(date);
//构造查询条件面板
conPane=new JPanel(new GridLayout(1,2));
checkPane = new JPanel();
checkPane.setLayout(null);

//创建查询条件设置面板checkPane上的组建并定位
checkLab=new JLabel("1.查询内容和条件");
checkLab.setBounds(10,10,140,30);
checkPane.add(checkLab);
        dateLab=new JLabel("查询日期");
dateLab.setBounds(30,50,100,30);
checkPane.add(dateLab);
dateTxt=new JTextField(temp[0]);
dateTxt.setBounds(100,50,100,30);
checkPane.add(dateTxt);

btLab=new JLabel("起始时间");
btLab.setBounds(30,90,100,30);
checkPane.add(btLab);
btTxt=new JTextField("00:00:00");
btTxt.setBounds(100,90,100,30);
checkPane.add(btTxt);
otLab=new JLabel("结束时间");
otLab.setBounds(220,90,100,30);
checkPane.add(otLab);
otTxt=new JTextField(temp[1]);
otTxt.setBounds(290,90,100,30);
checkPane.add(otTxt);
pcNo=new JLabel("计算机编号");
pcNo.setBounds(30,130,100,30);
checkPane.add(pcNo);
pcNobox=new JComboBox();
pcNobox.addItem("1");
pcNobox.addItem("2");
pcNobox.setEditable(true);
pcNobox.setBounds(110,130,90,30);
checkPane.add(pcNobox);
ncNo=new JLabel("系统编号");
ncNo.setBounds(220,130,100,30);
checkPane.add(ncNo);
String[] groupNo={"1","2","3","4","5","6","7","8","9","10"};
ncNobox=new JComboBox(groupNo);
ncNobox.setEditable(true);
ncNobox.setBounds(300,130,90,30);
checkPane.add(ncNobox);
conPane.add(checkPane);
blankPane=new JPanel(new BorderLayout());
    //创建NC代码显示区域
ncShowarea=new JTextArea("运行的NC代码: ");
//ncShowarea自动换行
                  ncShowarea.setLineWrap(true);
ncjsp=new JScrollPane(ncShowarea);
ncjsp.setLocation(450,10);
ncjsp.setSize(400,180);
ncjsp.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
        blankPane.add(ncjsp);
        conPane.add(blankPane);
        conPane.setBounds(0,0,850,200);
        /*构造功能选择面板*/
//创建功能选择面板operatePane上的组建并定位
operatePane=new JPanel();
operatePane.setLayout(null);
operateLab=new JLabel("2.功能选择");
operateLab.setBounds(10,10,140,30);
operatePane.add(operateLab);
String[] sig={"Power","Ready"};
operatebox=new JComboBox(sig);
operatebox.setEditable(false);
operatebox.setBounds(10,50,100,30);
operatePane.add(operatebox);
operatePane.setBounds(0,210,850,90);
/*构造卡片式操作面板*/
//构造数据信号曲线展示子操作面板
cardLO = new CardLayout(5,5);
selectPane= new JPanel(cardLO);
//构造Power信号展示面板
NCPowerPane=new JPanel();
NCPowerPane.setLayout(null);
//NCPowerPane.setLayout(new FlowLayout(FlowLayout.CENTER,10,300));
NCPowerBt=new JButton("Power信号曲线展示");
        NCPowerBt.setBounds(300,300,200,40);
    NCPowerPane.add(NCPowerBt);
ncpowerDraw=new JTextArea();
ncpowerDraw.setBounds(0,360,850,90);
NCPowerPane.add(ncpowerDraw);
selectPane.add(NCPowerPane,"NCPower");
//构造Ready信号展示面板
NCReadyPane = new JPanel();
NCReadyPane.setLayout(new GridLayout(2,1));
NCReadyBt=new JButton("Ready信号曲线展示");
    NCReadyPane.add(NCReadyBt);
ncreadyDraw=new JTextArea();
NCReadyPane.add(ncreadyDraw);
selectPane.add(NCReadyPane,"NCReady");
            //构造HeartBeat信号展示面板
HeartPane = new JPanel();
HeartPane.setLayout(new GridLayout(2,1));
HeartBt=new JButton("HeartBeat信号曲线展示");
HeartPane.add(HeartBt);
HeartDraw=new JTextArea();
HeartPane.add(HeartDraw);
selectPane.add(HeartPane,"HeartBeat");
                add(selectPane);
//添加消息映射

operatebox.addItemListener((ItemListener) this);

}
/**
 * 主函数
 */
public static void main(String []args)
  {
drawfrm = new DrawFrame(900,500);
drawfrm.show();
  drawfrm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  drawfrm.setLayout(null);
  drawfrm.add(conPane);
  drawfrm.add(operatePane);
  drawfrm.add(selectPane);
  }      
/**
 * 组件状态更改的响应函数
 */
  public void itemStateChanged(ItemEvent ie){
  //信号选择
  if(operatebox.getSelectedItem().equals("NCPower"))
  cardLO.show(NCPowerPane,"NCPower");
  if(operatebox.getSelectedItem().equals("NCReady"))
 
cardLO.show(NCReadyPane,"NCReady");
                if(operatebox.getSelectedItem().equals("HeartBeat"))
  cardLO.show(HeartPane,"HeartBeat");}
}