重要提示: 请勿将账号共享给其他人使用,违者账号将被封禁!
查看《购买须知》>>>
找答案首页 > 全部分类 > 计算机类考试
搜题
网友您好, 请在下方输入框内输入要搜索的题目:
搜题
题目内容 (请给出正确答案)
[主观题]

请完成下列Java程序。程序的功能是显示用户在命令行方式下指定的任意驱动器目录的内容。 (提示:pub

请完成下列Java程序。程序的功能是显示用户在命令行方式下指定的任意驱动器目录的内容。

请完成下列Java程序。程序的功能是显示用户在命令行方式下指定的任意驱动器目录的内容。 (提示:pu

(提示:public String[]list();//将目录中所有文件名保存在字符数组中返回)

注意:请勿改动main()主方法和其他已有的语句内容,仅在下划线处填入适当的语句。

import java.io.*;

public class FindDirectories

{

public static void main(String args[]

{

if(args.length==0)

args=new String[]{".."};

try

{

_______________

String[] fileName=pathName.list();

for(int i=0;i<fileName.length;i++

{

File f=new File(pathName.getPath() fileName[i]);

if(___________________)

{

System.out.println(f.getCanonicalPath());

main(new String[]

{

f.getPath()

});

}

}

}

catch(IOException e)

{

e.printStackTrace();

}

}

}

查看答案
更多“请完成下列Java程序。程序的功能是显示用户在命令行方式下指定的任意驱动器目录的内容。 (提示:pub”相关的问题

第1题

AWT中的布局管理器包括BorderLayout、【】、CardLayout、OridBagLayout和GridLayout。

AWT中的布局管理器包括BorderLayout、【 】、CardLayout、OridBagLayout和GridLayout。

点击查看答案

第2题

代码System.out.println(066)的输出结果是______。动测试,其主要方法有逻辑覆盖、基本路径测试等。

点击查看答案

第3题

在Java中,字符是以16位的______码表示。

点击查看答案

第4题

本程序的目的是在屏幕上显示当前目录下的文件信息。文件信息通过表格JTable的实例显示。请更正题中

带下划线的部分,使程序能输出正确的结果。

注意:不改变程序的结构,不得增行或删行。

import java.awt.*;

import javax.swing.*;

import java.util.Date;

import javax.swing.table.*;

import java.applet.*;

import java.io.*;

public class advance extends JApplet, JFrame

{

public void init()

{

FileModel fm=new FileModel();

JTable jt=new JTable();

jt.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);

jt.setColumnSelectionAllowed(true);

JScrollPane jsp=new JScrollPane(jt);

getContentPane().add(jsp, BorderLayout.CENTER);

}

public static void main(String args[])

{

advance ft=new advance();

ft.init();

JFrame. f=new JFrame();

f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

f.getContentPane().add(ft.getContentPane());

f.setSize(300,400);

f.show();

}

}

class FileModel extends AbstractTableModel

{

String[] columnName=new String[] {

"文件名","大小","最后修改时间"

};

Object[][] data;

public FileModel() {this(".");}

public FileModel(String dir)

{

File file=new File(dir);

String files[]=file.list();

data=new Object[files.length] [columnName.length];

for(int i=0; i<files.length; i++)

{

File tmp=new File(files[i]);

data[i] [0]=tmp.getName();

data[i] [1]=new Long(tmp.length());

data[i] [2]=new Date(tmp.lastModified());

}

}

public int getColumnNumber()

{

return columnName.length;

}

public int getRowCount()

{

return data.length;

}

public String getColumnName(int col)

{

return columnName[col];

}

public Object getValueAt(int row, int col)

{

return data[row] [col];

}

public Class getColumnClass(int c)

{

return getValueAt(0,c).getClass();

}

}

点击查看答案

第5题

本程序的功能是读取用户输入的整数a、b,单击按钮“计算”,则计算出a和b数的和,并显示计算的结果。请

将程序补充完整。

注意:请勿修改main()主方法和其他已有语句内容,仅在横线处填入适当语句。

import java.awt.*;

import java.awt.event.*;

import javax.swing.*;

public class simple

{

public static void main{String[] args)

{

ExampleFrame. frame=new ExampleFrame();

frame.______(JFrame.EXIT_ON_CLOSE);

frame.show();

}

}

class ExampleFrame. extends JFrame

{

private JPanel panel;

public static final int DEFAULT_WIDTH=250;

public static final int DEFAULT_HEIGHT=250;

public ExampleFrame()

{

Init();

setTitle("welcome");

setSize(DEFAULT_WIDTH,DEFAULT_HEIGHT);

Container contentPane=getContentPane();

contentPane.add(panel);

}

private void init()

{

JLabel la1=new JLabel("输入整数a:");

JLabel la2=new JLabel ("输入整数b:");

final JTextField num1=new JTextField(10);

final JTextField num2=new JTextField(10);

JButton but=new JButton("计算");

final JLabel res=new JLabel("结果:");

but.addActionListener(______{

public void actionPerformed(ActionEvent event){

String str=new String();

String s1=num1.getText();

String s2=num2.getText();

try

{

int a=Integer.parseInt(s1);

int b=Integer.parseInt(s2);

str=String.valueOf(a +b);

}

catch(Exception e)

{

str=e.getMessage();

}

res.setText ("结果:"+str);

}

});

panel=new JPanel();

panel.setLayout(new FlowLayout(FlowLayout.LEFT));

panel.add(la1);

panel.add(num1);

panel.add(la2);

panel.add(hum2);

panel.add(but);

panel.add(res);

}

}

点击查看答案

第6题

下面Applet程序,其功能是实现一个计数器,每隔0.15秒计数器数值加1,数值动态变化,并且能够控制计

数器的暂停和继续。要求通过使用swing的构件建立图形用户界面,主要包括一个文本区域,用于显示计数器结果;两个按钮,一个使计数器暂停,一个使计数器继续工作。请改正程序中的错误(有下划线的语句),使程序能输出正确的结果。

注意:不改动程序的结构,不得增行或删行。

程序运行结果如下:

import javax.swing.*;

import java.awt.*;

import java.awt.event.*;

/*

<applet code="ex7_3.class" width=800 height=400 >

</applet>

*/

public class ex7_3 extends JApplet {

private JTextField jtf = new JTextField(15);

private JButton Hold = new JButton("Hold"),resume = new JButton("Resume");

private ex7_3th obj7_3th = new ex7_3th();

class ex7_3th extends Thread {

private int cnt = 0;

private boolean bIsHold = false;

public ex7_3th() { start(); }

public void hold() {

bIsHold = true;

}

public synchronized void fauxResume() {

bIsHold = false;

wait();

}

public void run() {

while (true) {

try {

sleep(150);

synchronized(this) {

while (bIsHold)

not i fy ( );

}

} catch(InterruptedException ie) {

System.err.println("Interrupted");

}

jtf.setText(cnt);

}

}

public void init() {

Container cp = getContentPane();

cp.setLayout(new FlowLayout());

cp.add(jtf);

Hold.addActionListener(

new ActionListener() {

public void actionPerformed(ActionEvent ae) {

obj7_3th.hold();

}

});

cp.add(Hold);

resume.addActionListener(

new ActionListener() {

public void actionPerformed(ActionEvent e){

obj7_3th.fauxResume();

}

});

cp.add(resume);

public static void main(String[] args) {

ex7_3 obj7_3=new ex7_3();

String str= obi7_3.getClass().toString();

if(str.indexOf("class") != -1)

str= str.substring(6);

JFrame. frm = new JFrame(str);

frm.addWindowListener(new WindowAdapter() {

public void windowClosing(WindowEvent we) {

System.exit(O);

}

});

frm.getContentPane().add(obj7_3);

frm.setSize(300, 200);

obj7_3.init();

点击查看答案

第7题

请完成下列Java程序:用一个边框布局来安排一个工具栏和一个卡片布局。工具栏可浮动,包括2个按钮,

一个向前一个向后控制卡片的显示;卡片布局包括3张卡片,分别标识为card1,card2,card3。

注意;请勿改动main()主方法和其他已有语句内容,仅在下划线处填入适当的语句。

程序运行结果如下:

import java.awt.*;

import java.awt.event.*;

import javax.swing.*;

import javax.swing.border. LineBorder;

public class ex24_2{

private static CardLayout cl=new CardLayout();

private static JPanel cp=new JPanel();

public static void main(String[] args){

JFrame. if=new JFrame();

jf.setTitle("ex24_2");

Container c=jf.getContentPane();

JToolBar jtb=new JToolBar();

JButton btnNext=new JButton(new ImageIcon("next.gif"));

JButton btnPre=new JButton(new ImageIcon("back.gif"));

jtb.add(btnPre);

jtb.add(btnNext);

cp.setLayout(cl);

Dimension dim=new Dimension(150,80);

cp.setPreferredSize(dim);

cp.setBorder(new LineBorder(Color. BLACK));

cp.add(new JLabel("cardl",JLabel.CENTER),"card1");

cp.add(new JLabel("card2",JLabel.CENTER),"card2");

cp.add(new JLabel("card3",JLabel.CENTER),"card3");

c.add(jtb,BorderLayout.NORTH);

c.add(cp,BorderLayout.CENTER);

ActionListener al=new ActionResponse();

____________________________________;

____________________________________;

jf.addWindowListener(new WindowAdapter(){

public void windowClosing(WindowEvent we){

System.exit(0);

}

});

jf.pack();

jf.setVisible(true);

}

static class ActionResponse implements ActionListener{

public void actionPerformed(ActionEvent ae){

if(ae.getActionCommand().equals("next"))

cl.next(cp);

else

cl.previous(cp);

}

}

}

点击查看答案

第8题

请完成下列Java程序:读取新浪首页文件的数据并且显示出来。要求编写JFrame扩展类,以String类的对

象定义的url地址作为入口参数,该类实现根据url参数指定的地址进行连接和读取数据,并且能显示在1个文本区域内。

注意:请勿改动main()主方法和其他已有语句内容,仅在下划线处填入适当的语句。

程序运行结果如下:

import javax.swing.*;

import java.awt.*;

import java.awt.event.*;

import java.net.*;

import java.io.*;

public class ex25_2 {

public static void main(String[] arg) {

UrlFrame. page = new UrlFrame("http://www.sina.com.cn");

page.show();

}

}

class UrlFrame. extends JFrame. {

JTextArea jta = new JmextArea("正在读取文件…");

URL url;

public UrlFrame(String strAddr) {

super (strAddr); //使用父类的构造方法。

setSize(450, 300);

JScrollPane jsp = new JScrollPane(jta);

getContentPane().add(jsp);

WindowListener wl = new WindowAdapter() {

public void windowClosing(WindowEvent we) {

System.exit(0);

}

};

addWindowListener(wl);

try {

url = new URL(strAddr);

____________________;

} catch (MalformedURLException murle) {

System.out.println("不合适的URL: "+ strAddr);

}

}

void getData(URL url) {

URLConnection con = null;

InputStreamReader isr;

BufferedReader readBuf;

String strLine;

StringBuffer strBuf = new StringBuffer();

try {

con = this.url.openConnection();

con.connect();

jta.setText("打开连接...");

isr = new InputStreamReader(con.getInputStream( ));

readBuf = new BufferedReader(isr);

jta.setText("读取数据...");

while ((strLine = readBuf.readLine()) != null)

strBuf.append(strLine + "\n");

_____________________________;

} catch (IOException e) {

System.out.println("IO 错误:" + e.getMessage());

}

}

}

点击查看答案

第9题

下列程序中,要求输出一个特定文件(这里是ex1.java)的相关信息,包括文件的名字,相对路径以及文件

的长度。请将程序补充完整。

程序运行结果如下:

name:ex1.java

path:ex1.java

length:299

注意:不改动程序结构,不得增行或删行。

import java.io.*;

public class ex1

{

public static void main(String[] args)

{

File filel=new File("ex1.java");

System.out println("name:"+file1.______);

System.out println("path:"+file1.______);

System.out println("length:"+file1.______);

}

}

点击查看答案

第10题

若想在程序中使用JLabel类,则该程序可以使用impoa______JLabel;语句引入 JLabel类。

点击查看答案
下载上学吧APP
客服
TOP
重置密码
账号:
旧密码:
新密码:
确认密码:
确认修改
购买搜题卡查看答案
购买前请仔细阅读《购买须知》
请选择支付方式
微信支付
支付宝支付
选择优惠券
优惠券
请选择
点击支付即表示你同意并接受《服务协议》《购买须知》
立即支付
搜题卡使用说明

1. 搜题次数扣减规则:

功能 扣减规则
基础费
(查看答案)
加收费
(AI功能)
文字搜题、查看答案 1/每题 0/每次
语音搜题、查看答案 1/每题 2/每次
单题拍照识别、查看答案 1/每题 2/每次
整页拍照识别、查看答案 1/每题 5/每次

备注:网站、APP、小程序均支持文字搜题、查看答案;语音搜题、单题拍照识别、整页拍照识别仅APP、小程序支持。

2. 使用语音搜索、拍照搜索等AI功能需安装APP(或打开微信小程序)。

3. 搜题卡过期将作废,不支持退款,请在有效期内使用完毕。

请使用微信扫码支付(元)
订单号:
遇到问题请联系在线客服
请不要关闭本页面,支付完成后请点击【支付完成】按钮
遇到问题请联系在线客服
恭喜您,购买搜题卡成功 系统为您生成的账号密码如下:
重要提示: 请勿将账号共享给其他人使用,违者账号将被封禁。
发送账号到微信 保存账号查看答案
怕账号密码记不住?建议关注微信公众号绑定微信,开通微信扫码登录功能
警告:系统检测到您的账号存在安全风险

为了保护您的账号安全,请在“上学吧”公众号进行验证,点击“官网服务”-“账号验证”后输入验证码“”完成验证,验证成功后方可继续查看答案!

- 微信扫码关注上学吧 -
警告:系统检测到您的账号存在安全风险
抱歉,您的账号因涉嫌违反上学吧购买须知被冻结。您可在“上学吧”微信公众号中的“官网服务”-“账号解封申请”申请解封,或联系客服
- 微信扫码关注上学吧 -
请用微信扫码测试
选择优惠券
确认选择
谢谢您的反馈

您认为本题答案有误,我们将认真、仔细核查,如果您知道正确答案,欢迎您来纠错

上学吧找答案