📄 combox.html
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN"><!--NewPage--><html><head><!-- Generated by javadoc on Tue Nov 03 15:31:36 EST 1998 --><title> Class ComBox</title></head><body><a name="_top_"></a><h1> Class ComBox</h1><pre>java.lang.Object | +----ComBox</pre><hr><dl> <dt> public class <b>ComBox</b> <dt> extends Object <dt> implements <a href="DrawingObj.html#_top_">DrawingObj</a></dl>This class composes a commentary box to be drawn on any drawing panel/canvas. The width of the commentary box will be determined by the length of the text string being displayed. <p> Since this object implements <CODE>DrawingObj</CODE>, it can be added into the <CODE>DrawingPanel</CODE> by using either the <code>addCom</code> or <code>addDrawingObj</code> method. An added commentary box can be removed by calling the <code>removeCom</code> or <code>removeObj</code> method of the <code>DrawingPanel</code> class. <p> If the <code>addCom</code> method is called, the added commentary box is guaranteed to be displayed on top of all drawing objects added to the panel using <code>addDrawingObj</code>. Otherwise, if the commentary box is added to the panel using <code>addDrawingObj</code>, the last added object will be on top. <p> Typically, a commentary box can be initialized and added to a drawing panel and displayed by using the following statements: <code> <pre> ComBox com = new ComBox(x, y, "Example Comment", font); drawingPanel.addCom(com); drawingPanel.redraw(); </pre> </code> It is removed from the drawing panel by: <code> <pre> drawingPanel.removeCom(com); </pre> </code> where <code>drawingPanel</code> is an instance of the class object <code>DrawingPanel</code>, <code>x</code> and <code>y</code> define the top left position of the commentary box and <code>font</code> is an instance of the <code>Font</code> object, typically a fixed font, which is declared as follows: <code><pre> Font font = new Font("Courier", Font.PLAIN, 12); </pre></code> <B>Note</B> that the size-12 courier font is recommended for all situation since the width of the com box is calculated based on this particular size font. Otherwise, the dimension has to be modified.<p><dl> <dt> <b>See Also:</b> <dd> <a href="DrawingPanel.html#_top_">DrawingPanel</a>, <a href="DrawingPanel.html#addCom">addCom</a>, <a href="DrawingPanel.html#addDrawingObj">addDrawingObj</a>, <a href="DrawingPanel.html#redraw">redraw</a></dl><hr><a name="index"></a><h2> <img src="images/constructor-index.gif" width=275 height=38 alt="Constructor Index"></h2><dl> <dt> <img src="images/yellow-ball-small.gif" width=6 height=6 alt=" o "> <a href="#ComBox(int, int, java.lang.String, java.awt.Color, java.awt.Color, java.awt.Font)"><b>ComBox</b></a>(int, int, String, Color, Color, Font) <dd> Creates a commentary box with its topleft corner at (topLeftX, topLeftY) and the commentary text specified by the third <code>String</code> parameter, using the foreground and background colors indicated by the fourth and fifth parameters. <dt> <img src="images/yellow-ball-small.gif" width=6 height=6 alt=" o "> <a href="#ComBox(int, int, java.lang.String, java.awt.Font)"><b>ComBox</b></a>(int, int, String, Font) <dd> Creates a commentary box with its topleft corner at (topLeftX, topLeftY) and the commentary text specified by the third <code>String</code> parameter.</dl><h2> <img src="images/method-index.gif" width=207 height=38 alt="Method Index"></h2><dl> <dt> <img src="images/red-ball-small.gif" width=6 height=6 alt=" o "> <a href="#draw(java.awt.Graphics)"><b>draw</b></a>(Graphics) <dd> This method is to be called from the <code>paint(Graphics g)</code> method of the drawing panel/canvas. <dt> <img src="images/red-ball-small.gif" width=6 height=6 alt=" o "> <a href="#getText()"><b>getText</b></a>() <dd> This method is called to obtain the current text string to be displayed in the commentary box. <dt> <img src="images/red-ball-small.gif" width=6 height=6 alt=" o "> <a href="#getX()"><b>getX</b></a>() <dd> X coordinate of the top left position of the commentary box. <dt> <img src="images/red-ball-small.gif" width=6 height=6 alt=" o "> <a href="#getY()"><b>getY</b></a>() <dd> Y coordinate of the top left position of the commentary box. <dt> <img src="images/red-ball-small.gif" width=6 height=6 alt=" o "> <a href="#move(int, int)"><b>move</b></a>(int, int) <dd> Move the top left position of the commentary box. <dt> <img src="images/red-ball-small.gif" width=6 height=6 alt=" o "> <a href="#setBackground(java.awt.Color)"><b>setBackground</b></a>(Color) <dd> Set the background color of the commentary box. <dt> <img src="images/red-ball-small.gif" width=6 height=6 alt=" o "> <a href="#setColor(java.awt.Color)"><b>setColor</b></a>(Color) <dd> Set the text color of the commentary box. <dt> <img src="images/red-ball-small.gif" width=6 height=6 alt=" o "> <a href="#setText(java.lang.String)"><b>setText</b></a>(String) <dd> Set the text string to be displayed on the commentary box. <dt> <img src="images/red-ball-small.gif" width=6 height=6 alt=" o "> <a href="#setTopLeft(int, int)"><b>setTopLeft</b></a>(int, int) <dd> Set the top left position of the commentary box.</dl><a name="constructors"></a><h2> <img src="images/constructors.gif" width=231 height=38 alt="Constructors"></h2><a name="ComBox"></a><a name="ComBox(int, int, java.lang.String, java.awt.Font)"><img src="images/yellow-ball.gif" width=12 height=12 alt=" o "></a><b>ComBox</b><pre> public ComBox(int topLeftX, int topLeftY, String str, Font font)</pre><dl> <dd> Creates a commentary box with its topleft corner at (topLeftX, topLeftY) and the commentary text specified by the third <code>String</code> parameter. By default, the background color is yellow and the text is displayed in blue.<p> <dd><dl> <dt> <b>Parameters:</b> <dd> topLeftX - Integer value specifying the horizontal position of the topleft corner of the commentary box. <dd> topLeftY - Integer value specifying the vertical position of the topleft corner of the commentary box. <dd> str - The text string to be displayed on the commentary box. </dl></dd></dl><a name="ComBox(int, int, java.lang.String, java.awt.Color, java.awt.Color, java.awt.Font)"><img src="images/yellow-ball.gif" width=12 height=12 alt=" o "></a><b>ComBox</b><pre> public ComBox(int topLeftX, int topLeftY, String str, Color fg, Color bg, Font font)</pre><dl> <dd> Creates a commentary box with its topleft corner at (topLeftX, topLeftY) and the commentary text specified by the third <code>String</code> parameter, using the foreground and background colors indicated by the fourth and fifth parameters.<p> <dd><dl> <dt> <b>Parameters:</b> <dd> topLeftX - Integer value specifying the horizontal position of the topleft corner of the commentary box. <dd> topLeftY - Integer value specifying the vertical position of the topleft corner of the commentary box. <dd> str - The text string to be displayed on the commentary box. <dd> fg - Color of the text in the commentary box. <dd> bg - Color of the commentary box background. </dl></dd></dl><a name="methods"></a><h2> <img src="images/methods.gif" width=151 height=38 alt="Methods"></h2><a name="setText(java.lang.String)"><img src="images/red-ball.gif" width=12 height=12 alt=" o "></a><a name="setText"><b>setText</b></a><pre> public void setText(String str)</pre><dl> <dd> Set the text string to be displayed on the commentary box.<p> <dd><dl> <dt> <b>Parameters:</b> <dd> str - Text string in the form of class String </dl></dd></dl><a name="setTopLeft(int, int)"><img src="images/red-ball.gif" width=12 height=12 alt=" o "></a><a name="setTopLeft"><b>setTopLeft</b></a><pre> public void setTopLeft(int topLeftX, int topLeftY)</pre><dl> <dd> Set the top left position of the commentary box.<p> <dd><dl> <dt> <b>Parameters:</b> <dd> topLeftX - Horizontal position of the top left corner. <dd> topLeftY - Vertical position of the top left corner. </dl></dd></dl><a name="setBackground(java.awt.Color)"><img src="images/red-ball.gif" width=12 height=12 alt=" o "></a><a name="setBackground"><b>setBackground</b></a><pre> public void setBackground(Color col)</pre><dl> <dd> Set the background color of the commentary box. The background color of commentary box is specified by <code> java.awt.Color</code>.<p> <dd><dl> <dt> <b>Parameters:</b> <dd> col - Background color, instance of java.awt.color <dt> <b>See Also:</b> <dd> Color </dl></dd></dl><a name="setColor(java.awt.Color)"><img src="images/red-ball.gif" width=12 height=12 alt=" o "></a><a name="setColor"><b>setColor</b></a><pre> public void setColor(Color col)</pre><dl> <dd> Set the text color of the commentary box. This foreground color (text color) is specified by <code> java.awt.Color</code>.<p> <dd><dl> <dt> <b>Parameters:</b> <dd> col - Foreground color, instance of java.awt.color <dt> <b>See Also:</b> <dd> Color </dl></dd></dl><a name="draw(java.awt.Graphics)"><img src="images/red-ball.gif" width=12 height=12 alt=" o "></a><a name="draw"><b>draw</b></a><pre> public void draw(Graphics g)</pre><dl> <dd> This method is to be called from the <code>paint(Graphics g)</code> method of the drawing panel/canvas. It uses the graphical context of the drawing panel/canvas to construct the commentary box on the drawing panel/canvas.<p> <dd><dl> <dt> <b>Parameters:</b> <dd> g - Graphical context from the <code>paint(Graphics g)</code> method of the drawing panel/canvas. <dt> <b>See Also:</b> <dd> Graphics </dl></dd></dl><a name="move(int, int)"><img src="images/red-ball.gif" width=12 height=12 alt=" o "></a><a name="move"><b>move</b></a><pre> public void move(int x, int y)</pre><dl> <dd> Move the top left position of the commentary box.<p> <dd><dl> <dt> <b>Parameters:</b> <dd> x - Horizontal position of the top left corner. <dd> y - Vertical position of the top left corner. <dt> <b>See Also:</b> <dd> setTopLeft </dl></dd></dl><a name="getX()"><img src="images/red-ball.gif" width=12 height=12 alt=" o "></a><a name="getX"><b>getX</b></a><pre> public int getX()</pre><dl> <dd> X coordinate of the top left position of the commentary box.<p> <dd><dl> <dt> <b>Returns:</b> <dd> The X coordinate of the top left corner of the commentary box. </dl></dd></dl><a name="getY()"><img src="images/red-ball.gif" width=12 height=12 alt=" o "></a><a name="getY"><b>getY</b></a><pre> public int getY()</pre><dl> <dd> Y coordinate of the top left position of the commentary box.<p> <dd><dl> <dt> <b>Returns:</b> <dd> The Y coordinate of the top left corner of the commentary box. </dl></dd></dl><a name="getText()"><img src="images/red-ball.gif" width=12 height=12 alt=" o "></a><a name="getText"><b>getText</b></a><pre> public String getText()</pre><dl> <dd> This method is called to obtain the current text string to be displayed in the commentary box.<p> <dd><dl> <dt> <b>Returns:</b> <dd> The text string to be displayed on the commentary box. </dl></dd></dl></body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -