Java语言程序设计编程题2.doc_第1页
Java语言程序设计编程题2.doc_第2页
Java语言程序设计编程题2.doc_第3页
Java语言程序设计编程题2.doc_第4页
Java语言程序设计编程题2.doc_第5页
已阅读5页,还剩7页未读 继续免费阅读

下载本文档

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

文档简介

一、编程题。本题共七题,第1题5分,2、3、4题每题10分,第5、6、7题每题15分,共80分。1、编程实现,当在命令行中输入“好”时,输出为“good”,当在命令行中输入“坏”时,输出为“bad”。2编写程序计算12+22+32+42+972+982+992+1002的值,输出。3编写类C1,C1中只有一个方法pa(),显示“济南职业学院”,编写类C2,调用pa()方法,在屏幕上显示10行“济南职业学院”。4、自定义类Days及其方法dayInmonth( )。该方法的功能是返回用户输入月份的天数(二月份就按28天计算)。例如用户输入3,则该方法将返回值31;用户输入4,则该方法将返回值30。通过main()方法将返回值显示出来。(本题10分)5、自定义类Cla,该类中有方法convert(),其功能是将传入的数字字符串转换成数字,并显示出来。但若传入的字符串中含有字母,则该方法能抛出NumberFormatException异常,并输出“所输入的字符串中含有非数字的文字,无法转换”。(本题10分)6、编写程序,实现如图所示功能:在宽和高文本框中输入数值,当单击“更改”按钮时,将窗体大小改为文本框中输入的数值。单击“退出”时,退出应用程序。(本题10分)7、编写一个Applet程序Myapplet,实现如图所示的界面,并将怎样把该程序插入网页中的代码段写出来。(本题15分)8、编写程序,实现如图所示功能:在x和y两个文本框中输入数值,按下右面的任意按钮能进行相应的计算,并将结果显示在中间的文本区中,该区域可以用清除按钮清除。(本题15分)二、程序解释题(共1题,共20分)import java.awt.*;import java.awt.event.*;public class Mouseevent extends WindowAdapter implements MouseMotionListener Frame f=new Frame();Panel p1 = new Panel();Panel p2 = new Panel();Label l1 = new Label(X轴);Label l2 = new Label(Y轴);TextField tf1 = new TextField(4);TextField tf2 = new TextField(4);int x;int y;public static void main(String asgs)Mouseevent hua=new Mouseevent();hua.go();private void go() f.setSize(300, 200);f.add(p2,South);p2.add(l1);p2.add(tf1);p2.add(l2);p2.add(tf2);f.add(p1);p1.addMouseMotionListener(this);f.addWindowListener(this);f.setVisible(true);public void mouseDragged(MouseEvent event)public void mouseMoved(MouseEvent event)tf1.setText(Integer.toString(event.getX();tf2.setText(Integer.toString(event.getY();public void windowClosing(WindowEvent we)System.exit(0);参考答案:1、class Sapublic static void main(String args)if (args0.equals(“Good”)System.out.println(“好”);if (args0.equals(“Bad”)System.out.println(“坏”);2、class Sapublic Sa(String x)if (x.equals(“Good”)System.out.println(“好”);if (x.equals(“Bad”)System.out.println(“坏”);public class Sbpublic static void main(String args)Sa sa=new Sa(args0);3、在Sb类的定义前加上语句importmypackagejiafa;即可。4、class Daysstaticint dayInmonth(int a)int s=31;switch(a)case 2: s=28;break;case 4: case 6: case 9: case 11: s=30;return s;public static void main(String args)int a=Integer.parseInt(args0);int b=dayInmonth(a);System.out.println(a+月有+b+天);5、class Clastatic void convert(String s)trydouble a=Double.parseDouble(s);System.out.println(a);catch(NumberFormatException e)System.out.println(所输入的字符串中含有非数字的文字,无法转换);public static void main(String args)convert(args0);6、import java.awt.*;import java.awt.event.*;class Myframe implements ActionListenerFrame f=new Frame(窗口更改大小);Panel p=new Panel();Panel p1=new Panel();Label l=new Label(宽:);Label l1=new Label(高:);TextField tf=new TextField(4);TextField tf1=new TextField(4);Button b=new Button(更改);Button b1=new Button(退出);public static void main(String args)Myframe my=new Myframe();my.go();void go()p.add(l);p.add(tf);p.add(l1);p.add(tf1);p1.add(b);p1.add(b1);b.addActionListener(this);b1.addActionListener(this);f.add(p,North);f.add(p1);f.setSize(200,100);f.setVisible(true);public void actionPerformed(ActionEvent e)String s=e.getActionCommand();if (s.equals(更改)int a=Integer.parseInt(tf.getText();int b=Integer.parseInt(tf1.getText();/f.setSize(a,b);f.resize(a,b);else System.exit(0);7、import java.awt.*;import javax.swing.*;public class Myapplet extends JApplet JRadioButton jRadioButton1 = new JRadioButton(RadioButton1);JRadioButton jRadioButton2 = new JRadioButton(RadioButton2);ButtonGroup btg=new ButtonGroup();JCheckBox jCheckBox1 = new JCheckBox(CheckBox1);JCheckBox jCheckBox2 = new JCheckBox(CheckBox2);JCheckBox jCheckBox3 = new JCheckBox(CheckBox3);JTextField jTextField1 = new JTextField(TextField1);JLabel jLabel1 = new JLabel(Label1);FlowLayout flowLayout1 = new FlowLayout();public void init() myInit();void myInit() this.getContentPane().setLayout(flowLayout1);btg.add(jRadioButton1);btg.add(jRadioButton2);this.getContentPane().add(jRadioButton2, null);this.getContentPane().add(jRadioButton1, null);this.getContentPane().add(jCheckBox1, null);this.getContentPane().add(jCheckBox2, null);this.getContentPane().add(jCheckBox3, null);this.getContentPane().add(jLabel1, null);this.getContentPane().add(jTextField1, null);8、import java.awt.*;import java.awt.event.*;class jisuanqi implements ActionListenerFrame f=new Frame(计算器);Panel p=new Panel();Panel p1=new Panel();Panel p2=new Panel();Button b=new Button(x+y);Button b1=new Button(x-y);Button b2=new Button(清除);Label lbx=new Label(x);Label lby=new Label(y);TextField tfx=new TextField(4);TextField tfy=new TextField(4);TextArea ta=new TextArea();Font ft =new Font(宋体,Font.BOLD,18);GridLayout g1=new GridLayout(4,1);GridLayout g2=new GridLayout(2,1);double x,y,sum;public static void main(String args)jisuanqi ji=new jisuanqi() ;ji.go();public void go()b.setFont(ft);b1.setFont(ft);b2.setFont(ft);lbx.setAlignment(Label.CENTER);lby.setAlignment(Label.CENTER);lbx.setFont(ft);lby.setFont(ft);tfx.setFont(ft);tfy.setFont(ft);ta.setFont(ft);p.setLayout(g1);p.add(lbx);p.add(tfx);p.add(lby);p.add(tfy);f.add(p,West);p1.setLayout(g2);p1.add(b);p1.add(b1);b.addActionListener(this);b1.addActionListener(this);f.add(p1,East);p2.add(b2);b2.addActionListener(this);f.add(p2,South);f.add(ta,Center);f.setSize(250,150);f.setVisible(true);publ

温馨提示

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

评论

0/150

提交评论