首页 > 代码库 > JAVA写的模拟收发器设备面板工作状态并输出图形界面

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//机架面板

{//by Cooling QQ:21156410 http://xu-laoshi.cn

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=http://www.mamicode.com/getParameter("style"+Integer.toString(i));

ledvalue=http://www.mamicode.com/getParameter("led"+Integer.toString(i));

if (stylevalue =http://www.mamicode.com/= null) {

stylevalue = "http://www.mamicode.com/255";

}

if (ledvalue =http://www.mamicode.com/= null){

ledvalue = "http://www.mamicode.com/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=http://www.mamicode.com/Integer.toBinaryString(temp);

while(ledvalue.length()<8){

ledvalue="http://www.mamicode.com/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="http://www.mamicode.com/192.168.3.254">

<param name=JjNo value=http://www.mamicode.com/1>

<param name=style0 value=http://www.mamicode.com/0>

<param name=led0 value=http://www.mamicode.com/0>

<param name=style1 value=http://www.mamicode.com/1>

<param name=led1 value=http://www.mamicode.com/1>

<param name=style2 value=http://www.mamicode.com/2>

<param name=led2 value=http://www.mamicode.com/2>

<param name=style3 value=http://www.mamicode.com/0>

<param name=led3 value=http://www.mamicode.com/3>

<param name=style4 value=http://www.mamicode.com/1>

<param name=led4 value=http://www.mamicode.com/4>

<param name=style5 value=http://www.mamicode.com/2>

<param name=led5 value=http://www.mamicode.com/5>

<param name=style6 value=http://www.mamicode.com/1>

<param name=led6 value=http://www.mamicode.com/6>

<param name=style7 value=http://www.mamicode.com/1>

<param name=led7 value=http://www.mamicode.com/2>

<param name=style8 value=http://www.mamicode.com/0>

<param name=led8 value=http://www.mamicode.com/8>

<param name=style9 value=http://www.mamicode.com/1>

<param name=led9 value=http://www.mamicode.com/9>

<param name=style10 value=http://www.mamicode.com/0>

<param name=led10 value=http://www.mamicode.com/10>

<param name=style11 value=http://www.mamicode.com/1>

<param name=led11 value=http://www.mamicode.com/11>

<param name=style12 value=http://www.mamicode.com/2>

<param name=led12 value=http://www.mamicode.com/12>

<param name=style13 value=http://www.mamicode.com/1>

<param name=led13 value=http://www.mamicode.com/13>

<param name=style14 value=http://www.mamicode.com/1>

<param name=led14 value=http://www.mamicode.com/14>

<param name=style15 value=http://www.mamicode.com/1>

<param name=led15 value=http://www.mamicode.com/15>

</APPLET>

</CENTER>

</BODY>

</HTML>




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