package frogbean;
import java
import java
import java
import java
/**
* 在此處插入類型說明
* 創建日期
* @author
*/
public class BangBean extends Canvas implements Serializable {
protected int xm
protected int cSize=
protected String text=
protected int fontSize=
protected Color tColor=Color
protected ActionListener actionListener;
class ML extends MouseAdapter{
public void mousePressed(MouseEvent e){
Graphics g=getGraphics();
g
g
int width=g
g
g
//Call the listener
if(actionListener!=null)
actionListener
}
}
class MML extends MouseMotionAdapter{
public void mouseMoved(MouseEvent e){
xm=e
ym=e
repaint();
}
}
/**
* BangBean 構造子注解
*/
public BangBean() {
addMouseListener(new ML());
addMouseMotionListener(new MML());
}
public void addActionListener(ActionListener l) throws TooManyListenersException {
if(actionListener!=null)
throw new TooManyListenersException();
actionListener=l;
}
public String getBeanText(){return text;}
public int getCircleSize(){return cSize;}
public int getFontSize(){return fontSize;}
public Dimension getPreferredSize(){
return new Dimension(
}
public Color getTextColor(){return tColor;}
//Testing the BangBean:
public static void main(String[] args){
BangBean bb=new BangBean();
try{
//During testing
bb
new ActionListener(){
public void actionPerformed(ActionEvent e){
System
}
}
);
}catch(TooManyListenersException e){}
Frame f=new Frame(
f
new WindowAdapter(){
public void windowClosing(WindowEvent e){
System
}
}
);
f
f
f
}
public void paint(Graphics g){
g
g
}
public void removeActionListener(ActionListener l){
actionListener=null;
}
public void setBeanText(String newText){text=newText;}
public void setCircleSize(int newSize){cSize=newSize;}
public void setFontSize(int newSize){fontSize=newSize;}
public void setTextColor(Color newColor){tColor=newColor;}
}
以上是bean類
下面用Ibm visual Age for Java 自動生成調試代碼
package frogbean;
import java
import java
/**
* 在此處插入類型說明
* 創建日期
* @author
*/
public class TestBean extends Applet {
private BangBean ivjfirst = null;
/**
* 返回關於此 applet 的信息
* @return 返回關於此 applet 信息的字符串
*/
public String getAppletInfo() {
return
}
/**
* 返回 first 特性值
* @return frogbean
*/
/* 警告
private BangBean getfirst() {
if (ivjfirst == null) {
try {
ivjfirst = new frogbean
ivjfirst
ivjfirst
// user code begin {
// user code end
} catch (java
// user code begin {
// user code end
handleException(ivjExc);
}
}
return ivjfirst;
}
/**
* 每當部件拋出異常時被調用
* @param exception java
*/
private void handleException(java
/* 除去下列各行的注釋
// System
// exception
}
/**
* 初始化 applet
*
* @see #start
* @see #stop
* @see #destroy
*/
public void init() {
try {
super
setName(
setLayout(null);
setSize(
add(getfirst()
// user code begin {
// user code end
} catch (java
// user code begin {
// user code end
handleException(ivjExc);
}
}
/**
* 主入口點
* @param args java
*/
public static void main(java
try {
Frame frame = new java
TestBean aTestBean;
Class iiCls = Class
ClassLoader iiClsLoader = iiCls
aTestBean = (TestBean)java
frame
frame
frame
public void windowClosing(java
System
};
});
frame
} catch (Throwable exception) {
System
exception
}
}
/**
* 繪制 applet
* 如果此 applet 不需要繪制(例如
* awt 部件的一個容器)
*
* @param g 指定的
* @see #update
*/
public void paint(Graphics g) {
super
//在此處插入用來繪制 applet 的代碼
}
}
其中
TestBean aTestBean;
Class iiCls = Class
ClassLoader iiClsLoader = iiCls
aTestBean = (TestBean)java
是做什麼用的?為什麼不直接用
TestBean aTestBean=new TestBean() ?
From:http://tw.wingwit.com/Article/program/Java/hx/201311/25856.html