Public class getClass()
Public Object getSource()
Public Component getSource()
Public Component getTarget()
Public Component getComponent()
Public Component getTargetComponent()
第1题:
本题的功能是在文本域面板中添加一个带有行数的面板。窗口中有一个文本域,在文本域的左侧有一个带有数字的面板,该面板上的数字指示着文本域中的行数。
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.createEmptyBor-
der(20,20,20,20));
textPane=new JTextPane();
textPane.setFont(new Font("monospaeed",
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_BACK-
GROUND=Color.gray;
private final static Color DEFAULT_FORE-
GROUND=Color.black;
private final static Font DEFAUl。T—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);
setForegroun"DEFAULT_FOREGROUND);
setFont(DEFAULT FONT);
this.component=this;
}
else
{
setBaekground(DEFAULT_BACKGROUND);
setForeground(component.getForeground());
setFont(component.getFont());
this.component=component;
}
componentFontHeight=component.getFontMet-
rics(component.getFont()).getHeight();
componentFontAscent=component.getFontMet-
ries(component.getFont()).getAscent();
setPreferredWidth(9999);
}
public void setPreferredWidth(int row)
{
int width=fontMetrics.stringWidth(String.val-
ueOf(row));
if(currentRowWidth<;width)
{
currentRowWidth=width;
setPreferredSize(new Dfimension(2 * MARGIN
+width,HEIGHT));
}
}
public void setFont(Font font)
{
super.setFont(font);
fontMetrics=getFontMetrics(getFont());
}
public int getLineHeight()
{
if(hneHeight= =0)
return componentFontHeight;
else
return lineHeight;
}
public void setLineHeight(int lineHeight)
{
if(hneHeight>;0)
this.lineHeight=lineHeight;
}
public int getStartOffset()
{
return component.getlnsets().top+component-
FontAscent;
}
public void paintComponent(Graphics g)
{
int lineHeight=getLineHeight();
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/line-
Height)+1;
int endLineNUmber = startLineNumber+
(drawHere.height/lineHeight);
int start=(drawHere.Y/hneHeight)*line-
Height+startOffset;
for(int i=startLineNumber;i<;=endLineN-
umber;i++)
{
String lineNumber=String.valueOf(i);
int width=fontMetrics.stringWidth(lineNumber
);
g.drawstring(lineNumber,MARGIN+current-
RowWidth-width,start);
start+=lineHeight:
}
setPreferredWidth(endLineNumber);
}
}
第2题:
class super { public float getNum() {return 3.0f;} } public class Sub extends Super { } Which method, placed at line 6, will cause a compiler error?()
第3题:
Which two allow the class Thing to be instantiated using new Thing()?
第4题:
下列代码正确的是哪项?()
第5题:
public class Score implements Comparable
第6题:
Which two demonstrate an “is a” relationship?()
第7题:
Given an ActionEvent, which method allows you to identify the affected Component?()
第8题:
public interface Person { } public class Employee extends Person { }
public interface Shape { } public class Employee extends Shape { }
public interface Color { } public class Employee extends Color { }
public class Species { } public class Animal (private Species species;)
interface Component { } Class Container implements Component ( Private Component[ ] children; )
第9题:
void run()
public void run()
public void start()
void run(int priority)
public void run(int priority)
public void start(int priority)
第10题:
public class Session implements Runnable, Clonable{ public void run ();public Object clone () ; }
public class Session extends Runnable, Cloneable { public void run() {/*dosomething*/} public Object clone() {/*make a copy*/} }
public abstract class Session implements Runnable, Clonable { public void run() {/*do something*/} public Object clone() {/*make a copy*/} }
public class Session implements Runnable, implements Clonable { public void run() {/*do something*/} public Object clone() {/*make a copy*/} }
第11题:
public interface Person {} Public class Employee extends Person {}
public interface Shape {} public interface Rectangle extends Shape {}
public interface Color {} public class Shape { private Color color; }
public class Species {} public class Animal { private Species species; }
interface Component {} Class Container implements Component {private Component [] children;
第12题:
public class X { } public class Y extends X { }
public interface Shape { } public interface Rectangle extends Shape{ }
public interface Color { } public class Shape { private Color color; }
public interface Species { } public class Animal { private Species species; }
public class Person { } public class Employee { public Employee(Person person) { }
interface Component { } class Container implements Component { private Component[] children; }
第13题:
阅读下列函数说明和C++代码,将应填入(n)处的字句写在对应栏内。
[说明]
在销售系统中常常需要打印销售票据,有时需要在一般的票据基础上打印脚注。这样就需要动态地添加一些额外的职责。如下展示了Decorator(修饰)模式。SalesOrder对象使用一个SalesTicket对象打印销售票据,先打印销售票据内容,然后再打印脚注。图5-1显示了各个类间的关系。以下是C++语言实现,能够正确编译通过。
[图5-1]
[C++代码]
class Component{
public:
(1) void prtTicket()=0;
};
class SalesTicket:public Component{
public:
void prtTicket(){
cout<<"Sales Ticket!"<<endl;
}
};
class Decorator:public Component{
public:
virtual void prtTicket();
Decorator(Component *myC);
private:
(2) myComp;
};
Decorator::Decorator(Component *myC)
{
myComp=myC;
}
void Decorator::prtTicket()
{
myComp->prtTicket();
}
class Footer:public Decorator{
public:
Footer(Component *myC);
void prtTicket();
void prtFooter();
};
Footer::Footer(Component *myC): (3) {}
void Footer::prtFooter()
{
cout<<"Footer"<<endl;
}
void Footer::prtTicket()
{
(4) ;
prtFooter();
}
class SalesOrder{
public:
void prtTicket();
};
void SalesOrder::prtTicket()
{
Component *myST;
myST=new Footer( (5) );
myST->prtTicket();
}
(1)
第14题:
Which three demonstrate an “is a” relationship?()
第15题:
A JavaBeans component has the following field: 11. private boolean enabled; Which two pairs of method declarations follow the JavaBeans standard for accessing this field?()
第16题:
class One { public One foo() { return this; } } class Two extends One { public One foo() { return this; } } class Three extends Two { // insert method here } Which two methods, inserted individually, correctly complete the Three class?()
第17题:
Which the two demonstrate an “is a” relationship?()
第18题:
1. class super { 2. public float getNum() {return 3.0f;} 3. } 4. 5. public class Sub extends Super { 6. 7. } Which method, placed at line 6, will cause a compiler error?()
第19题:
Given the ActionEvent, which method allows you to identify the affected component?()
第20题:
GetClass.
GetTarget.
GetSource.
GetComponent.
GetTargetComponent.
第21题:
Public float getNum() {return 4.0f; }
Public void getNum (){}
Public void getNum (double d){}
Public double getNum (float d) {retrun 4.0f; }
第22题:
public void setEnabled( boolean enabled) public boolean getEnabled()
public void setEnabled( boolean enabled) public void isEnabled()
public void setEnabled( boolean enabled) public boolean isEnabled()
public boolean setEnabled( boolean enabled) public boolean getEnabled()
第23题:
public int compareTo(Object o) {/*mode code here*/}
public int compareTo(Score other) {/*more code here*/}
public int compare(Score s1,Score s2){/*more code here*/}
public int compare(Object o1,Object o2){/*more code here*/}
第24题:
Public class getClass()
Public Object getSource()
Public Component getSource()
Public Component getTarget()
Public Component getComponent()
Public Component getTargetComponent()