import java.applet.Applet;
import java.awt.Image;
import java.awt.Graphics;
import java.awt.Rectangle;
import java.awt.MediaTracker;
import java.awt.event.*;
import java.util.StringTokenizer;
import java.util.Vector;
import java.util.Hashtable;
import java.net.URL;
import java.awt.image.ImageProducer;
import java.awt.image.ImageFilter;
import java.awt.image.CropImageFilter;
import java.awt.image.FilteredImageSource;
import java.net.MalformedURLException;
import java.awt.*;
public class Mb extends Applet
implements MouseListener, MouseMotionListener, Runnable {
//********************************* Dim ***********************************
//********************************* Prepare ***********************************
Color ColorDarker(Color c) {
return c.darker();
}
Color ColorBrighter(Color c) {
return c.brighter();
}
void DrawLed(Graphics g, int x, int y, boolean On) {
//Led
int diam = 12;
Color LedColor;
Color BgColor = new Color(36, 46, 103);
if (On) {
LedColor = Color.green;
} else {
LedColor = new Color(198, 195, 198);
}
//Draw the Led beveled-outline portion.
g.setColor(ColorDarker(BgColor));
g.drawArc(x, y, diam, diam, 45, 180);
g.setColor(ColorBrighter(BgColor));
g.drawArc(x, y, diam, diam, 255, 180);
//Draw the Led fill portion.
g.setColor(LedColor);
g.fillOval(x+1, y+1, diam-2, diam-2);
//Draw the Led reflection and shadow arcs.
//This first reflection arc lies close to the upper-left edge.
g.setColor(ColorBrighter(LedColor));
g.drawArc(x + (diam / 10),
y + (diam / 10),
(4 * diam) / 5,
(4 * diam) / 5,
80,
110);
//These two, smaller arcs are closer to the center of the bulb,
//but are offset towards the light-source.
g.setColor(Color.white);
g.drawArc(x + (diam / 4) + 1,
y + (diam / 4) + 1,
(diam) / 4,
(diam) /4,
80,
110);
g.drawArc(x + (diam / 4) + 2,
y + (diam / 4) + 2,
(diam) / 5,
(diam) / 5,
80,
100);
//This final, shadow arc lies close to the lower-left edge.
g.setColor(ColorDarker(LedColor));
g.drawArc(x + (diam / 10),
y + (diam / 10),
(3 * diam) / 5,
(3 * diam) / 5,
260,
110);
}
void DrawTP(Graphics g, int x, int y, boolean On) {
//Draw TP OnLine and OffLine
int width = 22;
int height = 29;
int b = 6;//bound Space
int R = 3*(width-2*b)/8+1;
int r = R/3;
Color RjColor;
Color BgColor;
if (On) {
RjColor = new Color(30, 160, 208);
BgColor = new Color(165, 250, 201);
} else {
RjColor = Color.gray;
BgColor = ColorBrighter(Color.gray);
}
//Draw outter background
g.setColor(Color.white);
g.fillRect(x, y, width, height);
g.setColor(Color.black);
g.drawRect(x+2, y+2, width-4, height-4);
g.drawRect(x+3, y+3, width-6, height-6);
g.setColor(BgColor);
g.fillRect(x+4, y+4, width-8, height-8);
//Dill inner-RJ45 port
g.setColor(RjColor);
g.fillRect(x+b, y+b, width-2*b-R/2, height-2*b);
g.setColor(Color.black);
g.drawRect(x+b, y+b, width-2*b-R/2, height-2*b);
g.setColor(RjColor);
g.fillArc(x+width-b-2*R, y+b+r+1, 2*R, 2*R, 300, 120);
g.setColor(Color.black);
g.drawArc(x+width-b-2*R, y+b+r+1, 2*R, 2*R, 300, 120);
}
void DrawFxPort(Graphics g, int x, int y, int diam, Color c) {
//Draw FxPort OnLine and OffLine
//Draw Outer-bound
g.setColor(Color.black);
g.drawOval(x, y, diam, diam);
g.setColor(c);
g.fillOval(x+1, y+1, diam-2, diam-2);
}
void DrawFX(Graphics g, int x, int y, boolean On) {
//Draw FX OnLine and OffLine
int width = 22;
int height = 57;
int b = 6;//bound Space
int R = (width)/4;
Color RjColor;
Color BgColor;
if (On) {
RjColor = new Color(30, 160, 208);
BgColor = new Color(165, 250, 201);
} else {
RjColor = Color.gray;
BgColor = ColorBrighter(Color.gray);
}
//Draw outter background
g.setColor(Color.white);
g.fillRect(x, y, width, height);
g.setColor(Color.black);
g.drawRect(x+1, y+1, width-2, height-2);
g.setColor(BgColor);
g.fillRect(x+2, y+2, width-4, height-4);
//Draw inner FX port
DrawFxPort(g, x+width/2-R, y+2*b, 2*R, RjColor);
DrawFxPort(g, x+width/2-R, y+height-2*b-2*R, 2*R, RjColor);
}
void DrawCcMb(Graphics g, int x, int y, int index, int style, boolean On) {
//Draw Mb OnLine and OffLine by Style
int width = 47;
int height = 235;
int b = height/36;
Color MbColor = new Color(36, 46, 103);
g.setColor(Color.white);
g.drawLine(x, y, x, y+height);//left
g.drawLine(x, y, x+width, y);//top
g.setColor(ColorDarker(Color.white));
g.drawLine(x+width, y, x+width, y+height);//right
g.drawLine(x, y+height, x+width, y+height);//bottom
//Fill BackGrand
g.setColor(MbColor);
g.fillRect(x+3, y+3, width-5, height-5);
//Draw Caption
g.setColor(Color.white);
g.drawString(""+index, x+(width-6)/2, y+5*b);
if (On) {
//Draw TP, FX, Led
DrawTP(g, x+(47-21)/2, y+7*b, false);//22,29
DrawTP(g, x+(47-21)/2, y+7*b+29+b, true);//22,29
DrawLed(g, x+4, y+7*b+29+2*b+29+2*b, false);//12
DrawLed(g, x+4+12+2, y+7*b+29+2*b+29+2*b, false);
DrawLed(g, x+4+12+2+12+2, y+7*b+29+2*b+29+2*b, true);
DrawLed(g, x+4, y+7*b+29+2*b+29+2*b+12+2, false);
DrawLed(g, x+4+12+2, y+7*b+29+2*b+29+2*b+12+2, false);
DrawLed(g, x+4+12+2+12+2, y+7*b+29+2*b+29+2*b+12+2, false);
DrawFX(g, x+(47-21)/2, y+7*b+29+2*b+29+2*b+12+2+12+2*b, true);//22,57
}
}
//********************************* Exec ***********************************
// public void init() {
// DrawLed(this.getGraphics(), 1, 1, 10, Color.green);
// }
public void paint(Graphics g) {
setBackground(Color.gray);
DrawCcMb(this.getGraphics(), 10, 10, 10, 1, true);
}
public void run() {
}
public void mouseDragged(MouseEvent e) {
}
public void mouseMoved(MouseEvent e) {
}
public void mouseClicked(MouseEvent e) {
}
public void mousePressed(MouseEvent e) {
}
public void mouseReleased(MouseEvent e) {
}
public void mouseEntered(MouseEvent e) {
}
public void mouseExited(MouseEvent e) {
}
}
//html 文档
<HTML>
<HEAD>
</HEAD>
<BODY BGCOLOR="000000">
<CENTER>
<APPLET
code = "Mb.class"
width = "500"
height = "300"
>
alt="你的浏览器不支持java,请安装java插件!"
</APPLET>
</CENTER>
</BODY>
</HTML>
//****************************************
我要求的界面就是这样的,但我现在还希望能够实现下面的功能:
1、当鼠标移动到每个led,tp,fx上时,有tooltip显示出来。
2、鼠标单击控件范围内时,可以打开一个网页,比如 www.xxx.com/jj.htm
分不够再加
http://expert.csdn.net/Expert/topic/2629/2629672.xml?temp=.1379816
这里的 100 分也是
5 个解决方案
#1
编译运行现在没有问题的。
#2
up
#3
import java.awt.*;
import java.applet.*;
class tp extends Component {
String index;
void DrawIndex(String idx, Graphics g) {
g.setColor(Color.red);
g.drawString(idx, 10, 50);
}
public tp(String idx){
index = idx;
}
public tp() {
index = "10";
}
public void paint(Graphics g) {
super.paint(g);
DrawIndex(index, g);
}
public void update(Graphics g) {
paint(g);
}
}
public class Temp extends Applet {
tp tp1 = new tp("ok");
public void init()
{
this.setLayout(new GridLayout(1,1));
add(tp1);
}
}
直接从awt继承下来的 tp 组件,要让它有 tooptips 的功能,应该怎样实现?
哪位同志实现过这样的功能,请赐教!!
import java.applet.*;
class tp extends Component {
String index;
void DrawIndex(String idx, Graphics g) {
g.setColor(Color.red);
g.drawString(idx, 10, 50);
}
public tp(String idx){
index = idx;
}
public tp() {
index = "10";
}
public void paint(Graphics g) {
super.paint(g);
DrawIndex(index, g);
}
public void update(Graphics g) {
paint(g);
}
}
public class Temp extends Applet {
tp tp1 = new tp("ok");
public void init()
{
this.setLayout(new GridLayout(1,1));
add(tp1);
}
}
直接从awt继承下来的 tp 组件,要让它有 tooptips 的功能,应该怎样实现?
哪位同志实现过这样的功能,请赐教!!
#4
swing组件好象有tooptips 吧
#5
to : xylohouse(xylohouse)
我希望从 awt 继承下来。
我希望从 awt 继承下来。
#1
编译运行现在没有问题的。
#2
up
#3
import java.awt.*;
import java.applet.*;
class tp extends Component {
String index;
void DrawIndex(String idx, Graphics g) {
g.setColor(Color.red);
g.drawString(idx, 10, 50);
}
public tp(String idx){
index = idx;
}
public tp() {
index = "10";
}
public void paint(Graphics g) {
super.paint(g);
DrawIndex(index, g);
}
public void update(Graphics g) {
paint(g);
}
}
public class Temp extends Applet {
tp tp1 = new tp("ok");
public void init()
{
this.setLayout(new GridLayout(1,1));
add(tp1);
}
}
直接从awt继承下来的 tp 组件,要让它有 tooptips 的功能,应该怎样实现?
哪位同志实现过这样的功能,请赐教!!
import java.applet.*;
class tp extends Component {
String index;
void DrawIndex(String idx, Graphics g) {
g.setColor(Color.red);
g.drawString(idx, 10, 50);
}
public tp(String idx){
index = idx;
}
public tp() {
index = "10";
}
public void paint(Graphics g) {
super.paint(g);
DrawIndex(index, g);
}
public void update(Graphics g) {
paint(g);
}
}
public class Temp extends Applet {
tp tp1 = new tp("ok");
public void init()
{
this.setLayout(new GridLayout(1,1));
add(tp1);
}
}
直接从awt继承下来的 tp 组件,要让它有 tooptips 的功能,应该怎样实现?
哪位同志实现过这样的功能,请赐教!!
#4
swing组件好象有tooptips 吧
#5
to : xylohouse(xylohouse)
我希望从 awt 继承下来。
我希望从 awt 继承下来。