正文

中央空调模拟器(客户端全面版)(无图片)2006-05-24 19:17:00

【评论】 【打印】 【字体: 】 本文链接:http://blog.pfan.cn/hofy/14804.html

分享到:

import java.awt.*;import java.awt.event.*;import java.net.*;import javax.swing.*;import javax.swing.event.*;import java.io.*;import java.util.*; public class ktclient{ public static void main(String args[]) {  jiemian j=new jiemian();       }} class jiemian extends JFrame implements ActionListener{ String[] wsettem={ "初使状态","18.0 ℃","19.0 ℃","20.0 ℃","21.0 ℃","22.0 ℃","23.0 ℃","24.0 ℃","25.0 ℃","25.0 ℃","26.0 ℃","27.0 ℃","28.0 ℃","29.0 ℃","30.0 ℃","31.0 ℃","32.0 ℃"  };   JButton connect=new JButton("打开"); JButton disconnect=new JButton("关上"); JButton settem=new JButton("调节温度");  JPanel jp=new JPanel(); JPanel jpwdj=new JPanel();  JTextField jtconnect=new JTextField(); JComboBox jcbsettem1=new JComboBox(wsettem);  JLabel title=new JLabel("中央空调管理系统客户端程序"); JTextArea ltnr=new JTextArea();  JLabel jl1=new JLabel("当前温度"); JLabel jl2=new JLabel("目标温度"); JLabel jl3=new JLabel("室外温度"); JLabel mianban1=new JLabel(); JLabel point1=new JLabel(); JLabel point2=new JLabel(); JLabel point3=new JLabel(); JLabel jl4=new JLabel("输入房间号:"); JLabel jl5=new JLabel("请选择目标温度:"); JLabel jl6=new JLabel("消息栏:"); JLabel shuzi1=new JLabel(); JLabel shuzi2=new JLabel(); JLabel shuzi3=new JLabel(); JLabel shuzi4=new JLabel(); JLabel shuzi5=new JLabel(); JLabel shuzi6=new JLabel(); JLabel shuzi7=new JLabel(); JLabel shuzi8=new JLabel(); JLabel shuzi9=new JLabel(); JLabel image=new JLabel(); JLabel wenduji=new JLabel("温度计");   ktclient_thread ct=null; cloudleaf cl=new cloudleaf(jp); wenduji w1=new wenduji(jpwdj); up_shuzi s1=new up_shuzi(shuzi1,shuzi2,shuzi3); Font f1=new Font("Helvetica",Font.BOLD,17);  public jiemian() {  super("中央空调系统 客户端");    Container c=this.getContentPane();  c.setLayout(null);    jp.setBounds(25,255,380,70);    jp.setBackground(Color.BLACK);    c.add(jp);    title.setBounds(180,10,249,30);  title.setFont(f1);  image.setBounds(550,10,50,50);  image.setIcon(new ImageIcon("biaoti.jpg"));  c.add(image);  c.add(title);    jl1.setBounds(95,150,90,10);  jl2.setBounds(205,150,90,10);  jl3.setBounds(315,150,90,10);  jl4.setBounds(340,66,90,10);  jl5.setBounds(100,66,105,10);  jl6.setBounds(420,125,90,10);  wenduji.setBounds(29,40,80,10);  c.add(jl1);  c.add(jl2);  c.add(jl3);  c.add(jl4);  c.add(jl5);  c.add(jl6);  c.add(wenduji);    jpwdj.setBounds(25,59,40,160);  jpwdj.setBackground(Color.BLACK);   c.add(jpwdj);            ltnr.setBounds(420,140,170,185);  ltnr.setEnabled(false);  ltnr.setLineWrap(true);  c.add(ltnr);      mianban1.setBounds(25,228,380,27);  mianban1.setIcon(new ImageIcon("clouding0.jpg"));  c.add(mianban1);    shuzi1.setBounds(90,170,26,36);  shuzi2.setBounds(117,170,26,36);  shuzi3.setBounds(155,170,26,36);  shuzi4.setBounds(200,170,26,36);  shuzi5.setBounds(228,170,26,36);  shuzi6.setBounds(266,170,26,36);  shuzi7.setBounds(312,170,26,36);  shuzi8.setBounds(339,170,26,36);  shuzi9.setBounds(377,170,26,36);  point1.setBounds(146,175,5,5);  point2.setBounds(257,175,5,5);  point3.setBounds(368,175,5,5);  shuzi1.setIcon(new ImageIcon("l0.jpg"));  shuzi2.setIcon(new ImageIcon("l0.jpg"));  shuzi3.setIcon(new ImageIcon("l0.jpg"));  shuzi4.setIcon(new ImageIcon("l0.jpg"));  shuzi5.setIcon(new ImageIcon("l0.jpg"));  shuzi6.setIcon(new ImageIcon("l0.jpg"));  shuzi7.setIcon(new ImageIcon("l0.jpg"));  shuzi8.setIcon(new ImageIcon("l0.jpg"));  shuzi9.setIcon(new ImageIcon("l0.jpg"));  point1.setIcon(new ImageIcon("point.jpg"));  point2.setIcon(new ImageIcon("point.jpg"));  point3.setIcon(new ImageIcon("point.jpg"));  c.add(shuzi1);  c.add(shuzi2);  c.add(shuzi3);  c.add(shuzi4);  c.add(shuzi5);  c.add(shuzi6);  c.add(shuzi7);  c.add(shuzi8);  c.add(shuzi9);  c.add(point1);  c.add(point2);  c.add(point3);      connect.setBounds(430,80,80,20);  disconnect.setBounds(520,80,80,20);  settem.setBounds(220,80,100,20);  connect.addActionListener(this);  disconnect.addActionListener(this);  settem.addActionListener(this);  c.add(connect);  c.add(disconnect);  c.add(settem);    jtconnect.setBounds(340,80,80,20);  c.add(jtconnect);   jcbsettem1.setBounds(100,80,110,20);  jcbsettem1.setVisible(true);  c.add(jcbsettem1);    this.setConnectStatus(false);    this.setBounds(100,100,620,370);  this.setVisible(true);  this.setResizable(false);    this.addWindowListener(new WindowAdapter() {          public void windowClosing(WindowEvent e)          {           if(jiemian.this.disconnect.isEnabled())           {            try            {             jiemian.this.ct.out.writeUTF("#leave#");            }            catch(Exception ee)            {            }            jiemian.this.ct.flag=false;           }           System.exit(0);          }});   }   public void setConnectStatus(boolean status)//kong zhi button enabled  {   jtconnect.setEnabled(!status);   connect.setEnabled(!status);      disconnect.setEnabled(status);      jcbsettem1.setEnabled(true);        }   public void actionPerformed(ActionEvent e)  {      //----------------------#room#-------------------------------   if (e.getSource()==connect||e.getSource()==jtconnect)   {    if(jtconnect.getText().trim().equals(""))    {     messagebox info=new messagebox(this,"对不起,房间号不能为空",true);     return;     }    if(jcbsettem1.getSelectedIndex()==0)    {     messagebox info=new messagebox(this,"温度不能为空!",true);     return;    }            try    {     Socket sd=new Socket("localhost",10000);     ktclient_thread ct=new ktclient_thread(this,sd);     ct.out.writeUTF("#ROOM#"+jtconnect.getText().trim()+","+jcbsettem1.getSelectedItem().toString().trim()+","+"25"+","+"吹冷风");       ct.start();     this.ct=ct;               this.setConnectStatus(true);     }        catch(Exception ee)    {     messagebox info=new messagebox(this,"暂不能和服务器连接",true);    }       }   //----------------------#room#-------------------------------   //----------------------#leave#------------------------------   if(e.getSource()==disconnect)   {    try    {     this.ct.out.writeUTF("#LEAVE#"+jtconnect.getText().trim());    }    catch(Exception ee)    {         }    this.ct.flag=false;    this.ct=null;    this.cl.flag=false;    this.cl=null;    this.w1.flag=false;    this.w1=null;    this.s1.flag=false;    this.s1=null;    this.setConnectStatus(false);   }    //--------------------#changetem#-----------------------------*/      if (e.getSource()==settem)   {       String tiaojie=this.jtconnect.getText().trim()+"需要温度:"+this.jcbsettem1.getSelectedItem();        try    {     //change mubiaowendu     if (jcbsettem1.getSelectedItem().equals("18.0 ℃"))      {       this.shuzi4.setIcon(new ImageIcon("l1.jpg"));        this.shuzi5.setIcon(new ImageIcon("l8.jpg"));        this.shuzi6.setIcon(new ImageIcon("l0.jpg"));      }     if (jcbsettem1.getSelectedItem().equals("19.0 ℃"))      {       this.shuzi4.setIcon(new ImageIcon("l1.jpg"));        this.shuzi5.setIcon(new ImageIcon("l9.jpg"));        this.shuzi6.setIcon(new ImageIcon("l0.jpg"));      }     if (jcbsettem1.getSelectedItem().equals("20.0 ℃"))      {       this.shuzi4.setIcon(new ImageIcon("l2.jpg"));        this.shuzi5.setIcon(new ImageIcon("l0.jpg"));        this.shuzi6.setIcon(new ImageIcon("l0.jpg"));      }     if (jcbsettem1.getSelectedItem().equals("21.0 ℃"))      {       this.shuzi4.setIcon(new ImageIcon("l2.jpg"));        this.shuzi5.setIcon(new ImageIcon("l1.jpg"));        this.shuzi6.setIcon(new ImageIcon("l0.jpg"));      }     if (jcbsettem1.getSelectedItem().equals("22.0 ℃"))      {       this.shuzi4.setIcon(new ImageIcon("l2.jpg"));        this.shuzi5.setIcon(new ImageIcon("l2.jpg"));        this.shuzi6.setIcon(new ImageIcon("l0.jpg"));      }     if (jcbsettem1.getSelectedItem().equals("23.0 ℃"))      {       this.shuzi4.setIcon(new ImageIcon("l2.jpg"));        this.shuzi5.setIcon(new ImageIcon("l3.jpg"));        this.shuzi6.setIcon(new ImageIcon("l0.jpg"));      }     if (jcbsettem1.getSelectedItem().equals("24.0 ℃"))      {       this.shuzi4.setIcon(new ImageIcon("l2.jpg"));        this.shuzi5.setIcon(new ImageIcon("l4.jpg"));        this.shuzi6.setIcon(new ImageIcon("l0.jpg"));      }     if (jcbsettem1.getSelectedItem().equals("25.0 ℃"))      {       this.shuzi4.setIcon(new ImageIcon("l2.jpg"));        this.shuzi5.setIcon(new ImageIcon("l5.jpg"));        this.shuzi6.setIcon(new ImageIcon("l0.jpg"));      }     if (jcbsettem1.getSelectedItem().equals("26.0 ℃"))      {       this.shuzi4.setIcon(new ImageIcon("l2.jpg"));        this.shuzi5.setIcon(new ImageIcon("l6.jpg"));        this.shuzi6.setIcon(new ImageIcon("l0.jpg"));      }     if (jcbsettem1.getSelectedItem().equals("27.0 ℃"))      {       this.shuzi4.setIcon(new ImageIcon("l2.jpg"));        this.shuzi5.setIcon(new ImageIcon("l7.jpg"));        this.shuzi6.setIcon(new ImageIcon("l0.jpg"));      }     if (jcbsettem1.getSelectedItem().equals("28.0 ℃"))      {       this.shuzi4.setIcon(new ImageIcon("l2.jpg"));        this.shuzi5.setIcon(new ImageIcon("l8.jpg"));        this.shuzi6.setIcon(new ImageIcon("l0.jpg"));      }     if (jcbsettem1.getSelectedItem().equals("29.0 ℃"))      {       this.shuzi4.setIcon(new ImageIcon("l2.jpg"));        this.shuzi5.setIcon(new ImageIcon("l9.jpg"));        this.shuzi6.setIcon(new ImageIcon("l0.jpg"));      }     if (jcbsettem1.getSelectedItem().equals("30.0 ℃"))      {       this.shuzi4.setIcon(new ImageIcon("l3.jpg"));        this.shuzi5.setIcon(new ImageIcon("l0.jpg"));        this.shuzi6.setIcon(new ImageIcon("l0.jpg"));      }     if (jcbsettem1.getSelectedItem().equals("31.0 ℃"))      {       this.shuzi4.setIcon(new ImageIcon("l3.jpg"));        this.shuzi5.setIcon(new ImageIcon("l1.jpg"));        this.shuzi6.setIcon(new ImageIcon("l0.jpg"));      }     if (jcbsettem1.getSelectedItem().equals("32.0 ℃"))      {       this.shuzi4.setIcon(new ImageIcon("l3.jpg"));        this.shuzi5.setIcon(new ImageIcon("l2.jpg"));        this.shuzi6.setIcon(new ImageIcon("l0.jpg"));      }      if(this.jcbsettem1.getSelectedItem().equals("初使状态"))      {        messagebox info=new messagebox(this,"对不起,目标温度不能为空",true);                  return;        }      this.ct.out.writeUTF("#tem#"+tiaojie);         }    catch(Exception ew)    {    }    }        //settem button--     }} class ktclient_thread extends Thread{ jiemian father; Socket sd; DataInputStream in; DataOutputStream out; boolean flag=true;  public ktclient_thread(jiemian father,Socket sd) {  this.father=father;  this.sd=sd;    try  {   in=new DataInputStream(this.sd.getInputStream());   out=new DataOutputStream(this.sd.getOutputStream());  }    catch(Exception e)  {     }   }  public void run() {  while(flag)  {   String s=null;   try   {    s=this.in.readUTF();   }   catch(Exception e)   {   }   if(s!=null)   {    //--------------------#right#-------------------------    if(s.startsWith("#RIGHT#"))    {     s=s.substring(7);     this.father.ltnr.append("开始服务"+"\n"+"室外温度:"+s+"\n");     String temp_n1=s.substring(0,1);     this.father.shuzi7.setIcon(new ImageIcon("l"+temp_n1+".jpg"));          this.father.cl.flag=true;     this.father.cl.start();     this.father.w1.flag=true;     this.father.w1.start();     this.father.s1.flag=true;          this.father.s1.start();    }    //--------------------#right#-------------------------        //--------------------#error#-------------------------    if (s.startsWith("#ERROR#"))    {     this.father.ltnr.append("对不起,房间号不能重复"+"\n");     this.father.setConnectStatus(false);     this.flag=false;     this.father.ct=null;    }    //--------------------#error#-------------------------        //--------------------#close#-------------------------    if (s.startsWith("#CLOSE#"))    {     this.father.ltnr.append("服务器关机!!"+"\n");     this.flag=false;          this.father.setConnectStatus(false);    }        //--------------------#close#-------------------------   }  } }} class messagebox extends JDialog implements ActionListener{ jiemian father; String m; boolean b; JButton queding=new JButton("确定"); JTextArea ja=new JTextArea(); public messagebox(jiemian father,String m,boolean b) {    super(father,m,b);    this.m=m;  this.father=father;    Container c=this.getContentPane();  c.setLayout(null);    ja.setBounds(5,5,135,40);  ja.setText(this.m);  ja.setLineWrap(true);    ja.setBackground(Color.WHITE);  c.add(ja);    queding.setBounds(50,50,60,20);  queding.addActionListener(this);  c.add(queding);    int x=(int)this.father.getLocation().getX();  int y=(int)this.father.getLocation().getY();    this.setBounds(x+100,y+60,160,110);  this.setVisible(true);  this.setResizable(true);    this.addWindowListener(new WindowAdapter(){             public void windowClosing(WindowEvent e)             {              messagebox.this.father.setEnabled(true);              messagebox.this.dispose();             }}); }  public void actionPerformed(ActionEvent e) {  this.father.setEnabled(true);  this.dispose(); }} class cloudleaf extends Thread{ JPanel jp; boolean flag=true; int y=2;  public cloudleaf(JPanel jp) {  this.jp=jp; }  public void run() {   Graphics g=jp.getGraphics();      while(flag)   {    g.setColor(Color.BLACK);    g.fillRect(0,0,380,70);        g.setColor(new Color(150,210-y,238-y));    g.fillRect(10,-13+y,360,y/2);        g.setColor(new Color(123,195-y,238-y));    g.fillRect(10,y,360,y/2);        g.setColor(new Color(79,195-y*2,238-y*2));    g.fillRect(10,13+y,360,y/2);        g.setColor(new Color(50,160-y*3,238-y*3));    g.fillRect(10,26+y,360,y/2);        g.setColor(new Color(20,150-y*4,238-y*4));    g.fillRect(10,39+y,360,y/2);        g.setColor(new Color(5,139-y*5,238-y*5));    g.fillRect(10,52+y,360,y/2);       try    {     Thread.sleep(150);     }    catch(Exception e)    {        }       y+=2;     if(y>14) y=2;          }      g.dispose(); }} class wenduji extends Thread{ JPanel jpwdj; boolean flag=true; int ww=2;  public wenduji(JPanel jpwdj) {  this.jpwdj=jpwdj; }  public void run() {   Graphics w=jpwdj.getGraphics();      while(flag)   {    w.setColor(Color.BLACK);    w.fillRect(0,0,40,135);        w.setColor(new Color(251,90,130));    w.fillOval(9,130,23,27);        w.setColor(new Color(251,90,130));    w.fillRect(15,135-ww/2,10,ww/2);       try    {     Thread.sleep(150);     }    catch(Exception e)    {    }    ww+=2;     if(ww>250) ww=2;        }      w.dispose(); }} class up_shuzi extends Thread{ int i=-1; int j=0; int k=0; boolean flag=true; JLabel shuzi1,shuzi2,shuzi3; public up_shuzi(JLabel shuzi1,JLabel shuzi2,JLabel shuzi3) {  this.shuzi1=shuzi1;  this.shuzi2=shuzi2;  this.shuzi3=shuzi3; } public void run() {   while(flag)  {   i+=1;   if (i==100) i=0;       if (i%100==0)    {      shuzi1.setIcon(new ImageIcon("l"+k+".jpg"));      k+=1;    if (k==5) k=0;    }    if (i%10==0)    {    shuzi2.setIcon(new ImageIcon("l"+j+".jpg"));    j+=1;    if (j==10) j=0;   }     shuzi3.setIcon(new ImageIcon("l"+i%10+".jpg"));                 try     {      Thread.sleep(300);     }     catch(Exception e)     {     }     }    }} class down_shuzi extends Thread{ int i=100; int j=10; int k=5; boolean flag=true; JLabel shuzi1,shuzi2,shuzi3; public down_shuzi(JLabel shuzi1,JLabel shuzi2,JLabel shuzi3) {  this.shuzi1=shuzi1;  this.shuzi2=shuzi2;  this.shuzi3=shuzi3; } public void run() {  while (flag)  {   i-=1;   if (i==0) i=100;       if (i%100==0)    {      shuzi1.setIcon(new ImageIcon("l"+k+".jpg"));      k-=1;    if (k==0) k=5;    }    if (i%10==9)    {    shuzi2.setIcon(new ImageIcon("l"+(j-1)+".jpg"));    j-=1;    if (j==0) j=10;   }      shuzi3.setIcon(new ImageIcon("l"+i%10+".jpg"));                 try     {      Thread.sleep(300);     }     catch(Exception e)    {     }    }  }}

阅读(19262) | 评论(0)


版权声明:编程爱好者网站为此博客服务提供商,如本文牵涉到版权问题,编程爱好者网站不承担相关责任,如有版权问题请直接与本文作者联系解决。谢谢!

评论

暂无评论
您需要登录后才能评论,请 登录 或者 注册