图形截取代码




图形截取代码
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
import java.net.*;
import javax.swing.text.html.StyleSheet;
//Note : the extension is used for the
//String to Color conversion remove this reference
//and the functions it depends on,to create an applet
//that runs on older browsers without Java 1.2 installed.


/**
*@author 让痛苦痛苦
*@ 说明: ImageDisplay这个applet非常简单:完成初试化后,立即在applet标记内搜索参数,然后加载图片
* (图片必需与applet存放在同一服务器上),将其显示在一个图形窗筐中,最后在图形窗格上显示相关的文字。
*下面就是代码
*
*/
public class ImageDisplay extends Applet{

Image myImg;
MediaTracker mt;
String strDisplayOverlay="Copyright 2008 Todd Cook";
int iOverlayXPosition =20;
int iOverlayYPosition =20;
int iFontSize=14;
Color cOverlayColor =Color.white;
/**
*Construct the applet
*/

public ImageDisplay()
{

}

/***
*Initialize the applet
*
*
*/

public void init()
{
try {
jbInit();

}
catch (Exception ex) {
System.out.println (ex.getMessage());
ex.printStackTrace();
}
}
/**
*Componen initialization
*/


private void jbInit() throws Exception
{
mt=new MediaTracker(this);
//The applet viewers on some IDEs merely take
//the raw class file ,instead of loading the
//HTML file for parameters,hence the coding
//style of testing for nulls ,or otherwise
//assiging default values.
//Also one may use the applet viewer
//in the JDK ,e.g. on Windows

if(getParameter("DisplayImage")!=null)
{
myImg =getImage(getDocumentBase(),getParameter("DisplayImage"));
}
else
{
myImg =getImage(getDocumentBase(),"11.jpg");

}

if(getParameter("DisplayOverlay")!=null)
{
strDisplayOverlay=getParameter("DisplayOverlay");
}

if(getParameter("OverlayXPosition")!=null)
{
iOverlayXPosition =Integer.parseInt(getParameter("OverlayXPosition"));
}

if(getParameter("OverlayYPosition")!=null)
{
iOverlayYPosition=Integer.parseInt(getParameter("OverlayYPosition"));
}

if(getParameter("FontSize")!=null)
{
iFontSize=Integer.parseInt(getParameter("FontSize"));
}

if(getParameter("OverlayColor")!=null)
{
StyleSheet s=new StyleSheet();
cOverlayColor =s.stringToColor(getParameter("OverlayColor"));
}
mt.addImage(myImg,1);

try {
mt.waitForAll();
//stos program execution
//until the image(s) are loaded
}
catch (Exception ex) {
ex.printStackTrace();
}
}
public void caint(Graphics g)
{
g.drawImage(myImg,0,0,this);
g.setColor(cOverlayColor);
g.setFont(new Font("Arial",Font.PLAIN,iFontSize));
g.drawString(strDisplayOverlay,iOverlayXPosition,iOverlayYPosition);
}
/**
*Get Applet information
*
*/

public String getAppletInfo()
{
return "Display a simple banner display over an image";

}

/**
*Get parameter info
*/

public String[][] getParameterInfo()
{
return null;
}

/***
*
*Main method
*/
public static void main(String args[])
{
ImageDisplay applet=new ImageDisplay();
Frame frame;
frame=new Frame()
{
protected void processWindowEvent(WindowEvent e)
{
super.processWindowEvent(e);

if(e.getID()==WindowEvent.WINDOW_CLOSING)
{
System.exit(0);
}
}
public synchronized void setTitle(String title)
{
super.setTitle(title);
enableEvents(AWTEvent.WINDOW_EVENT_MASK);
}
};
frame.setTitle("Applet Frame");
frame.add(applet,BorderLayout.CENTER);
applet.init();
applet.start();
frame.setSize(800,600);
Dimension d=Toolkit.getDefaultToolkit().getScreenSize();
frame.setLocation((d.width-frame.getSize().width)/2,(d.height-frame.getSize().height)/2);
frame.setVisible(true);
}
}


评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值