本题中,通过菜单“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; )
第1题:
在Visual FoxPro的命令窗口中键入OPEN DATA命令以后,屏幕会出现一个创建对话框,要想完成同样的工作,还可以采取如下步骤( )。
A.单击“文件”菜单中的【打开】按钮,在“打开”对话框中,从“文件类型”列表框中选择“数据库”,并在显示窗口中选择要打开的数据库名,单击【确定】
B.单击“编辑”菜单中的【打开】按钮,在“打开”对话框中,从“文件类型”列表框中选择“数据库”,并在显示窗口中选择要打开的数据库名,单击【确定】
C.单击“文件”菜单中的【打开】按钮,在“打开”对话框中,从“文件类型”列表框中选择“项目”,并在显示窗口中选择要打开的数据库名,单击【确定】
D.单击“文件”菜单中的【打开】按钮,在“打开”对话框中,从“文件类型”列表框中选择“表”,并在显示窗口中选择要打开的数据库名,单击【确定】
第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");
}
}
第3题:
A.插入
B.工具
C.格式
D.数据
第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;
}
第5题:
在Visual FoxPro的命令窗口中键入CREATE DATA命令以后,屏幕会出现一个创建对话框,要想完成同样的工作,还可以采用如下步骤_______。
A.选择“文件”菜单中的“新建”命令,然后在新建对话框中单击“数据库”单选按钮,再单击“新建文件”命令按钮
B.选择“文件”菜单中的“新建”命令,然后在新建对话框中单击“数据库”单选按钮,再单击“向导”命令按钮
C.选择“文件”菜单中的“新建”命令,然后在新建对话框中单击“表”单选按钮,再单击“新建文件”命令按钮
D.选择“文件”菜单中的“新建”命令,然后在新建对话框中单击“表”单选按钮,再单击“向导”命令按钮