深圳自考报名网:http://www.0755zikaobaoming.com
} public void actionPerformed(ActionEvent e) { int n,d; if(e.getSource()==textF) { n = Integer.parseInt(textF.getText()); for (int k=1;k<=n; k++) { d= (int) (Math.random()*100000); textA.append(\35.阅读下列程序,请回答以下问题:
(1)程序运行时,呈现的界面中菜单条有哪些菜单? (2)程序中带注释/*1*/的代码行的作用是什么?
import javax.swing.*;import java.awt.*;import java.awt.event.*; class MenuWindow extends JFrame implements ActionListener{
JTextField text;
MenuWindow (String s,String menuList[][]){
setTitle(s);
Container con = this.getContentPane(); con.setLayout(new BorderLayout());
this.setLocation(100, 100); this.setSize(300, 100); JMenuBar menubar=new JMenuBar(); for(int i=0;i< menuList.length; i++){
JMenu menu = new JMenu(menuList[i][0]); for(int j=1;j JMenuItem anItem=new JMlenuItem(menuList[i][j]); /*1*/ anItem.setActionCommand(menuList[i][j]); anItem.addActionListener(this); menu.add(anItem); } menubar.add(menu); } text = new JTextField(); setjMenuBar(menubar); con.add(text,BorderLayout.SOUTH); } public void actionPerformed(ActionEvent e){ text.setText(\菜单项被选中!\); } } public class Test35{ public static void main(String[] args){ MenuWindow window; String menuList[][]={{\体育\,\跑步\,\打篮球\,\打乒乓\, ═══════════════════════════════════════════════════════════════════════════════ 深圳自考报名网:http://www.0755zikaobaoming.com {\娱乐\,\唱歌\,\跳舞\, {\学习\,\数学\,\语文\; window=new MenuWindow(\菜单示例程序\,menuList); window.setVisible(true); } } 答: (1)体育、娱乐、学习,三个菜单。 (2)用菜单项名称设置该菜单项事件源的文字信息。 import javax.swing.*;import java.awt.*;import java.awt.event.*; class MenuWindow extends JFrame implements ActionListener { JTextField text; MenuWindow (String s,String menuList[][]) { setTitle(s); Container con = this.getContentPane(); con.setLayout(new BorderLayout()); this.setLocation(100, 100); this.setSize(300, 100); JMenuBar menubar=new JMenuBar(); for(int i=0;i< menuList.length; i++) { JMenu menu = new JMenu(menuList[i][0]); for(int j=1;j { JMenuItem anItem=new JMenuItem(menuList[i][j]); /*1*/ anItem.setActionCommand(menuList[i][j]); anItem.addActionListener(this); menu.add(anItem); } menubar.add(menu); } text = new JTextField(); setJMenuBar(menubar); con.add(text,BorderLayout.SOUTH); } public void actionPerformed(ActionEvent e) { text.setText(\菜单项被选中!\ ═══════════════════════════════════════════════════════════════════════════════ 深圳自考报名网:http://www.0755zikaobaoming.com } } public class Test35 { public static void main(String[] args) { MenuWindow window; String menuList[][]={{\体育\跑步\打篮球\打乒乓\娱乐\唱歌\跳舞\学习\数学\语文\菜单示例程序\ 36.阅读下列程序,请回答以下问题: (1)程序要求在文本框text中输入的内容是什么? (2)程序采用什么输入方式下载网络文件? import java.net.*; import java.awt.*; import java.awt.event.*; import java.io.*; import javax.swing.*; public class Test36{ public static void main(String args[]){ new ConnectNet(\读取网络文本文件示意程序\); } } class ConnectNet extends JFrame implements ActionListener{ JTextField text = new JTextField(30); JTextArea showArea=new JTextArea(); JButton b= new JButton(\下载\ConnectNet(String s){ super(s);Container con = this.getContentPane(); p.add(text); p.add(b); JScrollPane jsp = new JScrollPane(showArea); b.addActionListener(this); con.add(p,\ con.add(jsp, \ setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setSize(500, 400); setVisible(true); } public void actionPerformed(ActionEvent e){ String urlName=text.getText(); try{ URL url: new URL(urlName);∥由网址创建URL对象 URLConnection tc =url.openConnection();∥获得URLConnection对象 tc.connect();∥设置网络连接 InputStreamReader in = new InputStreamReader(tc.getInputStream()); BufferedReader dis = new BufferedReader(in); ═══════════════════════════════════════════════════════════════════════════════ 深圳自考报名网:http://www.0755zikaobaoming.com String inLine; while((inLine=dis.readLine())!=null){ showArea.append(inLine+\} dis.close(); } catch (MalformedURLException e2){e2.printStackTrace();} catch(IOException e3){ e3.printStackTrace();} } } 答: (1)网络文本文件的 URL 地址。 (2)缓冲式输入 import java.net.*;import java.awt.*; import java.awt.event.*; import java.io.*; import javax.swing.*; public class Test36 { public static void main(String args[]) { new ConnectNet(\读取网络文本文件示意程序\} } class ConnectNet extends JFrame implements ActionListener { JTextField text = new JTextField(30); JTextArea showArea=new JTextArea(); JButton b= new JButton(\下载\JPanel p= new JPanel(); ConnectNet(String s) { super(s);Container con = this.getContentPane(); p.add(text); p.add(b); JScrollPane jsp = new JScrollPane(showArea); b.addActionListener(this); con.add(p,\con.add(jsp, \setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setSize(500, 400); setVisible(true); } public void actionPerformed(ActionEvent e) { String urlName=text.getText(); try { ═══════════════════════════════════════════════════════════════════════════════