问题 填空题

1.Look!All the people are looking in the d       of the corner.What’s happening there?

2.How f       it is outside.You see,everything is covered with ice.

3.There was no a       for the police but to set the young man free,for they didn’t have enough

evidence although they were sure it was he who committed the murder.

4.Can you see the bottle f       on the river?There seems to be a piece of paper in it.

5.Terry can’t p       in the match because he has hurt his foot.

6.Mr.Green worked so hard that      (最后) he made himself ill.

7.After the air crash,few people on board       (幸存) at last,which brought sadness to many families.

8.Mother      (测量) me to see what size of dress I should have.

9.Study the facts again and maybe you’ll draw a different       (结论).

10.Anyone who wants to get       (更进一步的) information can get in touch with us at any time.

答案

1direction   2freezing   3alternative   4floating   5participate   e6ventually  7 survived   8measured  

9conclusion    10further

问答题
多项选择题

本题的功能是在文本域面板中添加一个带有行数的面板。窗口中有一个文本域,在文本域的左侧有一个带有数字的面板,该面板上的数字指示着文本域中的行数。
import javax.swing.*;
import javax.swing.event.*;
import java.awt.*;
public class java3 extends JFrame

public static JTextPane textPane;
public static JScrollPane scrollPane;
JPanel panel;
public java3()

super("java3()");
panel=new JPanel();
panel.setLayout(new BorderLayout());
panel.setBorder(BorderFactory.createEmptyBorder(20,20,20,20));
textPane=new JTextPane();
textPane.setFont(new Font("monospaced",Font.PLAIN,12));
scrollPane=new JScrollPane(textPane);
panel.add(scrollPane);
scrollPane.setPreferredsize(new Dimension(300,250));
setContentPane(panel);
setCloseOperation(JFrame.EXIT_ON_CLOSE);
LineNumber lineNumber=new LineNumber();
scrollPane.setRowHeaderView(lineNumber);

public static void main(String[]args)

java3 ttp=new java3();
ttp.pack();
ttp.setVisible(true);


class LineNumber extends JTextPane

private final static Color DEFAULT_BACKGROUND=Color.gray;
private final static Color DEFAULT_FOREGROUND=Color.black;
private final static Font DEFAULT_FONT=new Font("monospaced",Font.PLAIN,12);
private final static int HEIGHT=Integer.MAX_VALUE-1000000;
private final static int MARGIN=5;
private FontMetrics fontMetrics;
private int lineHeight;
private int currentRowWidth;
private JComponent component;
private int componentFontHeight;
private int componentFontAscent;
public LineNumber(JComponent component)

if(component==null)

setBackground(DEFAULT_BACKGROUND);
setForeground(DEFAULT_FOREGROUND);
setFont(DEFAULT_FONT);
this.component=this;

else

setBackground(DEFAULT_BACKGROUND);
setForeground(component.getForeground());
setFont(component.getFont());
this.component=component;

componentFontHeight=component.getFontMetrics(component.getFont()).getHeight();
componentFontAscent=component.getFontMetrics(component.getFont()).getAscent();
setPreferredWidth(9999);

public void setPreferredWidth(int row)

int width=fontMetrics.stringWidth(String.valueOf(row));
if(currentRowWidth<width)

currentRowWidth=width;
setPreferredSize(new Dimension(2*MARGIN+width,HEIGHT));


public void setFont(Font font)

super.setFont(font);
fontMetrics=getFontMetrics(getFont());

public int getLineHeight()

if(lineHeight==0)
return componentFontHeight;
else
return lineHeight;

public void setLineHeight(int lineHeight)

if(lineHeight>0)
this.lineHeight=lineHeight;

public int getStartOffset()

return component.getInsets().top+componentFontAscent;

public void paintComponent(Graphics g)

int lineHeight=getLinerteight();
int startOffset=getStartOffset();
Rectangle drawHere=g.getClipBounds();
g.setColor(getBackground());
g.fillRect(drawHere.x,drawHere.y,drawHere.width.drawHere.height);
g.setColor(getForeground());
int startLineNumber=(drawHere.y/lineHeight)+1;
int endLineNumber=startLineNumber+(drawHere.height/lineHeight);
int start=(drawHere.y/lineHeight)*lineHeight+startOffset;
for(int i=startLineNumber;i<=endLineNumber;i++)

String lineNumber=String.valueOf(i);
int width=fontMetrics.stringWidth(lineNumber);
g.drawstring(lineNumber,MARGIN+currentRowWidth-width,start);
start+=lineHeight;

setPreferredWidth(endLineNumber);