本题中,通过菜单“Connect”显示-个对话框,单击“0k”按钮后,所填写的内容就会传回到主窗口并显示出来。password.setText(transfer.password); k=false; show( ); if(ok){ transfer.username=username.getText( ); transfer.password=new String(password.get Password( )); ) return ok; } private JTextField username

题目

本题中,通过菜单“Connect”显示-个对话框,单击“0k”按钮后,所填写的内容就会传回到主窗口并显示出来。password.setText(transfer.password); k=false; show( ); if(ok){ transfer.username=username.getText( ); transfer.password=new String(password.get Password( )); ) return ok; } private JTextField username; private JPasswordField password; private boolean ok; private JButton okButton; private J Button cancelButton; )


相似考题
更多“ 本题中,通过菜单“Connect”显示-个对话框,单击“0k”按钮后,所填写的内容就会传回到主窗口并显示出来。password.setText(transfer.password); k=false; show(”相关问题
  • 第1题:

    在Visual FoxPro的命令窗口中键入OPEN DATA命令以后,屏幕会出现一个创建对话框,要想完成同样的工作,还可以采取如下步骤( )。

    A.单击“文件”菜单中的【打开】按钮,在“打开”对话框中,从“文件类型”列表框中选择“数据库”,并在显示窗口中选择要打开的数据库名,单击【确定】

    B.单击“编辑”菜单中的【打开】按钮,在“打开”对话框中,从“文件类型”列表框中选择“数据库”,并在显示窗口中选择要打开的数据库名,单击【确定】

    C.单击“文件”菜单中的【打开】按钮,在“打开”对话框中,从“文件类型”列表框中选择“项目”,并在显示窗口中选择要打开的数据库名,单击【确定】

    D.单击“文件”菜单中的【打开】按钮,在“打开”对话框中,从“文件类型”列表框中选择“表”,并在显示窗口中选择要打开的数据库名,单击【确定】


    正确答案:A
    解析:使用“打开”命令方式打开数据库。首先选择“文件”菜单的“打开”命令,然后在“打开”对话框中,从“文件类型”列表框中选择“数据库”,并在显示窗口中选择要打开的数据库名,单击【确定】按钮。

  • 第2题:

    本题中,主窗口有一个按钮“打开对话框”和一个文本域,单击按钮“打开对话框”后会弹出一个对话框,对话框上有两个按钮“Yes"和“N0”,单击对话框上的“Yes”和“N0”按 钮后返回主窗口,并在右侧文本域中显示刚才所单击的按钮信息。

    import java.awt.event.*;

    import java.awt.*;

    class MyDialog implements ActionListener

    {static final int YES=1,N0=0;

    int message=-1;Button yes,no;

    MyDialog(Frame. f.String S,boolean b)

    {super(f,S,b);

    ves=new Button("Yes");yes.addActionListener

    (this);

    no=new Button("No"); no.addActionListener

    (this)o

    setLayout(new FlowLayout());

    add(yes);add(no);

    setBounds(60,60,100,100);

    addWindowListener(new WindowAdapter()

    { public void windowClosing(WindowEvent e)

    {message=-1;setVisible(false);)

    });

    }

    public void actionPerformed(ActionEvent e)

    {if(e.getSource()= =yes)

    {message=YES;

    setVisible(false);

    }

    else if(e.getSource()= = no)

    {message=NO;

    setVisible(false);

    }

    }

    public int getMessage()

    {return message;

    }

    }

    class Dwindow extends Frame. implements ActionLis-

    tener

    {TextArea text;Button button;MyDialog dialog;

    Dwindow(String s)

    {super(s);

    text=new TextArea(5,22);button=new Button

    ("打开对话框");

    button.addActionListener(this);

    setLayout(new FlowLayout());

    add(button);add(text);

    dialog=new MyDialog(this,"Dialog",true);

    setBounds(60,60,300,300);setVisible(true);

    validate();

    addWindowListener(new WindowAdapter()

    {public void windowClosing(WindowEvent e)

    {System.exit(0);}

    });

    }

    public void actionPerformed(ActionEvent e)

    {if(e.getSource()= =button)

    {

    if(dialog.getMessage()= =MyDialog.YES)

    {text.append("\n你单击了对话框的yes按

    钮");

    }

    else if(dialog.getMessage()= =MyDialog.NO)

    {text.append("\n你单击了对话框的N0按

    钮");

    }

    }

    }

    }

    public class java2

    {public static void main(String args[])

    {new Dwindow("java2");

    }

    }


    正确答案:
    第1处:extendsDialog第2处:dialog.setVisible(true)【解析】第1处设定对话框的类应继承Dialog类;第2处显示对话框。

  • 第3题:

    如果要显示公式,可选择()菜单中的选项命令,显示对话框后,单击"视图"标签,选择"窗口选项"框中的公式,按下"确定"按钮即可。

    A.插入

    B.工具

    C.格式

    D.数据


    参考答案:B

  • 第4题:

    本题中,通过菜单“Connect”显示一个对话框,单击“ok”按钮后,所填写的内容就会传回到主窗口并显示出来。

    import java.awt.*

    import java.awt.event.*;

    import javax.swin9.*;

    public class java3 extends JFrame. implements ActionL-

    istener{

    public java3(){

    setTitle("java3");

    setSize(300,300);

    addWindowListener(new WindowAdapter(){

    public void windowClosing(WindowEvent e){

    System.exit(0);

    }

    });

    JMenuBar mbar = new JMenuBar();

    setJMenuBar(bar);

    JMenu fileMenu=new JMenu("File");

    mbar.add(fileMenu);

    connectltem=new JMenuhem("Connect");

    connecthem.addActionListener(this);

    fileMenu.add(connecthem);

    exithem=new JMenuhem("Exit");

    exithem.addActionListener(this);

    fileMenu.add(exithem);

    }

    public void actionPerformed(ActionEvent evt){

    Object source=evt.getSource();

    if(source= =connecthem){

    Connectlnfo transfer=new ConnectInfo ("your-

    name","pw");

    if(dialog= =null)

    dialog=new ConnectDialog(this);

    if(dialog.showDialog(transfer)){

    String uname=transfer.username;

    String pwd=transfer.password;

    Container contentPane=getContentPane();

    contentPane.add(new JLabel("username="+

    uname+",password="+pwd),"South");

    validate();

    }

    }

    else if(source= =exitltem)

    System.exit(0);

    }

    public static void main(String[]args){

    JFrame. f=new java3();

    f.show();

    }

    private ConnectDialog dialog=null;

    private JMenuhem connecthem;

    private JMenuhem exithem;

    }

    class Connectlnfo{

    public String username;

    public String password;

    public Connectlnfo(String U,String p){

    username=u;password=P;

    }

    }

    class ConnectDialog extends JDialog implements Ac-

    tionListener{

    public ConnectDialog(){

    super(parent,"Connect",true);

    Container contentPane=getContentPane();

    JPanel pl=new JPanel();

    pl.setLayout(new GridLayout(2,2));

    pl.add(newJLabel("User name:"));

    pl.add(username=new JTextField(""));

    pl.add(new JLabel("Password:"));

    pl.add(password=new JPasswordField(""));

    contentPane.add("Center",pl);

    Panel p2=new Panel();

    okButton=addButton(p2,"ok");

    cancelButton=addButton(p2。"Cancel");

    contentPane.add("South",p2);

    setSize(240,120);

    }

    JButton addButton(Container C,String name){

    JButton button=new JButton(name);

    button.addActionListener(this);

    C.add(button);

    return button;

    }

    public void actionPerformed(ActionEvent evt){

    object source=evt.getSource();

    if(source= =okButton){

    ok=true:

    setVisible(false);

    }

    else if(source= =cancelButton)

    setVisible(false);

    }

    public void showDialog(Connectlnfo transfer){

    username.setText(transfer.username);

    password.setText(transfer.password);

    ok=false;

    show();

    if(ok){

    transfer.username=username.getText();

    transfer.password=new String(password.get-

    Password());

    }

    return ok;

    }

    private JTextField username

    private JPasswordField password;

    private boolean ok;

    private JButton okButton;

    private JButton cancelButton;

    }


    正确答案:
    第1处:setJMenuBar(mbar)第2处:publicConnectDialog(JFrameparent)第3处:publicBooleanshowDialog(Connectlnfotransfer)【解析】第1处参数错误,bar未定义;第2处从下一行的super(parent,"Connect",true);可以看出,这里需要的参数为父窗体;第3处从下面的returnok;等可以看出,这是一个有Boolean型返回值的函数,故类型应为Boolean。

  • 第5题:

    在Visual FoxPro的命令窗口中键入CREATE DATA命令以后,屏幕会出现一个创建对话框,要想完成同样的工作,还可以采用如下步骤_______。

    A.选择“文件”菜单中的“新建”命令,然后在新建对话框中单击“数据库”单选按钮,再单击“新建文件”命令按钮

    B.选择“文件”菜单中的“新建”命令,然后在新建对话框中单击“数据库”单选按钮,再单击“向导”命令按钮

    C.选择“文件”菜单中的“新建”命令,然后在新建对话框中单击“表”单选按钮,再单击“新建文件”命令按钮

    D.选择“文件”菜单中的“新建”命令,然后在新建对话框中单击“表”单选按钮,再单击“向导”命令按钮


    正确答案:A
    解析:建立数据库的常用方法有以下3种:①在项目管理器中建立数据库在“数据”选项卡中选择“数据库”,然后单击“新建”按钮并选择“新建数据库”,通过“新建”对话框提示用户输入数据库的名称,即扩展名为.dbc的文件名。②通过“新建”对话框建立数据库选择“文件”菜单中的“新建”命令,然后在“新建”对话框中单击“数据库”单选按钮,再单击“新建文件”命令按钮。③使用命令交互建立数据库CREATE DATABASE[DatabaseName|?]