本题是设计一个窗体,窗口的背景色为系统桌面的颜色,在窗口中分别画了空心和实心的黑色矩形、深灰色圆角矩形和浅灰色椭圆形,并且画了白色粗体的“Java二级考试!”字符串。
Import java.awt.*;
Import javax.swing.*;
Public class java2
{
Public static void main(string[]args)
{
Fillframe. frame=new fillframe;
Frame. setdefaultcloseoperatio (jframe. exit_on_
close);
Frame.show;
}
}
Class fillframe. extends jframe
{
Public fillframe
{
Settitle("simple");
Setsize(width,height);
Fillpanel panel=new fillpanel;
Panel.setbackground(systemcolor.desktop);
Container contentpane=getcontentpane;
Contentpane.add(panel);
}
Public static final int width=400;
Public static final int width=250;
}
Class fillpanel extends jpanel
{
Public void paintcomponent(graphics g)
{
;
g.setcolor(new color(10,10,10));’
g.drawrect(10,10,100,30);
g.seteolor(new color(100,100,l00));
g.drawroundrect(150,10,100,30,15,15);
g.setcolor(new color(150,150,150));
g.drawoval(280,10,80,30);
g.setcolor(new color(10,10,10));
g.fillreet(10,110,100,30);
g.setcolor(new color(100,100,100));
g.drawroundreet(150,110,100,30,15,15);
g.seteolor(new color(150,150,150));
g.filloval(280,110,80,30);
g.setcolor(color.white);
font f=new font("宋体",_ _,20);
g.setfont(f);
g.drawstring("java二级考试!",l50,200);
}
}
本题的功能是跟踪鼠标在窗口的操作,以及在窗口的坐标,包括移进、移出、移动、单击、释放和拖曳,并将这些信息显示在窗口的文字标签上。
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class java3extends JFrame. implements MouseL-
istener MouseMotionListener
{
private JLabel statusBar;
public java3
{
super("java3");
statllsBar=new TLabel;
getContentPane.add(statusBar,BorderLayout.
SOUTH);
addMouseListener(this);
addMouseMotionListener(this);
setSize(275,100);
show;
}
public void mouseClicked(MouseEvent e)
{
statusBar.setText("Clicked at["+e.getX+
","+e.getY+"]");
}
public void mousePressed(MouseEvent e)
{
statusBar.setText("Pressed at["+e.getX+
","+e.getY+"]");
}
public void mouseReleased(MouseEvent e)
{
statusBar.setText("Released at["+e.getX
+","+e.getY+"]");
}
public void mouseln(MouseEvent e)
{
statusBar.setText("Mouse in window");
public void mouseExited(MouseEvent e)
{
statusBar.setText("Mouse outside window");
}
public void mouseDragged(MouseEvent e)
{
statusBar.setText("Dragged at["+e.getX
+","+e.getY+"]");
}
public void mouseMoved(MouseEvent e)
{
statusBar.setText("Moved at["+e.getX+
","+e.getY+"]");
}
public static void main(String args[])
{
java3 app=new java3;
app.addWindowListener(new WindowAdapter
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
};
本题中定义了一个带有参数的构造方法javal,并定义了一个该类的对象temp。构造方法javal有两个参数:字符串name和整型age。定义对象temp时将字符串“Tom"和整数17传递给构造方法,构造方法将这两个参数打印输出。
public class javal{
String name;
int age;
public static void main(String[]args){
String name="Tom";
int age=17;
javal temp = ;
}
public javal(String name, ){
;
this.age= age;
System.out.println(name+"is"+age+"
years old.");
}
}
类Panel默认的布局管理器是( )。
下列有关Java语言的叙述中,正确的是( )。
已知zipname是一个压缩文件名。则zipname在下列代码中出现的正确位置是( )。
ZipInputStream zin=
new ZipInputStzeam(new FileInputStream(①));
ZipEntry entry ;
while((entry=zin.getNextEntry(②))!=null){
fileCombo.addltem(entry.getNamc(③));
zin.closeEntry(④);
}
zin.close;
执行下列程序之后,变量n的值为( )。
public class Exam{
public static void main(String[]args){
int y=2;
int z=3:
int n=4:
n=n+-y*z/n;
System.out.println(n);
}
}
在下列程序的空白处,应填入的正确选项是( )。
Import java.io.*;
Pulilc class ObjectStreamTest{
Publilc static void main(string args[])throws IOEx-
ception{
OhiectOutputStream os=new OhjectOutputStream
(new FileOutputStream("serial.bin"));
Java.util.Date d=new Java.util.Date;
Oos (d);
ObjectInputStream is=
new OhjectlnputStream(new FileOutputStream("serial.
bin"));
try{
java.util.date restoredDate=
(Java.util.Date)ois.readObject;
System.out.println
("read object back from serial.bin file:"
+restoredDate);
}
Catch(ClassNotFoundException cnf){
System.out.println("class not found");
}
}
下列关于线程优先级的说法中,正确的是( )。
数据结构中,与所使用的计算机无关的是数据的( )。
2017年全国计算机等级《二级VF》
2017年计算机二级考试VF模拟试题
2017年计算机二级考试VF模拟试题
2017年计算机二级考试VF模拟试题
2017年全国计算机二级考试题库1(
2017年全国计算机二级考试题库2(
2017年全国计算机二级考试题库3(
2016年全国计算机等级考试《二级V
2016年全国计算机等级考试《二级V
2016年全国计算机等级考试《二级V