填空题本题的功能是用文本框来设定表盘中指针的位置。窗口中有一个画板和两个文本框,画板中绘制了一个表盘和时针、分针,通过文本框分别设定“时”和“分”,表盘中的时针和分针就会指到对应的位置上。 import java. awt. * ; import java. awt. event. * ; import java. awt. geom. * ; import javax. swing. * ; import javax. swing, event. * ; public class java3 public static void main(String[] args) TextTestFrame frame=new TextTestFrame(); frame. setDefaultCloseOperation (JFrame. EXIT_ON_CLOSE); frame. show(); class TextTestFrame extends JFrame public TextTestFrame() setTitle("java3"); setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT); Container contentPane=getContentPane(); DocumentListener listener=new DocumentListen-er(); JPanel panel=new JPanel(); hourField=new JTextField("12",3); panel, add(hourField); hourField, getDocument (). addDocumentListener(this); minuteField=new JTextField("00",3); panel, add(minuteField); minuteField, getDocument(), addDocumentListener(listener); contentPane, add ( panel, BorderLayout. SOUTH); clock=new ClockPanel(); contentPane, add (clock, BorderLayout. CENTER); public void setClock() try int hours = Integer. parseInt (hourField. getText(). trim()); int minutes = Integer. parselnt(minuteField, getText(), trim()); clock, setTime(hours, minutes); catch (NumberFormatException e) public static final int DEFAULT WIDTH=300; public static final int DEFAULT_HEIGHT=300; private JTextField hourField; private JTextField minuteField; private ClockPanel clock; private class clockFieldListener extends DocumentListener public void insertUpdate(DocumentEvent e) setClock(); public void removeUpdate(DocumentEvent e) setClock(); public void changedUpdate(DocumentEvent e) class ClockPanel extends JPanel public void paintComponent(Graphics g) super, paintComponent(g); Graphics2D g2=(Graphics2D)g; Ellipse2D circle =new Ellipse2D. Double(0,0,2 * RADIUS, 2 * RADIUS); g2. draw(circle); double hourAngle =Math. toRadians(90-360 * minutes/(12 * 60)); drawHand (g2, hourAngle, HOUR_HAND_LENGTH); double minuteAngle Math. toRadians(90-360 * minutes/60) drawHand(g2, minuteAngle, MINUTE_HAND_LENGTH); public void drawHand(Graphics2D g2, double angle, double handLength) Point2D end=new Point2D. Double( RADIUS+handLength * Math. cos(angle), RADIUS-handLength * Math. sin(angle)); Point2D center=new Point2D. Double(RADIUS, RADIUS) g2. draw(new Line2D. Double(center, end)); public void setTime(int h, int m) minutes=h*60+m; repaint(); private double minutes=0; private double RADIUS=100; private double MINUTE_HAND_LENGTH=0.8 * RADIUS; private double HOUR_HAND_LENGTH=0.6 * RADIUS;
填空题本题的功能是在文本域面板中添加一个带有行数的面板。窗口中有一个文本域,在文本域的左侧有一个带有数字的面板,该面板上的数字指示着文本域中的行数。 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_BACKGROUN=Color. gray; private final static Color DEFAULT_FOREGROUND=Color. black; private final static Font DEFAULTFONT=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 IineHeight; private int eurrentRowWidth; private JComponent component ; private int componentFontHeight; private int eomponentFontAscent; public LineNumber(JComponent component) if(component==null) setBackground(DEFAULT_BACKGROUND); setForeground(DEFAULTFOREGROUND); setFont(DEFAULT_FONT); this. componen =this; else setBackground(DEFAULT_BACKGROUND); setForeground(component, getForeground()); setFont(component, getFont()); this. component=component; componentFontHeight=component, getFontMettics(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 IineHeight; 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=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/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);
填空题Java的简单性首先体现在自身系统的精炼上,它的基本解释程序和 【6】 占内存 40 KB,附加的基本标准类库和支持线程程序占175 KB。
填空题Java源文件经过编译后生成的文件的后缀是{{U}} 【15】 {{/U}}。
填空题已知int a[11]={12,18,24,35,47,50,62,83,90,115,134};使用对分查找法查找值为90的元素时,查找成功所进行的比较次数是{{U}} 【4】 {{/U}}。
填空题
【8】true解析:这个题没有太大的难度,首先看出是个赋值表达式,而表达式的值是一个布尔型的,比较5和6是否不相等,当然不等,返回true。
填空题软件测试的常用方法通常可分为白盒测试和{{U}} 【5】 {{/U}}。前者是根据程序的内部逻辑来设计测试用例,后者是根据软件的规格说明宋设计测试用例。
填空题catch子句都带一个参数,该参数是某个异常的类及其变量名(该异常对象的指针),catch用该参数去与抛出异常对象的类进行{{U}} 【8】 {{/U}}。
填空题以下程序运行后输出的结果是______。 main() int x=0210; printf("%o/n",x);
填空题软件定义时期主要包括{{U}} 【4】 {{/U}}和需求分析两个阶段。
填空题实体之间的联系可以归结为一对一的联系、一对多的联系与多对多的联系。如果一个学校有许多学生,而一个学生只归属于一个学校,则实体集学校与实体集学生之间的联系属于{{U}} 【5】 {{/U}}的联系。
填空题使用一个过滤流要求首先把过滤流连接到某个I/O流上,再通过______的参数去指定连接的I/O流。
填空题break语句最常见的用法是在switch语句中,通过break语句退出switch语句,使程序从整个switch语句后面的{{U}} 【7】 {{/U}}开始执行。
填空题数据型包括简单数据类型和复合数据类型。简单数据类型又包括数值类型、______、布尔类型三大类。
填空题Java中,新建的线程调用start()方法,如mythread.start(),将线程的状态从New转换为 【13】 。
填空题下面ButtonFrame类创建了一个容器,包含有3个按键。
import javax.swing.*;
public class ButtonFrame extends JFrame
{
JButton Button1= new JButton("Button1");
JButton Button2= new JButton("Button2");
JButton Button3= new JButton("Button3");
public ButtonFrame()
{
super("ButtonFrame");
setSize (100,150);
setDefaultCloseOperation(JFrame. EXIT ON CLOSE);
JPanel pane = new JPanel();
pane.add(Buttonl);
pane. add(Button2);
pane. add (Button3);
{{U}} 【12】 {{/U}};
}
public static void main(String args[])
{
ButtonFrame bf= new ButtonFrame();
bf. show(};
}
}
请在程序代码中的画线处添上正确的语句,使程序完整。
填空题软件设计模块化的目的是工 【3】 。
填空题对n条记录的文件进行快速排序,最坏情况下的执行时间为______。
填空题Java中的对象锁是一种独占的{{U}} 【12】 {{/U}}锁。
填空题关系模型的数据操纵即是建立在关系上的数据操纵,一般有 【2】 增加、删除和修改四种操作。
