java图形界面实验报告

合集下载

南邮Java实验报告1-综合图形界面程序设计

南邮Java实验报告1-综合图形界面程序设计

南邮Java实验报告1-综合图形界面程序设计英文回答:Firstly, I would like to express my sincere gratitudeto my instructor for providing me with the opportunity to work on this Java programming project, which focuses on the design of a comprehensive graphical user interface (GUI). Throughout this project, I have gained valuable experiencein developing a user-friendly and visually appealing application that meets the specified requirements.To begin with, I started by gathering the necessary requirements and understanding the problem statement. Ithen proceeded to design the GUI layout and create the corresponding Java classes and methods. I utilized various Java Swing components, such as buttons, text fields, labels, and panels, to construct a user-friendly interface. Additionally, I implemented event handling mechanisms to respond to user interactions and perform appropriateactions.During the development process, I encountered several challenges. One of the challenges was ensuring that the GUI was responsive and user-friendly. I addressed this by carefully designing the layout and implementing efficient event handling mechanisms. Another challenge was handling complex user interactions and data validation. I overcame this by using appropriate data structures and algorithms to validate user input and perform the required operations.To further enhance the user experience, I incorporated custom graphics and animations. I created custom icons and images to enhance the visual appeal of the application. I also implemented animations to provide visual feedback to users. By incorporating these elements, I aimed to create an engaging and immersive experience for the users.In addition to the technical aspects of the project, I also focused on adhering to coding conventions and best practices. I used proper naming conventions, indentation, and commenting throughout my code. This ensured the codewas readable, maintainable, and extensible.Overall, working on this Java GUI programming project has been a rewarding experience. I have learned a great deal about GUI design, event handling, and the implementation of custom graphics and animations. I am confident that the knowledge and skills I have acquired through this project will be invaluable in my future endeavors as a software developer.中文回答:首先,我谨向我的导师在这次Java编程项目中提供给我的机会表示由衷的感谢。

JAVA-SWING图形界面程序设计实验报告(附完整代码)

JAVA-SWING图形界面程序设计实验报告(附完整代码)

图形界面(GUI)程序设计一、课题内容和要求内容:设计和编写一个用于将人民币转换为等值的美元的程序,界面要求可以输入人民币的金额并可以得到转换后的结果。

要求:学习和理解JAVA SWING中的容器,部件,布局管理器和部件事件处理方法。

通过编写和调试程序,掌握JAVA图形界面程序设计的基本方法。

二、设计思路分析class RMBtoDollar:主类,调用主函数。

class change:设置界面,并通过界面上的事件触发实现汇率转换。

三、概要设计public class RMBtoDollar{public static void main(String[] args);}class change extends JFrame implements MouseListener { JLabel l1, l2,l3;JTextField tf1, tf2;JButton b;double RMB, Dollar;public change();public void mousePressed(MouseEvent e);public void mouseClicked(MouseEvent e);public void mouseEntered(MouseEvent e);public void mouseExited(MouseEvent e);public void mouseReleaseed(MouseEvent e);//鼠标释放时进行转换}四、详细设计import java.awt.*;import java.awt.event.*;import javax.swing.*;public class RMBtoDollar {public static void main(String[] args) {new change();}}class change extends JFrame implements MouseListener { JLabel l1, l2,l3;JTextField tf1, tf2;JButton b;double RMB, Dollar;public change() {//添加组件和设置布局l1 = new JLabel("人民币/元:");l2 = new JLabel("美元/dollar:");l3=new JLabel("(汇率:6.17)");tf1 = new JTextField(12);tf2 = new JTextField(12);b = new JButton("转换");add(l1);add(tf1);add(l2);add(tf2);add(l3);add(b);setLayout(new FlowLayout(FlowLayout.CENTER));setTitle("人民币转换为美元");setBounds(300, 300, 300, 150);setVisible(true);setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);b.addMouseListener(this);//鼠标事件监视器}public void mousePressed(MouseEvent e) {if (tf2.getText() != null) {// tf2 test 默认初始设为空tf2.setText("");}}public void mouseClicked(MouseEvent e) {}public void mouseEntered(MouseEvent e) {}public void mouseExited(MouseEvent e) {}public void mouseReleased(MouseEvent e) {if (tf1.getText() != null) {// 检查tf1 test 是否为空try {// 取异常RMB = Double.parseDouble(tf1.getText());// 字符转为double型Dollar = RMB / 6.17;//转换tf2.setText("" + Dollar);// 显示} catch (Exception ex) {tf1.setText("");// 如果输入不是数字,设为空}}}}五、测试数据及其结果分析1正常输入:2输入字符串不能转为double型时清空输入框:3结果:输出正常。

Java图形用户界面实验报告

Java图形用户界面实验报告

西安邮电大学(计算机学院)课内实验报告实验名称:图形用户界面专业名称:计算机科学与技术班级:计科1405班学生姓名:高宏伟学号:04141152指导教师:刘霞林实验日期:2016.11.24一、实验目的了解图形用户界面基本组件窗口、按钮、文本框、选择框、滚动条等的使用方法,了解如何使用布局管理器对组件进行管理,以及如何使用Java 的事件处理机制。

二、实验要求1. 掌握使用布局管理器对组件进行管理的方法。

2. 理解Java 的事件处理机制,掌握为不同组件编写事件处理程序的方法。

3. 掌握编写独立运行的窗口界面的方法。

4. 掌握组件的使用方法。

5. 了解对话框的使用方法。

三、实验内容(一)算术测试。

✧实验要求:编写一个算术测试小软件,用来训练小学生的算术能力。

程序由3个类组成,其中Teacher类对象负责给出算术题目,并判断回答者的答案是否正确;ComputerFrame类对象负责为算术题目提供视图,比如用户可以通过ComputerFrame类对象提供的GUI界面看到题目,并通过该GUI界面给出题目的答案;MainClass是软件的主类。

✧程序模板:Teacher.javapublic class Teacher{ int numberOne,numberTwo;String operator="";boolean right;public int giveNumberOne(int n){ numberOne=(int)(Math.random()*n)+1;return numberOne;}public int giveNumberT wo(int n){ numberTwo=(int)(Math.random()*n)+1;return numberTwo;}public String giveOperator(){ double d=Math.random();if(d>=0.5)operator="+";elseoperator="-";return operator;}public boolean getRight(int answer){ if(operator.equals("+")){ if(answer==numberOne+numberTwo)right=true;elseright=false;}else if(operator.equals("-")){ if(answer==numberOne-numberTwo)right=true;elseright=false;}return right;}}ComputerFrame.javaimport java.awt.*;import java.awt.event.*;public class ComputerFrame extends Frame implements ActionListener { TextField textOne,textTwo,textResult;Button getProblem,giveAnwser;Label operatorLabel,message;Teacher teacher;ComputerFrame(String s){ super(s);teacher=new Teacher();setLayout(new FlowLayout());textOne=【代码1】 //创建textOne,其可见字符长是10textTwo=【代码2】 //创建textTwo,其可见字符长是10textResult=【代码3】 //创建textResult,其可见字符长是10operatorLabel=new Label("+");message=new Label("你还没有回答呢");getProblem=new Button("获取题目");giveAnwser=new Button("确认答案");add(getProblem);add(textOne);add(operatorLabel);add(textTwo);add(new Label("="));add(textResult);add(giveAnwser);add(message);textResult.requestFocus();textOne.setEditable(false);textTwo.setEditable(false);【代码4】//将当前窗口注册为getProblem的ActionEvent事件监视器【代码5】//将当前窗口注册为giveAnwser的ActionEvent事件监视器【代码6】//将当前窗口注册为textResult的ActionEvent事件监视器 setBounds(100,100,450,100);setVisible(true);validate();addWindowListener(new WindowAdapter(){ public void windowClosing(WindowEvent e) { System.exit(0);}});}public void actionPerformed(ActionEvent e){ if(【代码7】) //判断事件源是否是getProblem{ int number1=teacher.giveNumberOne(100);int number2=teacher.giveNumberTwo(100);String operator=teacher.givetOperator();textOne.setText(""+number1);textTwo.setText(""+number2);operatorLabel.setText(operator);message.setText("请回答");textResult.setText(null);}if(【代码8】) //判断事件源是否是giveAnwser{ String answer=textResult.getText();try{int result=Integer.parseInt(answer);if(teacher.getRight(result)==true){ message.setText("你回答正确");}else{ message.setText("你回答错误");}}catch(NumberFormatException ex){ message.setText("请输入数字字符");}}textResult.requestFocus();validate();}}MainClass.javapublic class MainClass{ public static void main(String args[]){ ComputerFrame frame;frame=【代码9】//创建窗口,其标题为:算术测试}}✧实验后的练习:1. 给上述程序增加测试乘、除的功能。

南邮Java实验报告1-综合图形界面程序设计

南邮Java实验报告1-综合图形界面程序设计

南邮Java实验报告1-综合图形界面程序设计英文回答:Hello, I'm glad to help you with your Java lab report on comprehensive graphical user interface programming.In this report, I will provide a detailed description of the steps I took to create a graphical user interface (GUI) for a simple application. I will also include screenshots of the GUI and discuss the challenges I faced and how I overcame them.Step 1: Create a new Java project。

The first step was to create a new Java project in my preferred development environment. I used IntelliJ IDEA, but you can use any IDE that you are comfortable with.Step 2: Design the GUI。

Once I had created a new project, I began designing the GUI. I sketched out a rough draft on paper and then usedthe Swing library to create the actual GUI.The Swing library provides a set of components that can be used to create GUIs. These components include buttons, text fields, labels, and menus.Step 3: Add functionality to the GUI。

java图形界面实验报告1

java图形界面实验报告1

河南工业大学实验报告专业班级: 计科F1401 学号: 姓名:实验单元八【实验目的】1.掌握程序设计方法2.掌握程序设计方法3.掌握程序设计方法4.掌握程序设计方法5、掌握使用????程序设计方法。

【实验环境】安装了jdk软件的PC机。

【实验内容】第18章、图形界面。

【程序功能内容说明】设置标签的显示字体、大小背景及颜色。

【实验程序原码】import java.awt.Dimension ;import java.awt.Color ;import java.awt.Font ;import java.awt.Point ;import javax.swing.JLabel ;import javax.swing.JFrame ;public class JLabelDemo02{public static void main(String args[]){JFrame frame = new JFrame("Welcome To MLDN") ;JLabel lab = new JLabel("MLDN",JLabel.CENTER) ; // 实例化标签对象Font fnt = new Font("Serief",Font.ITALIC + Font.BOLD,28) ;lab.setFont(fnt) ;frame.add(lab) ; // 将组件件入到面板之中Dimension dim = new Dimension() ;frame.setBackground(Color.WHITE) ;//设置窗体的背景颜色dim.setSize(200,70) ;frame.setSize(dim) ;Point point = new Point(300,200) ; // 设置坐标frame.setLocation(point) ;frame.setVisible(true) ;}};【实验结果】【该程序关键技术说明】JFrame作为基本容器用于创建窗口。

java实验报告

java实验报告

java实验报告Java实验报告实验名称:Java图形界面编程实验对象:Java初学者实验目的:通过实际操作掌握Java图形界面编程的基本知识和技巧实验过程:1. 实验准备:安装Java JDK开发环境,并准备好IDE工具(如Eclipse或IntelliJ IDEA)2. 创建工程:打开IDE工具,新建一个Java工程,并指定工程名和保存路径3. 创建界面:在工程上新建一个Java类,命名为"MainUI"4. 设计界面:在"MainUI"类中使用Swing或JavaFX等GUI库,设计界面布局和组件5. 添加事件监听:在"MainUI"类中添加事件监听器,使组件与逻辑代码进行关联6. 编写逻辑代码:在"MainUI"类中编写逻辑代码,实现界面交互和功能实现7. 编译运行:将工程编译成可执行文件,并运行程序,查看界面效果和功能是否符合预期8. 调试修复:根据实际运行情况,对代码进行调试和修复,确保程序的稳定性和正确性9. 测试验证:使用不同输入数据对程序进行测试,验证程序的鲁棒性和准确性10. 总结反思:对实验过程进行总结和反思,提出改进和优化的建议实验结果:通过实验,我成功创建了一个简单的Java图形界面程序,并实现了基本的交互和功能。

在界面设计方面,我使用了Swing库进行布局和组件的添加,通过事件监听器实现了按钮点击和文本框输入的监听。

在逻辑代码方面,我实现了简单的计算器功能,能够进行加减乘除等基本运算。

通过测试验证,程序运行稳定,结果准确。

实验心得:通过这次实验,我对Java图形界面编程有了更深入的了解和掌握。

我学会了使用Swing或JavaFX等库进行界面设计,以及如何添加事件监听器和编写逻辑代码。

通过实际操作,我发现编写图形界面程序相对于命令行程序更加复杂,需要考虑到用户的交互和界面布局,还需要注意代码的可读性和可维护性。

南邮Java实验报告1-综合图形界面程序设计

南邮Java实验报告1-综合图形界面程序设计

南邮Java实验报告1-综合图形界面程序设

自查报告。

在本次实验中,我设计了一个综合图形界面程序,实现了基本的图形绘制、文本输入和按钮操作功能。

在完成实验过程中,我对自己的工作进行了自查,总结如下:
1. 程序功能完整性,在实验中,我确保了程序能够实现基本的图形绘制、文本输入和按钮操作功能,并且能够正确响应用户的操作。

我对每个功能模块进行了测试,确保程序的功能完整性。

2. 界面美观度,在设计界面时,我注重了界面的美观度和用户体验,保证了界面的布局合理,颜色搭配和图形元素的大小比例协调,使得用户操作起来更加舒适。

3. 代码规范性,在编写代码时,我遵循了Java编程规范,命名规范和代码风格规范,确保了代码的可读性和可维护性。

我对代码进行了注释,方便他人阅读和理解。

4. 错误处理和异常处理,在程序中,我对用户的输入和操作进
行了错误处理和异常处理,保证了程序的稳定性和健壮性。

当用户
输入错误或者操作不当时,程序能够给出相应的提示或者处理方式。

5. 性能优化,在编写程序时,我尽量避免了冗余的代码和不必
要的计算,保证了程序的性能优化。

我对程序进行了性能测试,确
保程序能够在各种情况下都能够正常运行。

通过这次自查,我发现了一些不足之处,比如界面美观度还有
待提高,代码规范性需要进一步加强等。

在今后的学习和实践中,
我会继续努力改进自己的不足之处,提高自己的编程能力和程序设
计水平。

同时,我也会继续关注Java编程技术的发展,不断学习和
掌握新的知识和技能,为自己的成长和发展打下更加坚实的基础。

java图形用户界面实验报告

java图形用户界面实验报告

java图形用户界面实验报告Java图形用户界面实验报告一、引言图形用户界面(Graphical User Interface,简称GUI)是现代软件开发中不可或缺的一部分。

通过GUI,用户能够直观地与程序进行交互,提高了软件的易用性和用户体验。

本实验旨在通过使用Java编程语言,实现一个简单的GUI应用程序,并介绍相关的技术和方法。

二、实验目标本实验的目标是设计并实现一个简单的GUI应用程序,要求具备以下功能:1. 显示一个窗口,并在窗口中心显示一个标签;2. 在窗口中添加一个按钮,并实现按钮的点击事件;3. 当按钮被点击时,标签的文本发生变化。

三、实验过程1. 环境准备在开始实验之前,需要确保已经安装了Java开发环境(JDK)和集成开发环境(IDE),例如Eclipse或IntelliJ IDEA。

2. 创建GUI应用程序首先,创建一个Java项目,并创建一个名为"GUIApplication"的类。

在该类中,引入Java的GUI库,并继承JFrame类,实现一个窗口。

3. 设计窗口布局在窗口的构造方法中,设置窗口的标题、大小和关闭方式。

然后,创建一个JPanel对象,并将其添加到窗口中。

在JPanel中,使用布局管理器(例如FlowLayout或GridBagLayout)来安排组件的位置和大小。

4. 添加标签和按钮在JPanel中,创建一个JLabel对象,并设置其文本和位置。

然后,创建一个JButton对象,并设置其文本和点击事件。

在点击事件中,通过修改JLabel的文本来实现标签内容的变化。

5. 运行程序完成以上步骤后,编译并运行程序。

将会显示一个窗口,其中包含一个标签和一个按钮。

当按钮被点击时,标签的文本会发生变化。

四、实验结果经过以上步骤,成功实现了一个简单的GUI应用程序。

运行程序后,窗口显示如下图所示:(插入程序运行截图)在窗口中心显示了一个标签,标签的文本为"Hello, GUI!"。

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

河南工业大学实验报告专业班级:计科F1401 学号:姓名:实验单元八【实验目的】1、掌握程序设计方法2、掌握程序设计方法3、掌握程序设计方法4、掌握程序设计方法5、掌握使用?程序设计方法。

【实验环境】安装了jdk软件的PC机。

【实验内容】第18章、图形界面。

【程序功能内容说明】设置标签的显示字体、大小背景及颜色。

【实验程序原码】import java.awt.Dimension ;import java.awt.Color ;import java.awt.Font ;import java.awt.Point ;import javax.swing.JLabel ;import javax.swing.JFrame ;public class JLabelDemo02{public static void main(String args[]){JFrame frame = new JFrame("Welcome To MLDN") ;JLabel lab = new JLabel("MLDN",JLabel.CENTER) ; // 实例化标签对象Font fnt = new Font("Serief",Font.ITALIC + Font.BOLD,28) ;lab.setFont(fnt) ;frame.add(lab) ; // 将组件件入到面板之中Dimension dim = new Dimension() ;frame.setBackground(Color.WHITE) ;//设置窗体的背景颜色dim.setSize(200,70) ;frame.setSize(dim) ;Point point = new Point(300,200) ; // 设置坐标frame.setLocation(point) ;frame.setVisible(true) ;}};【实验结果】【该程序关键技术说明】JFrame作为基本容器用于创建窗口。

JLabel作为标签组件用于在窗口上的显示。

【程序功能内容说明】设置GridLayout用于加入按钮。

【实验程序原码】import java.awt.GridLayout ;import javax.swing.JFrame ;import javax.swing.JButton ;public class GridLayoutDemo01{public static void main(String args[]){JFrame frame = new JFrame("Welcome To MLDN") ;frame.setLayout(new GridLayout(3,5,3,3)) ;JButton but = null ;for(int i=0;i<13;i++){but = new JButton("按钮-"+ i) ;frame.add(but) ;}frame.pack() ;frame.setVisible(true) ;}};【实验结果】【该程序关键技术说明】按钮组件JButton用于定义按钮。

GridLayout布局管理器用于摆放多个按钮。

【程序功能内容说明】用户登录系统。

【实验程序原码】import java.awt.event.WindowAdapter ;import java.awt.event.ActionListener ;import java.awt.event.WindowEvent ;import java.awt.event.ActionEvent ;import java.awt.Color ;import java.awt.GridLayout ;import java.awt.Font ;import javax.swing.JFrame ;import javax.swing.JButton ;import javax.swing.JLabel ;import javax.swing.JTextField ;import javax.swing.JPasswordField ;import javax.swing.JPanel ;class LoginCheck{private String name ;private String password ;public LoginCheck(String name,String password){ = name ;this.password = password ;}public boolean validate(){if("lixinghua".equals(name)&&"mldn".equals(password)){ return true ;}else{return false ;}}};class ActionHandle{private JFrame frame = new JFrame("Welcome To MLDN") ;private JButton submit = new JButton("登陆");private JButton reset = new JButton("重置");private JLabel nameLab = new JLabel("用户名:") ;private JLabel passLab = new JLabel("密码:") ;private JLabel infoLab = new JLabel("用户登陆系统") ;private JTextField nameText = new JTextField(10) ;private JPasswordField passText = new JPasswordField() ;private JPanel pan = new JPanel() ;public ActionHandle(){Font fnt = new Font("Serief",Font.ITALIC + Font.BOLD,12) ;infoLab.setFont(fnt) ; // 设置标签的显示文字submit.addActionListener(new ActionListener(){public void actionPerformed(ActionEvent e){if(e.getSource()==submit){String tname = nameText.getText() ;String tpass = new String(passText.getPassword()) ;LoginCheck log = new LoginCheck(tname,tpass) ;if(log.validate()){infoLab.setText("登陆成功,欢迎光临!") ;}else{infoLab.setText("登陆失败,错误的用户名或密码!") ;}}}}) ;reset.addActionListener(new ActionListener(){public void actionPerformed(ActionEvent e){if(e.getSource()==reset){nameText.setText("") ;passText.setText("") ;infoLab.setText("用户登陆系统") ;}}}) ;frame.addWindowListener(new WindowAdapter(){public void windowClosing(WindowEvent e){System.exit(1) ;}}) ; // 加入事件frame.setLayout(null) ;nameLab.setBounds(5,5,60,20) ;passLab.setBounds(5,30,60,20) ;infoLab.setBounds(5,65,220,30) ;nameText.setBounds(65,5,100,20) ;passText.setBounds(65,30,100,20) ;submit.setBounds(165,5,60,20) ;reset.setBounds(165,30,60,20) ;frame.add(nameLab) ;frame.add(passLab) ;frame.add(infoLab) ;frame.add(nameText) ;frame.add(passText) ;frame.add(submit) ;frame.add(reset) ;frame.setSize(280,130) ;frame.setBackground(Color.WHITE) ;frame.setLocation(300,200) ;frame.setVisible(true) ;}};public class MyActionEventDemo03{public static void main(String args[]){new ActionHandle() ;}};【实验结果】【该程序关键技术说明】JFame、JLabel、JButton等综合应用,实现窗口的显示、输入、按钮等。

【程序功能内容说明】建立表格。

【实验程序原码】import java.awt.event.WindowAdapter ;import java.awt.event.WindowEvent ;import javax.swing.JTable ;import javax.swing.JScrollPane ;import javax.swing.JFrame ;public class JTableDemo01{public static void main(String args[]){JFrame frame = new JFrame("Welcome To MLDN") ;String[] titles = {"姓名","年龄","性别","数学成绩","英语成绩","总分","是否及格"} ;Object [][] userInfo = {{"李兴华",30,"男",89,97,186,true} ,{"李康",23,"女",90,93,183,false}} ; // 定义数据JTable table = new JTable(userInfo,titles) ; // 建立表格JScrollPane scr = new JScrollPane(table) ;frame.add(scr) ;frame.setSize(370,90) ;frame.setVisible(true) ;frame.addWindowListener(new WindowAdapter(){public void windowClosing(WindowEvent e){System.exit(1) ;}}) ;}}【实验结果】【该程序关键技术说明】JTable建立表格。

相关文档
最新文档