实验二之实验报告_第1页
实验二之实验报告_第2页
实验二之实验报告_第3页
实验二之实验报告_第4页
实验二之实验报告_第5页
已阅读5页,还剩8页未读 继续免费阅读

下载本文档

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

文档简介

1、 Ssd4实验二之实验报告一、 实验目的:1、 为了进一步了解布局的作用,及重要性2、 学习分析软件功能,及布局实现3、 加强对java的了解二、 实验要求:1、 模拟出界面2、 实现其所有功能(1) 焦点设置(2) 事件监听设置,文本框内容变化监听,按钮监听(3) 字体设置(4) 对话框信息提示设置三、 实验步骤:1、 研究布局,模拟布局,测绘2、 组件属性设置3、 功能分析4、 实现功能四、 实验结果:源代码:package .gui;import javax.swing.*;import javax.swing.event.CaretEvent;import ja

2、vax.swing.event.CaretListener;import javax.swing.event.ChangeEvent;import javax.swing.event.ChangeListener;import java.awt.event.ActionEvent;import java.awt.event.TextListener;import java.awt.event.TextEvent;import java.awt.*;import java.awt.event.ActionListener;import .util.*;public cla

3、ss MainFrame extends JFrameprivate JLabel labComponentNames;private JLabel labComponentDescription; private JLabel labFirstName; private JLabel labSecondName; private JLabel labThirdName; private JLabel labForthName; private JLabel labFifthName; private JLabel labSixName; private JLabel labSevenName

4、; private JLabel labEnterNumber; private JLabel labEnterString; private JLabel labFound; private JLabel labFirstOccurrence; private JLabel labLastOccurrence; private TextField textDisplay; private TextField textSearch; private JTextArea textComponentDescription; private JButton butDisplay; private J

5、Button butSearch; private JButton butExit; private JPanel paneMain; private JPanel paneComponent; private JPanel paneComponentNames; private JPanel paneComponentDescription; private JPanel paneEnter; private JPanel paneFound; private JPanel paneExit; private JScrollPane scrollPane; private int count

6、;public MainFrame()labComponentNames = new JLabel(UAR components names:);/将字体设置为粗体/labComponentName.setFont();/labFirstName = new JLabel(1. UAR Identifier);labSecondName = new JLabel(2. Succinct Descripition of the Usability Aspect);labThirdName = new JLabel(3. Evidence for the Aspect);labForthName

7、= new JLabel(4. Explanation of the Aspect);labFifthName = new JLabel(5. severity of the Problem or the Benefit of the Good Feature);labSixName = new JLabel(6. Possible Solutions and Potential Trade-offs);labSevenName = new JLabel(7. Relationship to Other Usability Aspects);labEnterNumber = new JLabe

8、l(Enter a number:);labEnterString = new JLabel(Enter a search string:);butDisplay = new JButton(Display);butSearch = new JButton(Search);butExit = new JButton(Exit);labComponentDescription = new JLabel(UAR component description:);labFound = new JLabel(Found at:);labFirstOccurrence = new JLabel();lab

9、LastOccurrence = new JLabel();textDisplay = new TextField();textSearch = new TextField();textComponentDescription = new JTextArea();paneMain = new JPanel();paneComponent = new JPanel();paneComponentNames = new JPanel();paneComponentDescription = new JPanel();paneEnter = new JPanel();paneFound = new

10、JPanel();paneExit = new JPanel();scrollPane = new JScrollPane();init();/必须在窗口显示后才能获得焦点textDisplay.requestFocusInWindow();private void init() /textDisplay.set/textSearch.setBorder(BorderFactory.createLoweredBevelBorder();paneComponentNames.setLayout(new GridLayout(9,1);paneComponentNames.add(labCompo

11、nentNames);Font font = new Font(null,Font.BOLD,15);/Font butFont = new Font(null,Font.ROMAN_BASELINE,12);labComponentNames.setFont(font);labComponentDescription.setFont(font);paneComponentNames.add(labFirstName);paneComponentNames.add(labSecondName);paneComponentNames.add(labThirdName);paneComponent

12、Names.add(labForthName);paneComponentNames.add(labFifthName);paneComponentNames.add(labSixName);paneComponentNames.add(labSevenName);/布局scrollPane.setViewportView(textComponentDescription);scrollPane.setVerticalScrollBarPolicy(scrollPane.VERTICAL_SCROLLBAR_ALWAYS);scrollPane.setBorder(BorderFactory.

13、createLoweredBevelBorder();JPanel myPane = new JPanel();myPane.setLayout(new BorderLayout();myPane.add(new JPanel(),BorderLayout.NORTH);myPane.add(scrollPane,BorderLayout.CENTER);myPane.add(new JPanel(),BorderLayout.SOUTH);myPane.add(new JPanel(),BorderLayout.EAST);paneComponentDescription.setLayout

14、(new BorderLayout();paneComponentDescription.add(labComponentDescription,BorderLayout.NORTH);paneComponentDescription.add(myPane,BorderLayout.CENTER);paneComponentDescription.add(labFound,BorderLayout.SOUTH);/paneEnter面板布局JPanel thirdPane = new JPanel();JPanel thirdPane2 =new JPanel();JPanel thirdPa

15、ne3 = new JPanel();JPanel thirdPane4 = new JPanel();JPanel thirdPane5 = new JPanel();thirdPane.setLayout(new BorderLayout();thirdPane.add(new JPanel(),BorderLayout.NORTH);thirdPane.add(thirdPane2,BorderLayout.CENTER);thirdPane2.setLayout(new BorderLayout();thirdPane2.add(thirdPane3,BorderLayout.NORT

16、H);thirdPane3.setLayout(new BorderLayout();thirdPane3.add(paneEnter,BorderLayout.CENTER);thirdPane3.add(thirdPane4,BorderLayout.EAST);thirdPane4.setLayout(new BorderLayout();thirdPane4.add(new JPanel(),BorderLayout.WEST);thirdPane4.add(thirdPane5,BorderLayout.CENTER);thirdPane4.add(new JPanel(),Bord

17、erLayout.EAST);thirdPane5.setLayout(new GridLayout(2,1);paneEnter.setLayout(new GridLayout(2,2);paneEnter.add(labEnterNumber);paneEnter.add(textDisplay);paneEnter.add(labEnterString);paneEnter.add(textSearch);thirdPane5.add(butDisplay);thirdPane5.add(butSearch);/paneFound面板布局JPanel forthPane =new JP

18、anel();JPanel forthPane2 = new JPanel();JPanel forthPane3 = new JPanel();forthPane.setLayout(new FlowLayout(FlowLayout.RIGHT);forthPane2.setLayout(new BorderLayout();forthPane3.setLayout(new GridLayout(3,1);forthPane3.add(labFirstOccurrence);forthPane3.add(new JPanel();forthPane3.add(labLastOccurren

19、ce);forthPane.add(butExit);paneFound.setLayout(new BorderLayout();paneFound.add(new JPanel(),BorderLayout.NORTH);paneFound.add(forthPane2,BorderLayout.CENTER);forthPane2.add(forthPane3,BorderLayout.NORTH);paneFound.add(forthPane,BorderLayout.SOUTH);/paneEnterAndFound.add(comp);/paneEnterAndFound.add

20、(comp);/paneEnterAndFound.add(comp);/paneEnterAndFound.add(comp);paneComponent.setLayout(new GridLayout(2,2);paneComponent.add(paneComponentNames);paneComponent.add(paneComponentDescription);paneComponent.add(thirdPane);paneComponent.add(paneFound);paneMain.setLayout(new BorderLayout();paneMain.add(

21、paneComponent,BorderLayout.CENTER);this.add(new JPanel(),BorderLayout.NORTH);this.add(new JPanel(),BorderLayout.SOUTH);this.add(paneMain,BorderLayout.CENTER);this.add(new JPanel(),BorderLayout.WEST);this.add(new JPanel(),BorderLayout.EAST);/butDisplay.setFont(butFont);butDisplay.addActionListener(ne

22、w MyListener();butSearch.addActionListener(new MyListener();butExit.addActionListener(new MyListener();textDisplay.addTextListener(new MyTextListener();textSearch.addTextListener(new MyTextListener();/ TODO Auto-generated method stubthis.setSize(880,500);/将显示出来的大小作为最小尺寸this.setMinimumSize(getSize();

23、this.setTitle(URA Components);this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);this.setLocationRelativeTo(null);this.setVisible(true);public int getStringCount(String str1,String str2)String s = str1;count =0;if(str2.length()!=1)for(int i=0;is.length();i+)if(s.indexOf(str2)!=-1)s=s.substring(s.in

24、dexOf(str2)+1);count+;elseint i=0,j=0;i=s.length();s=s.replaceAll(str2,);/反串中的字符a替换成 ,使其长度减一.s=s.replaceAll(str2.toUpperCase(),);/System.out.println(s);j=s.length(); count=i-j;return count;class MyListener implements ActionListenerpublic void actionPerformed(ActionEvent e)Text text = new Text();JBut

25、ton but =(JButton)e.getSource();if(but = butDisplay)try/传递焦点textDisplay.transferFocus();textComponentDescription.setText();textComponentDescription.setText(text.textInteger.parseInt(textDisplay.getText().trim()-1);textComponentDescription.setLineWrap(true);catch(Exception ex)JOptionPane.showMessageD

26、ialog(null, Please enter values between 1 and 7,Search String,JOptionPane.WARNING_MESSAGE);else if(but = butSearch)if(textComponentDescription.getText().equals()|textSearch.getText().equals()JOptionPane.showMessageDialog(null, Please select text,Search String,JOptionPane.WARNING_MESSAGE);return;tryt

27、extSearch.transferFocusBackward();int ncount=getStringCount(textComponentDescription.getText(),textSearch.getText();labFirstOccurrence.setText();labLastOccurrence.setText();if(ncount!=0)labFirstOccurrence.setText(Occurrence +1: +Position: +(textComponentDescription.getText().indexOf(textSearch.getTe

28、xt()+1);labLastOccurrence.setText(Occurrence +ncount+: +Position: +(textComponentDescription.getText().lastIndexOf(textSearch.getText()+1);Object options = 是 ,否;int response=JOptionPane.showOptionDialog(null, The number of occurrences of +textSearch.getText()+ is:+ncount+nn Search same text?,Search

29、String,JOptionPane.YES_OPTION,JOptionPane.WARNING_MESSAGE,null,options,options0);if(response=1)textDisplay.setText();textSearch.setText();labFirstOccurrence.setText();labLastOccurrence.setText();textComponentDescription.setText();else/int optionTypeObject options = 是 ,否;int response=JOptionPane.show

30、OptionDialog(null, String +textSearch.getText()+ not found n Search same text again?,Search String,JOptionPane.YES_OPTION,JOptionPane.WARNING_MESSAGE,null,options,options0);if(response=1)textDisplay.setText();textSearch.setText();textComponentDescription.setText();catch(Exception ex)/butExit.setBord

31、er(BorderFactory.createRaisedBevelBorder();else/butExit.setBorder(BorderFactory.createRaisedBevelBorder();System.exit(0);class MyTextListener implements TextListenerOverridepublic void textValueChanged(TextEvent e) / TODO Auto-generated method stubTextField text =(TextField)e.getSource();if(text=tex

32、tDisplay)textComponentDescription.setText();labFirstOccurrence.setText();labLastOccurrence.setText();textSearch.setText();elselabFirstOccurrence.setText();labLastOccurrence.setText();package .util;public class Text public String text = new String7;public Text()text0=This should be a uniq

33、ue identifier for the purposes of filing. +If more than one person is working on the project or more than one analysis technique is being used, + this identifier could contain letters and numbers. For example, if Chris Smith and Jan Koo are both doing an analysis, +the identifier might be CS1 or JK7

34、5. If both a heuristic evaluation and a think-aloud usability study were used, the identifiers might be HE6 or TA89. + Follow the unique identifier with the word Problem, if the report pertains to a usability problem of the interface, or the words Good Feature, +if it describes an aspect of the inte

35、rface you feel should be preserved in any redesign.;text1=This description will be used as the name of this UAR when you talk about its relation to other UARs. + Make the name as short as possible (about three to five words) but still descriptive and distinguishable from other aspects of the system.

36、 +If this UAR is about a problem (as opposed to a good feature), + make sure you have a name that describes the problem, rather than a solution.;text2=This is the objective supporting material that justifies your identifying the aspect as worthy of report. + This section needs to contain enough info

37、rmation for a reader of this UAR to understand what triggered the report. For an HE report, for instance, + this could be an image of a cluttered screen and the heuristic about aesthetics and minimalist design. +In a think-aloud study this is usually what was on the screen (a screen shot or descript

38、ion), what the user did (keystrokes, mouse movements), +what the system did in response to any user actions, and what the user said. +You need to include enough pertinent information about the identification of an aspect for the reader to understand what the analyst was +thinking when the aspect was

39、 identified (for HE) or what the user was trying to do +when the aspect either hindered or facilitated his or her progress.;text3=This is your interpretation of the evidence. That is, for a think-aloud usability test, +why you think what happened happened, or, for an HE, why you think the aspect was designed the way it was. +You need to provide enough content in this explanation for the reader to understand the problem-even if they do not know the + system or domain as well as you do.;text4=This is your reasoning about how important it is to either fix th

温馨提示

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

评论

0/150

提交评论