当前位置: 技术问答>java相关
我这么写为什么不行呀?
来源: 互联网 发布时间:2017-04-05
本文导语: ////////////////////////////////////////////以下是自定义控件 import com.ms.wfc.core.*; import com.ms.wfc.ui.*; /** * This class is a visual component. The entry point for class execution * is the constructor. */ public class CcMb extends UserContro...
////////////////////////////////////////////以下是自定义控件
import com.ms.wfc.core.*;
import com.ms.wfc.ui.*;
/**
* This class is a visual component. The entry point for class execution
* is the constructor.
*/
public class CcMb extends UserControl
{
public CcMb()
{
super();
// Required for Visual J++ Form Designer support
//
initForm();
// TODO: Add any constructor code after initForm call
}
/**
* NOTE: The following code is required by the Visual J++ form
* designer. It can be modified using the form editor. Do not
* modify it using the code editor.
*/
Container components = new Container();
Panel panel1 = new Panel();
Label label1 = new Label();
private void initForm()
{
this.setSize(new Point(300, 300));
this.setText("CcMb");
panel1.setBackColor(Color.ACTIVECAPTION);
panel1.setLocation(new Point(8, 8));
panel1.setSize(new Point(176, 280));
panel1.setTabIndex(0);
panel1.setText("panel1");
label1.setForeColor(Color.WINDOW);
label1.setLocation(new Point(32, 112));
label1.setSize(new Point(100, 12));
label1.setTabIndex(0);
label1.setTabStop(false);
label1.setText("label1");
label1.setAutoSize(true);
label1.setTextAlign(HorizontalAlignment.CENTER);
this.setNewControls(new Control[] {
panel1});
panel1.setNewControls(new Control[] {
label1});
}
public static class ClassInfo extends UserControl.ClassInfo
{
// TODO: Add your property and event infos here
}
}
///////////////////////////////////////以下应用
import java.awt.*;
import java.applet.*;
/**
* This class reads PARAM tags from its HTML host page and sets
* the color and label properties of the applet. Program execution
* begins with the init() method.
*/
public class Mb extends Applet
{
/**
* The entry point for the applet.
*/
public void init()
{
initForm();
usePageParams();
// TODO: Add any constructor code after initForm call.
}
private final String labelParam = "label";
private final String backgroundParam = "background";
private final String foregroundParam = "foreground";
/**
* Reads parameters from the applet's HTML host and sets applet
* properties.
*/
private void usePageParams()
{
final String defaultLabel = "Default label";
final String defaultBackground = "C0C0C0";
final String defaultForeground = "000000";
String labelValue;
String backgroundValue;
String foregroundValue;
/**
* Read the ,
* ,
* and tags from
* the applet's HTML host.
*/
labelValue = getParameter(labelParam);
backgroundValue = getParameter(backgroundParam);
foregroundValue = getParameter(foregroundParam);
if ((labelValue == null) || (backgroundValue == null) ||
(foregroundValue == null))
{
/**
* There was something wrong with the HTML host tags.
* Generate default values.
*/
labelValue = defaultLabel;
backgroundValue = defaultBackground;
foregroundValue = defaultForeground;
}
/**
* Set the applet's string label, background color, and
* foreground colors.
*/
label1.setText(labelValue);
label1.setBackground(stringToColor(backgroundValue));
label1.setForeground(stringToColor(foregroundValue));
this.setBackground(stringToColor(backgroundValue));
this.setForeground(stringToColor(foregroundValue));
}
/**
* Converts a string formatted as "rrggbb" to an awt.Color object
*/
private Color stringToColor(String paramValue)
{
int red;
int green;
int blue;
red = (Integer.decode("0x" + paramValue.substring(0,2))).intValue();
green = (Integer.decode("0x" + paramValue.substring(2,4))).intValue();
blue = (Integer.decode("0x" + paramValue.substring(4,6))).intValue();
return new Color(red,green,blue);
}
/**
* External interface used by design tools to show properties of an applet.
*/
public String[][] getParameterInfo()
{
String[][] info =
{
{ labelParam, "String", "Label string to be displayed" },
{ backgroundParam, "String", "Background color, format "rrggbb"" },
{ foregroundParam, "String", "Foreground color, format "rrggbb"" },
};
return info;
}
Label label1 = new Label();
CcMb ccmb1 = new CcMb();//这里定义
/**
* Intializes values for the applet and its components
*/
void initForm()
{
this.setBackground(Color.lightGray);
this.setForeground(Color.black);
label1.setText("label1");
this.setLayout(new BorderLayout());
this.add("North",label1);
this.add("South",ccmb1);//这里提示不行
}
}
那么自定义控件到底应该怎么弄呢?
import com.ms.wfc.core.*;
import com.ms.wfc.ui.*;
/**
* This class is a visual component. The entry point for class execution
* is the constructor.
*/
public class CcMb extends UserControl
{
public CcMb()
{
super();
// Required for Visual J++ Form Designer support
//
initForm();
// TODO: Add any constructor code after initForm call
}
/**
* NOTE: The following code is required by the Visual J++ form
* designer. It can be modified using the form editor. Do not
* modify it using the code editor.
*/
Container components = new Container();
Panel panel1 = new Panel();
Label label1 = new Label();
private void initForm()
{
this.setSize(new Point(300, 300));
this.setText("CcMb");
panel1.setBackColor(Color.ACTIVECAPTION);
panel1.setLocation(new Point(8, 8));
panel1.setSize(new Point(176, 280));
panel1.setTabIndex(0);
panel1.setText("panel1");
label1.setForeColor(Color.WINDOW);
label1.setLocation(new Point(32, 112));
label1.setSize(new Point(100, 12));
label1.setTabIndex(0);
label1.setTabStop(false);
label1.setText("label1");
label1.setAutoSize(true);
label1.setTextAlign(HorizontalAlignment.CENTER);
this.setNewControls(new Control[] {
panel1});
panel1.setNewControls(new Control[] {
label1});
}
public static class ClassInfo extends UserControl.ClassInfo
{
// TODO: Add your property and event infos here
}
}
///////////////////////////////////////以下应用
import java.awt.*;
import java.applet.*;
/**
* This class reads PARAM tags from its HTML host page and sets
* the color and label properties of the applet. Program execution
* begins with the init() method.
*/
public class Mb extends Applet
{
/**
* The entry point for the applet.
*/
public void init()
{
initForm();
usePageParams();
// TODO: Add any constructor code after initForm call.
}
private final String labelParam = "label";
private final String backgroundParam = "background";
private final String foregroundParam = "foreground";
/**
* Reads parameters from the applet's HTML host and sets applet
* properties.
*/
private void usePageParams()
{
final String defaultLabel = "Default label";
final String defaultBackground = "C0C0C0";
final String defaultForeground = "000000";
String labelValue;
String backgroundValue;
String foregroundValue;
/**
* Read the ,
* ,
* and tags from
* the applet's HTML host.
*/
labelValue = getParameter(labelParam);
backgroundValue = getParameter(backgroundParam);
foregroundValue = getParameter(foregroundParam);
if ((labelValue == null) || (backgroundValue == null) ||
(foregroundValue == null))
{
/**
* There was something wrong with the HTML host tags.
* Generate default values.
*/
labelValue = defaultLabel;
backgroundValue = defaultBackground;
foregroundValue = defaultForeground;
}
/**
* Set the applet's string label, background color, and
* foreground colors.
*/
label1.setText(labelValue);
label1.setBackground(stringToColor(backgroundValue));
label1.setForeground(stringToColor(foregroundValue));
this.setBackground(stringToColor(backgroundValue));
this.setForeground(stringToColor(foregroundValue));
}
/**
* Converts a string formatted as "rrggbb" to an awt.Color object
*/
private Color stringToColor(String paramValue)
{
int red;
int green;
int blue;
red = (Integer.decode("0x" + paramValue.substring(0,2))).intValue();
green = (Integer.decode("0x" + paramValue.substring(2,4))).intValue();
blue = (Integer.decode("0x" + paramValue.substring(4,6))).intValue();
return new Color(red,green,blue);
}
/**
* External interface used by design tools to show properties of an applet.
*/
public String[][] getParameterInfo()
{
String[][] info =
{
{ labelParam, "String", "Label string to be displayed" },
{ backgroundParam, "String", "Background color, format "rrggbb"" },
{ foregroundParam, "String", "Foreground color, format "rrggbb"" },
};
return info;
}
Label label1 = new Label();
CcMb ccmb1 = new CcMb();//这里定义
/**
* Intializes values for the applet and its components
*/
void initForm()
{
this.setBackground(Color.lightGray);
this.setForeground(Color.black);
label1.setText("label1");
this.setLayout(new BorderLayout());
this.add("North",label1);
this.add("South",ccmb1);//这里提示不行
}
}
那么自定义控件到底应该怎么弄呢?
|
visual j++?
|
UserControl??控制类可以这么加吗??
本站(WWW.)旨在分享和传播互联网科技相关的资讯和技术,将尽最大努力为读者提供更好的信息聚合和浏览方式。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。