Java考试题之swt组件.doc_第1页
Java考试题之swt组件.doc_第2页
Java考试题之swt组件.doc_第3页
Java考试题之swt组件.doc_第4页
Java考试题之swt组件.doc_第5页
已阅读5页,还剩5页未读 继续免费阅读

下载本文档

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

文档简介

Java考试题之swt组件一、JavaTest01C:. .classpath .project.settings org.eclipse.jdt.core.prefsbin com example test Main.class WindowsActionEvent.classsrc com example test Main.java WindowsActionEvent.java/WindowsActionEvent.javapackage com.example.test;import java.awt.FlowLayout;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import javax.swing.JButton;import javax.swing.JFrame;import javax.swing.JTextField;/*一、编写一个GUI程序,要求如下 * 1.有一个窗口,标题是计算sin的值,布局是FlowLyaout布局 * 初始大小是(200,300),初始位置是(120,260) * 2.窗口中有两个文本框(JTextField),名字分别是input和show,可见字符长度不小于15 * 3.窗口中有两个按钮(JButton),button_1和button_2,这两个按钮上的名字分别是按度计算,按弧度计算 * 4.将文本框和按钮添加到窗口,顺序是input,button_1,button_2,show * 5.用户在input中输入一个数,比如60, * 单击按度计算,在show 中显示(sin)正弦60度的值 * 单击按弧度计算,在show 中显示(sin)正弦60弧度的值 * * 提示:Math类中的静态方法sin(x)将x看成弧度,因此,要计算60度的正弦值,必须写成 * Math.sin(60*3.1415926/180) * 或Math.sin(60*Math.PI/180) * * 在命令行输入一个数,程序输出这个数的sin值 * 在命令行输入2个数,然后计算Math.pow(a,b) * * */public class WindowsActionEvent extends JFrame implements ActionListener JTextField input, show;JButton button_1, button_2;WindowsActionEvent() setTitle(计算sin的值);/ setSize(200, 300);/ setLocation(120, 260);setBounds(120, 260, 200, 300);setLayout(new FlowLayout();input = new JTextField(15);show = new JTextField(15);button_1 = new JButton(按度计算);button_2 = new JButton(按弧度计算);add(input);add(button_1);add(button_2);add(show);input.addActionListener(this);button_1.addActionListener(this);button_2.addActionListener(this);setVisible(true);setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);Overridepublic void actionPerformed(ActionEvent e) if (e.getSource() = button_1)String str=input.getText();double a=Double.parseDouble(str);double r=Math.sin(a*3.1415926/180);show.setText(+r);if (e.getSource() = button_2) String str=input.getText();double a=Double.parseDouble(str);double r=Math.sin(a);show.setText(+r);/Main.javapackage com.example.test;public class Main public static void main(String args) WindowsActionEvent wae=new WindowsActionEvent();二、JavaTest02C:. .classpath .project.settings org.eclipse.jdt.core.prefsbin com example test Main.class WindowsActionEvent.classsrc com example test Main.java WindowsActionEvent.java/WindowsActionEvent.javapackage com.example.test;import java.awt.FlowLayout;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import javax.swing.JButton;import javax.swing.JFrame;import javax.swing.JTextField;/*二、编写一个GUI程序,要求如下 * 1.有一个窗口,标题是大小写转换器,窗口宽300,高200 * 布局是FlowLyaout布局 * 2.窗口中有一个文本框(JTextField),两个按钮(JButton),两个按钮名字分别为大写,小写, * 当用户单击大写按钮时,文本框中的文本转换成大写,并显示在文本框中, * 当用户单击小写按钮时,文本框中的文本转换成小写,并显示在文本框中, * * */public class WindowsActionEvent extends JFrame implements ActionListener JTextField text;JButton button_1, button_2;WindowsActionEvent() setTitle(大小写转换器);setSize(300, 200);setLayout(new FlowLayout();text = new JTextField(20);button_1 = new JButton(大写);button_2 = new JButton(小写);add(text);add(button_1);add(button_2);text.addActionListener(this);button_1.addActionListener(this);button_2.addActionListener(this);setVisible(true);setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);Overridepublic void actionPerformed(ActionEvent e) if (e.getSource() = button_1)String str=text.getText().toUpperCase();text.setText(+str);if (e.getSource() = button_2) String str=text.getText().toLowerCase();text.setText(+str);/Main.javapackage com.example.test;public class Main public static void main(String args) WindowsActionEvent wae=new WindowsActionEvent();三、JavaTest03C:. .classpath .project.settings org.eclipse.jdt.core.prefsbin com example test Main.class WindowsActionEvent.classsrc com example test Main.java WindowsActionEvent.java/WindowsActionEvent.javapackage com.example.test;import java.awt.FlowLayout;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import javax.swing.JButton;import javax.swing.JFrame;import javax.swing.JTextField;/*三、编写一个GUI程序,要求如下 * 1.给定a,b,c三个文本框。和一个确定按钮 * 往a,b放入数据,在b中回车,则在c中显示a+b的值 * b,确定按钮设为监视器 * 需要用try-catch判断输入是否合法 * * */public class WindowsActionEvent extends JFrame implements ActionListener JTextField text_1, text_2, text_3;JButton button;WindowsActionEvent() setTitle(处理事件);setSize(300, 200);setLayout(new FlowLayout();text_1 = new JTextField(20);text_2 = new JTextField(20);text_3 = new JTextField(20);button = new JButton(確定);add(text_1);add(text_2);add(text_3);add(button);text_2.addActionListener(this);button.addActionListener(this);setVisible(true);setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);Overridepublic void actionPerformed(ActionEvent e) double a, b;try a = Double.parseDouble(text_1.getText();b = Double.parseDouble(text_2.getText();if (e.getSource() = text_2) text_3.setText(String.valueOf(a+b);if (e.getSource() = button) text_3.setText(String.valueOf(a-b); catch (Exception e2) text_3.setText(请输入合法数字);/Main.javapackage com.example.test;public class Main public static void main(String args) WindowsActionEvent wae=new WindowsActionEvent();四、JavaTest04C:. .classpath .project.settings org.eclipse.jdt.core.prefsbin com example test Main.class ReadListener.class WindowsActionEvent.classsrc com example test Main.java ReadListener.java WindowsActionEvent.java/WindowsActionEvent.javapackage com.example.test;import java.awt.FlowLayout;import java.awt.event.ActionListener;import javax.swing.JButton;import javax.swing.JFrame;import javax.swing.JTextField;/*三、编写一个GUI程序,要求如下 * 1.给定a,b,c三个文本框。和一个确定按钮 * 往a,b放入数据,在b中回车,则在c中显示a+b的值 * b,确定按钮设为监视器 * 需要用try-catch判断输入是否合法 * * */public class WindowsActionEvent extends JFrameJTextField text_1, text_2, text_3;JButton button;ActionListener listener;/接口回调WindowsActionEvent() setTitle(处理事件);setSize(300, 200);setLayout(new FlowLayout();text_1 = new JTextField(20);text_2 = new JTextField(20);text_3 = new JTextField(20);button = new JButton(確定);add(text_1);add(text_2);add(text_3);add(button);listener=new ReadListener();(ReadListener) listener).setJTextField(text_1,text_2,text_3,button);text_2.addActionListener(listener);button.addActionListener(listener);setVisible(true);validate();setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);/ReadListener.javapackage com.example.test;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import javax.swing.JButton;import javax.swing.JTextField;public class ReadListener implements ActionListene

温馨提示

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

评论

0/150

提交评论