JAVA上机考试题目.doc_第1页
JAVA上机考试题目.doc_第2页
JAVA上机考试题目.doc_第3页
JAVA上机考试题目.doc_第4页
JAVA上机考试题目.doc_第5页
已阅读5页,还剩2页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

上机考试题目1、 冒泡排序(P114、例6.20)(注意到时候是按照什么顺序排序的)public class BubbleSort public static void main(String args) int array=63,4,24,1,3,5;BubbleSort sorter=new BubbleSort();sorter.sort(array);/冒泡排序public void sort(int array)for(int i=1;iarray.length;i+)for(int j=0;jarrayj+1)int temp=arrayj;arrayj=arrayj+1;arrayj+1=temp; showArray(array);/遍历数组,并输出数组的元素。public void showArray(int array)for(int i=0;iarray.length;i+) System.out.print(arrayi+t);System.out.println();2、 类的定义与使用(参照练习题册的类定义)参考老师给的题目!3、 界面编程(获取界面的录入信息,并输出到控制台)这个地方大家可能会有疑问,因为之前写的没有重置这个按钮功能,我把他添了进去,所以到时候抽到这道题目的时候,注意下,题目是否要有重置监听器!import java.awt.event.*;import javax.swing.*;import javax.swing.border.Border;import javax.swing.border.EtchedBorder;import javax.swing.border.TitledBorder;public class SwingReigster extends JFrame JPasswordField pwd = new JPasswordField();JTextField nameTxt = new JTextField();JTextArea intrArea = new JTextArea();ButtonGroup group = new ButtonGroup();JRadioButton fRdo = new JRadioButton(男, true);JCheckBox hobbyChk2 = new JCheckBox(运动, true);JCheckBox hobbyChk3 = new JCheckBox(爬山);JCheckBox hobbyChk = new JCheckBox(睡觉);JComboBox edicbo = new JComboBox();public SwingReigster() this.init();public void init() this.setTitle(用户注册);this.setBounds(100, 100, 340, 500);this.createUI();this.setVisible(true);this.setDefaultCloseOperation(EXIT_ON_CLOSE);getContentPane().setLayout(null);public void createUI() JPanel panel = new JPanel();/ 添加边框Border border = BorderFactory.createEtchedBorder(EtchedBorder.LOWERED);TitledBorder tBorder = BorderFactory.createTitledBorder(border, 注册面板,TitledBorder.CENTER, TitledBorder.TOP);panel.setBorder(tBorder);panel.setLayout(null);this.add(panel);/ 密码JLabel pwdLbl = new JLabel(输入密码:);pwdLbl.setBounds(10, 80, 60, 25);panel.add(pwdLbl); pwd = new JPasswordField();pwd.setBounds(80, 80, 120, 22);panel.add(pwd);/ 性别JLabel genderLbl = new JLabel(性别:);genderLbl.setBounds(10, 110, 60, 25);panel.add(genderLbl);group = new ButtonGroup();fRdo.setBounds(80, 110, 50, 25);group.add(fRdo);JRadioButton mRdo = new JRadioButton(女, false);mRdo.setBounds(140, 110, 50, 25);group.add(mRdo);panel.add(fRdo);panel.add(mRdo);/姓名JLabel nameLbl = new JLabel(输入姓名:);nameLbl.setBounds(10, 50, 60, 25);panel.add(nameLbl); nameTxt = new JTextField();nameTxt.setBounds(80, 50, 120, 22);panel.add(nameTxt);/ 学历JLabel ediLbl = new JLabel(学历:);ediLbl.setBounds(10, 140, 60, 25);panel.add(ediLbl);/ 下拉列表edicbo.addItem(高中);edicbo.addItem(大专);edicbo.addItem(本科);edicbo.addItem(其它);edicbo.setBounds(80, 140, 80, 22);panel.add(edicbo);/ 爱好JLabel hobbyLbl = new JLabel(爱好:);hobbyLbl.setBounds(10, 170, 60, 25);panel.add(hobbyLbl);/ 复选框hobbyChk.setBounds(80, 170, 60, 25);panel.add(hobbyChk);hobbyChk2.setBounds(150, 170, 60, 25);panel.add(hobbyChk2);hobbyChk3.setBounds(220, 170, 60, 25);panel.add(hobbyChk3);/ 自我介绍JLabel intrLbl = new JLabel(自我介绍:);intrLbl.setBounds(10, 200, 60, 25);panel.add(intrLbl);/ Swing中,文本域默认是不带滚动条的,必须放置在JScrollPane中,才会滚动条intrArea = new JTextArea();JScrollPane scrollPane = new JScrollPane(intrArea,JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);scrollPane.setBounds(20, 230, 240, 110);panel.add(scrollPane);/ 按钮JButton btn = new JButton( 提交 );btn.setBounds(50, 420, 70, 22);btn.addActionListener(new ActionListener() public void actionPerformed(ActionEvent arg0) /* * 参数1: 父组件 参数2: 提示信息 参数3: 标题信息 * 参数4: 指定按钮类型 参数5: 指定图标类型 * 返回值:用户所选选项的整数 */int option = JOptionPane.showConfirmDialog(null, 你确定提交吗?,提交提示, JOptionPane.OK_CANCEL_OPTION,JOptionPane.WARNING_MESSAGE);if (option = JOptionPane.OK_OPTION) System.out.println(ok,submit!); else System.out.println(no, cancel););panel.add(btn);JButton btn2 = new JButton( 重置 );btn2.setBounds(150, 420, 70, 22);panel.add(btn2);btn2.addActionListener(new ActionListener() public void actionPerformed(ActionEvent arg0) /重置处理代码. nameTxt.setText(); pwd.setText(); intrArea.setText(); fRdo.setSelected(true) ; hobbyChk2.setSelected(true); hobbyChk3.setSelected(false); hobbyChk.setSelected(false); edicbo.setSelectedIndex(0); );public static void main(String args) new SwingReigster();4、 I/O输入输出(使用FileReader与FileWriter实现例子15.3)import java.io.File;import java.io.FileReader;import java.io.FileWriter;public class SwingReigster public static void main(String args) File file=new File(word.txt); tryFileWriter out=new FileWriter(file);String buy=我是一头小毛驴;out.write(buy);out.close();catch(Exception e)e.printStackTrace(); try FileReader in=new FileReader(file);char buy=new char1024;int len=in.read(buy);System.out.println(文件中的信息是 +new String(buy,0,len);in.close();catch(Exception e)e.printStackTrace();5、 多线程(p335例18.9)6、 编程基础(p74、练习3)import java.util.Scanner; public

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

最新文档

评论

0/150

提交评论