码迷,mamicode.com
首页 > 编程语言 > 详细

JAVA写的模拟收发器设备面板工作状态并输出图形界面

时间:2016-11-24 22:11:11      阅读:216      评论:0      收藏:0      [点我收藏+]

标签:提示信息   java   收发器   

java模拟收发器工作状态,每个光口、电口、状态灯都可以跟随鼠标移动,显示提示信息。变异jiava代码生成class文件后,html文件调用。

技术分享

源代码,可以在附件里下载


mb.java 源代码如下:

import java.awt.*;

import java.awt.event.*;

import javax.swing.*;

import java.applet.*;

import java.net.URL;

import java.net.MalformedURLException;

public class Mb extends Applet//机架面板

{

Color BkColor=new Color(9,76,254);

final Color[] mycolor={new Color(0,255,0),new Color(198,195,198)};//0在线 1下线

String ip;

String JjNo;

String ledvalue;

String stylevalue;

public void init()

{

ip=getParameter("ip");

JjNo=getParameter("JjNo");

this.setLayout(new GridLayout(1,16));

for(int i=0;i<16;i++)

{

stylevalue=getParameter("style"+Integer.toString(i));

ledvalue=getParameter("led"+Integer.toString(i));

if (stylevalue == null) {

stylevalue = "255";

}

if (ledvalue == null){

ledvalue = "255";

}

add(new CcMb(i,stylevalue,ledvalue));

}

}

public boolean openurl(String avg)

{

URL url;

try

{

url = new URL("http://"+ip+"/cgi-bin/ccmain?jjno="+JjNo+"&ccno="+avg);

}

catch(MalformedURLException _ex)

{

System.out.println("URL not found.");

return true;

}

getAppletContext().showDocument(url, "_blank");

return true;

}

class CcMb extends JPanel implements ActionListener//插槽面板

{

Button JjIndex=null;

Label JjIdx=null;

final String[] CcStyle={"第1型号","第2型号","第3型号"};

String ledvalue;

int temp;

public CcMb(int j, String style, String led)

{

temp=Integer.valueOf(led).intValue();

ledvalue=Integer.toBinaryString(temp);

while(ledvalue.length()<8){

ledvalue="0"+ledvalue;

}

// this.add(new Label(ledvalue));}//////////////

this.setBackground(BkColor);

this.setLayout(new GridLayout(5,1));

this.setBorder(BorderFactory.createLineBorder(Color.gray));

if(Integer.parseInt(style)<16)

{

JjIndex=new Button(Integer.toString(j));

JjIndex.setBackground(BkColor);

JjIndex.addActionListener(this);

if(Integer.parseInt(style)==1)//自适应

{

add(JjIndex);

add(new FxPanel("电口 0",ledvalue.charAt(5)));//5

add(new FxPanel("电口 1",ledvalue.charAt(4)));//4

add(new sixLedPanel1(style,ledvalue));

add(new LxPanel("光口",ledvalue.charAt(3)));//3

}

else if(Integer.parseInt(style)==2)//100M

{

add(JjIndex);

add(new Label(""));

add(new FxPanel("电口",ledvalue.charAt(4)));//4

add(new sixLedPanel2(style,ledvalue));

add(new LxPanel("光口",ledvalue.charAt(3)));//3

}

}else

{

JjIdx=new Label(Integer.toString(j));

add(JjIdx);

}

}

public void actionPerformed(ActionEvent ev)

{

String label=ev.getActionCommand();

openurl(label);

}

}

class FxPanel extends JPanel//电口

{

int cl=1;

public FxPanel(String hint,char colorindex)

{

if(colorindex==‘1‘)

cl=0;

this.setBackground(BkColor);

this.setToolTipText(hint);

}

public void paintComponent(Graphics g)

{

super.paintComponent(g);

g.setColor(mycolor[cl]);

g.fill3DRect(5,5,20,30,false);

g.fill3DRect(25,10,5,20,false);

}

}

class LxPanel extends JPanel//光口

{

int cl=1;

public LxPanel(String hint,char colorindex)

{

if(colorindex==‘1‘)

cl=0;

this.setBackground(BkColor);

this.setToolTipText(hint);

}

public void paintComponent(Graphics g)

{

super.paintComponent(g);

g.setColor(mycolor[cl]);

g.fill3DRect(5,5,25,35,false);

g.fillArc(12,10,10,10,0,360);

g.fillArc(12,25,10,10,0,360);

}

}

class sixLedPanel1 extends JPanel//6个灯 自适应

{

public sixLedPanel1(String sty,String led)

{

this.setBackground(new Color(9,76,254));

this.setLayout(new GridLayout(2,3));

add(new LedPanel("SPD 1",led.charAt(6)));//6

add(new LedPanel("SPD 0",led.charAt(7)));//7

add(new LedPanel("电源",‘1‘));

add(new LedPanel("电口 1 Link",led.charAt(4)));//4

add(new LedPanel("电口 0 Link",led.charAt(5)));//5

add(new LedPanel("光口Link",led.charAt(3)));//3

}

}

class sixLedPanel2 extends JPanel//6个灯 100M

{

public sixLedPanel2(String sty,String led)

{

this.setBackground(new Color(9,76,254));

this.setLayout(new GridLayout(2,3));

add(new LedPanel("TP_TX",led.charAt(6)));//6

add(new LedPanel("光口Link",led.charAt(3)));//3

add(new LedPanel("FDXLED",led.charAt(7)));//7

add(new LedPanel("FX-T",led.charAt(5)));//5

add(new LedPanel("电口Link",led.charAt(4)));//4

add(new LedPanel("电源",‘1‘));

}

}

class LedPanel extends JPanel//一个灯

{

int ledx,ledy,ledr;

int cd=1;

public LedPanel(String hint,char clindex)

{

if(clindex==‘1‘)

cd=0;

this.setBackground(BkColor);

this.setToolTipText(hint);

}

public void paintComponent(Graphics g)

{

super.paintComponent(g);

g.setColor(mycolor[cd]);

g.fillArc(0,0,8,8,0,360);

}

}

}

 

mb.htm 文件如下:

<HTML>

<HEAD>

</HEAD>

<BODY BGCOLOR="ffffff">

<CENTER>

<APPLET

code = "Mb.class"

width = "570"

height = "220"

>

<param name=Ip value="192.168.3.254">

<param name=JjNo value=1>

<param name=style0 value=0>

<param name=led0 value=0>

<param name=style1 value=1>

<param name=led1 value=1>

<param name=style2 value=2>

<param name=led2 value=2>

<param name=style3 value=0>

<param name=led3 value=3>

<param name=style4 value=1>

<param name=led4 value=4>

<param name=style5 value=2>

<param name=led5 value=5>

<param name=style6 value=1>

<param name=led6 value=6>

<param name=style7 value=1>

<param name=led7 value=2>

<param name=style8 value=0>

<param name=led8 value=8>

<param name=style9 value=1>

<param name=led9 value=9>

<param name=style10 value=0>

<param name=led10 value=10>

<param name=style11 value=1>

<param name=led11 value=11>

<param name=style12 value=2>

<param name=led12 value=12>

<param name=style13 value=1>

<param name=led13 value=13>

<param name=style14 value=1>

<param name=led14 value=14>

<param name=style15 value=1>

<param name=led15 value=15>

</APPLET>

</CENTER>

</BODY>

</HTML>




JAVA写的模拟收发器设备面板工作状态并输出图形界面

标签:提示信息   java   收发器   

原文地址:http://8516023.blog.51cto.com/8506023/1876298

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!