hoxisoft(hoxisoft) :可以先不看我的源代码三,帮帮忙。
解决方案 »
- 用java开发桌面软件,有什么好的控件库吗?
- 谁有jdom的中文帮助文档啊,给我一份,实在没有英文也行
- 请哪位大侠帮忙看看,写拉一天代码,然后测试一个很简单的java类,出现下面的异常,急呀
- 关闭Socket 的问题
- snmp: westhawk.co.uk公司的java snmp开发包,接受Trap初始化异常:Socket already in use: Cannot bind
- 这样的现象你见过吗!我想你一定见过!呵呵,请指教!THANKS
- JAVA与C++关于JNI中文字符串操作问题???
- 请教写二进制文件的问题
- 着急,上火,怎么编译一批java文件?
- 什么情况下两个对象可以用“==”或者“!=”来比较啊?
- 如何在这个File类对象对应的文件尾部追加而不会覆盖以前的内容???
- 请教一下关于哈斯的概念
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.awt.image.*;class myIcon implements Icon//实现图标
{
//大框图
private double scale;
private int startX=3;
private int startY=3;
private double width;
private double height;
//网络故障二层
private double nWidth;
private double nHeight;
private int nStartx;
private int nStarty;
//电力故障三层
private double eWidth;
private double eHeight;
private int eStartx;
private int eStarty;
//顶层
//硬件故障一列
private double hWidth;
private double hHeight;
private int hStartx;
private int hStarty;
//软件故障二列
private double sWidth;
private double sHeight;
private int sStartx;
private int sStarty;
//更新故障二列
private double uWidth;
private double uHeight;
private int uStartx;
private int uStarty; //和个模块的颜色
private Color OK_COLOR=Color.green;
private Color NULL_COLOR=Color.lightGray;
private Color eColor= Color.black;
private Color nColor=Color.red;
private Color hColor=Color.orange;
private Color sColor=Color.white;
private Color uColor=Color.pink; myIcon(double a)
{
//大框图
scale=a;
width=100.0/scale;
height=200.0/scale;
//网络故障二层
nWidth=width;
nHeight=height/3;
nStartx=startX;
nStarty=startY+(int)nHeight;
//电力故障三层
eWidth=width;
eHeight=height-height*2/3+2;
eStartx=startX;
eStarty=nStarty+(int)nHeight;
//顶层//硬件故障一列
hWidth=width/3;
hHeight=nHeight;
hStartx=startX;
hStarty=startY;
//软件故障二列
sWidth=width/3;
sHeight=nHeight;
sStartx=hStartx+(int)hWidth;
sStarty=startY;
//更新故障二列
uWidth=width-hWidth-sWidth+2;
uHeight=nHeight;
uStartx=sStartx+(int)hWidth;
uStarty=startY;
}
public int getIconWidth(){return (int)width+3;}
public int getIconHeight(){return (int)height+3;}
public void paintIcon(Component c,Graphics g,int x,int y)
{
g.drawRect(startX,startY,(int)width,(int)height); g.setColor(nColor);
g.fillRect(nStartx,nStarty,(int)nWidth,(int)nHeight); g.setColor(eColor);
g.fillRect(eStartx,eStarty,(int)eWidth,(int)eHeight); g.setColor(hColor);
g.fillRect(hStartx,hStarty,(int)hWidth,(int)hHeight); g.setColor(sColor);
g.fillRect(sStartx,sStarty,(int)sWidth,(int)sHeight); g.setColor(uColor);
g.fillRect(uStartx,uStarty,(int)uWidth,(int)uHeight); g.draw3DRect(startX-1,startY-1,(int)width+1,(int)height+1,true);
g.draw3DRect(startX-2,startY-2,(int)width+2,(int)height+2,true);
g.draw3DRect(startX-3,startY-3,(int)width+3,(int)height+3,true);
}
}
class myPanel extends JPanel
{
private Graphics g;
private ImageIcon icon;
private Toolkit tool=Toolkit.getDefaultToolkit();
private myIcon myicon=new myIcon(2.0); private Point first,last;
int i=0;
private int width,height; JLabel mmm//小的
,lll;//大的
myPanel(JPanel jp)
{
setLayout(null);
icon=new ImageIcon("d.jpg");
mmm=new JLabel(myicon);
lll=new JLabel(icon);
lll.setBounds(0,0,icon.getIconWidth(),icon.getIconHeight());
mmm.setBounds(0,0,myicon.getIconWidth(),myicon.getIconHeight());
jp.add(mmm);
add(lll);
width=icon.getIconWidth();
height=icon.getIconHeight();
setSize(width,height);
mmm.addMouseListener(new MouseAdapter()
{
public void mousePressed(MouseEvent e)
{
first=e.getPoint();
System.out.println("first="+first);
}
public void mouseReleased(MouseEvent e)
{
} }
); //实现小图标的拖动
mmm.addMouseMotionListener(new MouseMotionAdapter()
{
public void mouseDragged(MouseEvent e)
{
JLabel ppp=(JLabel)e.getSource();
last=e.getPoint();
System.out.println("last="+last);
ppp.setLocation(ppp.getLocation().x+last.x-first.x,ppp.getLocation().y+last.y-first.y);
}
}
); }
public int getWidth(){return width;}
public int getHeight(){return height;}
}
class myView extends JViewport implements AdjustmentListener
{
//实现滚屏
public void adjustmentValueChanged(AdjustmentEvent e)
{
if(((JScrollBar)e.getSource()).getName().equals("a"))
setViewPosition(new Point(getViewPosition().x,e.getValue()));
else if(((JScrollBar)e.getSource()).getName().equals("b"))
setViewPosition(new Point(e.getValue(),getViewPosition().y));
((JPanel)super.getParent()).repaint();
}
}
public class applet8 extends JFrame
{
public applet8()
{
addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e){System.exit(0);}
}
);
}
public static void main(String args[]) {
Toolkit tool=Toolkit.getDefaultToolkit();
Dimension screen=tool.getScreenSize();
applet8 myform=new applet8();
myPanel my=new myPanel((JPanel)myform.getContentPane());
myView view=new myView();
view.setView(my);
JScrollBar ver=new JScrollBar();
JScrollBar hor=new JScrollBar();
hor.setOrientation(JScrollBar.HORIZONTAL);
ver.addAdjustmentListener(view);
hor.addAdjustmentListener(view);
ver.setName("a");
hor.setName("b");
myform.setSize(800,600);
myform.setLocation(myform.getToolkit().getScreenSize().width/2-myform.getWidth()/2,myform.getToolkit().getScreenSize().height/2-myform.getHeight()/2);
myform.getContentPane().add(view,"Center");
myform.getContentPane().add(ver,"East");
myform.getContentPane().add(hor,"South");
myform.show();
}
}