用户界面分析与设计(SSD4) 实验二
作者:互联网
Take Assessment: Exercise 2
1.需求分析
(1)显示选定UAR组件内容的说明
① 当用户输入有效的UAR组件列表号并单击“显示”按钮时,应用程序将在“输出”文本框中显示该组件内容的描述。
② 当用户输入无效的输入值或根本不输入值并单击“显示”按钮时,应用程序会通知用户消息框中的错误,这将提示用户从 数字的有效范围(例如,“请输入一个值1到7”),当用户输入一个值时,突出显示无效的输入。
(2)搜索显示的UAR组件内容描述中的关键字或短语
① 当用户输入关键字时,该关键字出现在当前显示在“输出”文本框中的内容描述中,则应用程序应显示该关键字。
关键字第一次出现的位置(从描述开始时的字符数偏移);
以及关键字最后一次出现的位置(从描述开始到字符数的偏移);
一个消息框,指示在内容描述中出现关键字的次数,并询问用户是否要搜索相同的描述以查找不同的关键字。
② 当用户输入关键字而该关键字不存在于当前显示在“输出”文本框中的内容描述中时,应用程序应显示该关键字。
一个消息框,通知用户没有找到字符串,并询问用户是否要搜索相同的描述以寻找不同的关键字。
③ 当用户单击“搜索”按钮但尚未输入关键字时,应用程序应显示提示用户输入关键字的消息框;以及在用户确认提示符后,指示用户输入关键字的位置。
④ 如果用户想要搜索相同的描述以寻找不同的关键字,应用程序应该突出显示(即选择)先前在输入文本中输入的关键字,将用户的位置指向输入新关键字;否则,当用户不想搜索相同的描述时,应用程序应该清除输入文本框的内容,并指示用户如何重新启动搜索过程。
⑤ 当用户输入关键字而当前不显示UAR组件内容描述时,应用程序应该显示消息框,提示用户选择要搜索的UAR组件内容描述;以及指导用户如何继续使用应用程序-也就是说,如果没有输入组件号,应用程序应将焦点设置为默认文本框;否则,应用程序应设置向“显示”按钮显示。
⑥ 当用户单击“退出”按钮时,应用程序应关闭。
2.概要设计
(1)本程序没有涉及抽象数据类型,无定义。
(2)先对程序进行界面设计,与原程序部件、大小、数量等属性设计一致。
(3)实现在Enter a number后面的文本框输入数字1-7,点击Display后,显示对应的文本到文本框中,鼠标自动跳转到Enter a search string后面的文本框中。
(4)当在Enter a number后面的文本框的输入不是数字1-7时,点击Display弹出警告框,提示用户输入数字1-7.
(5)实现在Enter a search string后面的文本框输入任意字符串,点击search按钮,如果文本框存在该字符串,统计该字符串出现的次数,第一次和最后一次出现的位置,显示在Found at下面,同时弹出对话框,显示相关信息,询问用户是否继续对该文本进行搜索,点击确定则回到搜索文本框继续输入,否则对所有输入框清空处理,鼠标回到Enter a number后面的文本框中。
(6)点击search按钮后,先检测搜索框与文本是否含有内容,若文本框没有内容,则弹出警告框告诉用户先选择文本,若搜索字符框没有内容,则弹出警告窗提示用户输入搜索字符串。
(7)设计Exit按钮,点击则退出程序。
(8)设计监听事件,Enter a string后面的文本框内容发生变化时,清空文本框和搜索框的内容。
3.详细设计
(1)先对程序进行界面设计,与原程序部件、大小、数量等属性设计一致。
利用NetBeans的Frame界面直接添加所需的部件并进行界面设计即可。
(2)实现在Enter a number后面的文本框输入数字1-7,点击Display后,显示对应的文本到文本框中,鼠标自动跳转到Enter a search string后面的文本框中。
先用getText()获取该文本框内容,如果是数字1-7之间任意一个,则设计switch语句将对应的文字用setText()输出到文本显示框中。
(3)当在Enter a number后面的文本框的输入不是数字1-7时,点击Display弹出警告框,提示用户输入数字1-7.
利用Integer.parseInt()将文本框中内容转化为数字, 利用try-catch语句,如果可以转化,则输出,反之利用JOptionPane.showMessageDialog()弹出警告框并设计相关语句。
(4)实现在Enter a search string后面的文本框输入任意字符串,点击search按钮,如果文本框存在该字符串,统计该字符串出现的次数,第一次和最后一次出现的位置,显示在Found at下面,同时弹出对话框,显示相关信息,询问用户是否继续对该文本进行搜索,点击确定则回到搜索文本框继续输入,否则对所有输入框清空处理,鼠标回到Enter a number后面的文本框中。
获取文本框中的字符串,利用indexOf()以及substring()函数对文本框的内容进行统计并将相关数据收集显示。弹出的对话框利用JOptionPane.showOptionDialog()设计,点击“是(Y)”是回到输入搜索字符串的文本框并选中文本内容,点击“否(N)”则清空界面所有文本框内容,并将鼠标回到Enter a number后面的文本框中。
(5)点击search按钮后,先检测搜索框与文本是否含有内容,若文本框没有内容,则弹出警告框告诉用户先选择文本,若搜索字符框没有内容,则弹出警告窗提示用户输入搜索字符串。
利用双层嵌套if-else以及JOptionPane.showMessageDialog()即可。
(6)设计Exit按钮,点击则退出程序。
对Exit进行鼠标双击按钮事件设计,输入函数System.exit(WIDTH);即可。
(7)设计监听事件,Enter a string后面的文本框内容发生变化时,清空文本框和搜索框的内容。
因为对于jTextField来说,NetBeans中并没有监听函数,而Document有该函数,对DocumentListener接口中的insertUpdate()、removeUpdate()、changedUpdate()三个函数进行重写,再将jTextField中内容转化到Document中,设置DocumentListener函数,监听到文本变化则清空所有文本内容。
4.调试分析
(1)字符串统计主要利用indexOf()和subString()函数,但是对于循环次数的设计想了很久,最终是利用无限循环,条件为文本不为空,循环时就逐渐利用subString函数缩短文本直至空。
(2)弹出自定义对话框的设计一开始也是bug不断,对于该函数不是很熟悉,后来在百度上找到一篇比较全的关于java swing的对话框设计后解决。(参考链接:消息对话框MessageDialog综合应用:九九表 - - ITeye博客 http://lbsnm.iteye.com/blog/1472914)
(3)对于程序随时感知Enter a number后面文本框的内容变化设计花了很多时间,一开始以为jTextField有监听函数,结果找了很久都没找到,后来又尝试PropertyChange函数,都没有用,之后与室友一起在百度上尝试了很多方案,最终发现Document有监听函数,所以对其方法进行重写,并将jTextField的内容放到Document中就实现了。
5.用户使用说明
6.测试结果
(1)输入正确数字,搜索字符串,弹出信息显示框,显示字符串出现的第一次位置和最后一次位置。
点击“是(Y)”:
点击“否(N)”:
(2)输入错误数字或者字符串,弹出警告窗
(3)未输入搜索字符串或未显示文本,弹出警告窗
未显示文本:
未输入搜索字符串:
(4)直接改变Enter a number后面的文本框,则清空其他两个文本框并隐藏显示文字出现位置的按钮。
(5)未搜索到该字符串。
(6)搜索字符串只出现一次,则只显示第一次出现的位置,不显示最后出现的位置。
7.附录
可参考压缩包 实验二源码 中目录SSD4-program2\src\ssd4\program2下的SSD4_Program2_GUI.java和SSD4_Program2_GUI.form文件。
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package ssd4.program2;
import javax.swing.text.Document;
import javax.swing.JOptionPane;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
/**
*
* @author Summer
*/
public class SSD4_Program2_GUI extends javax.swing.JFrame implements DocumentListener{
@Override
public void insertUpdate(DocumentEvent e) {
jTextArea1.setText("");
jTextField2.setText("");
jLabel13.setVisible(false);
jLabel14.setVisible(false);
}
/**
* 实现DocumentListener接口removeUpdate方法
* 该方法可以跟踪文本框中移除的内容,例如:在文本框中点击Backspace
*/
@Override
public void removeUpdate(DocumentEvent e) {
jTextArea1.setText("");
jTextField2.setText("");
jLabel13.setVisible(false);
jLabel14.setVisible(false);
}
/**
* 实现DocumentListener接口changedUpdate方法
* 该方法可以跟踪当文本框中已存在的内容改变时,获取相应的值
*/
@Override
public void changedUpdate(DocumentEvent e) {
jTextArea1.setText("");
jTextField2.setText("");
jLabel13.setVisible(false);
jLabel14.setVisible(false);
}
/**
* Creates new form NewJFrame
*/
public SSD4_Program2_GUI() {
initComponents();
this.setTitle("UAR Components");
this.jTextField1.requestFocus();
jLabel13.setVisible(false);
jLabel14.setVisible(false);
}
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
jPanel1 = new javax.swing.JPanel();
jButton3 = new javax.swing.JButton();
jLabel14 = new javax.swing.JLabel();
jLabel13 = new javax.swing.JLabel();
jButton2 = new javax.swing.JButton();
jButton1 = new javax.swing.JButton();
jLabel10 = new javax.swing.JLabel();
jLabel11 = new javax.swing.JLabel();
jTextField1 = new javax.swing.JTextField();
jTextField2 = new javax.swing.JTextField();
jLabel12 = new javax.swing.JLabel();
jScrollPane1 = new javax.swing.JScrollPane();
jTextArea1 = new javax.swing.JTextArea();
jLabel7 = new javax.swing.JLabel();
jLabel6 = new javax.swing.JLabel();
jLabel5 = new javax.swing.JLabel();
jLabel4 = new javax.swing.JLabel();
jLabel3 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
jLabel1 = new javax.swing.JLabel();
jLabel8 = new javax.swing.JLabel();
jLabel9 = new javax.swing.JLabel();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setPreferredSize(new java.awt.Dimension(890, 510));
jPanel1.setPreferredSize(new java.awt.Dimension(705, 305));
jPanel1.setRequestFocusEnabled(false);
jButton3.setText("Exit");
jButton3.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
jButton3MouseClicked(evt);
}
});
jButton3.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton3ActionPerformed(evt);
}
});
jLabel14.setFont(new java.awt.Font("宋体", 0, 14)); // NOI18N
jLabel14.setText("jLabel14");
jLabel13.setFont(new java.awt.Font("宋体", 0, 14)); // NOI18N
jLabel13.setText("jLabel13");
jButton2.setText("Search");
jButton2.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
jButton2MouseClicked(evt);
}
});
jButton2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton2ActionPerformed(evt);
}
});
jButton1.setText("Display");
jButton1.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
jButton1MouseClicked(evt);
}
});
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});
jLabel10.setFont(new java.awt.Font("宋体", 0, 14)); // NOI18N
jLabel10.setText("Enter a number:");
jLabel11.setFont(new java.awt.Font("宋体", 0, 14)); // NOI18N
jLabel11.setText("Enter a search string:");
jTextField1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jTextField1ActionPerformed(evt);
}
});
jTextField1.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
public void propertyChange(java.beans.PropertyChangeEvent evt) {
jTextField1PropertyChange(evt);
}
});
jTextField2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jTextField2ActionPerformed(evt);
}
});
jTextField2.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
public void propertyChange(java.beans.PropertyChangeEvent evt) {
jTextField2PropertyChange(evt);
}
});
jLabel12.setFont(new java.awt.Font("宋体", 0, 14)); // NOI18N
jLabel12.setText("Found at:");
jTextArea1.setColumns(20);
jTextArea1.setLineWrap(true);
jTextArea1.setRows(5);
jScrollPane1.setViewportView(jTextArea1);
jLabel7.setFont(new java.awt.Font("宋体", 0, 14)); // NOI18N
jLabel7.setText("7. Relationship to Other Usability Aspects");
jLabel6.setFont(new java.awt.Font("宋体", 0, 14)); // NOI18N
jLabel6.setText("6. Possible Solutions and Potential Trade-offs");
jLabel5.setFont(new java.awt.Font("宋体", 0, 14)); // NOI18N
jLabel5.setText("5. Severity of the Problem or Benefit of the Good Feature");
jLabel4.setFont(new java.awt.Font("宋体", 0, 14)); // NOI18N
jLabel4.setText("4. Explanation of the Aspect");
jLabel3.setFont(new java.awt.Font("宋体", 0, 14)); // NOI18N
jLabel3.setText("3. Evidence for the Aspect");
jLabel2.setFont(new java.awt.Font("宋体", 0, 14)); // NOI18N
jLabel2.setText("2. Succinct Description of the Usability Aspect");
jLabel1.setFont(new java.awt.Font("宋体", 0, 14)); // NOI18N
jLabel1.setText("1. UAR Identitier");
jLabel8.setFont(new java.awt.Font("微软雅黑", 1, 12)); // NOI18N
jLabel8.setText("UAR components names:");
jLabel9.setFont(new java.awt.Font("微软雅黑", 1, 12)); // NOI18N
jLabel9.setText("UAR component description:");
javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGap(22, 22, 22)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel1)
.addComponent(jLabel8)
.addComponent(jLabel2)
.addComponent(jLabel3)
.addComponent(jLabel4)
.addComponent(jLabel6)
.addComponent(jLabel7)
.addComponent(jLabel5, javax.swing.GroupLayout.PREFERRED_SIZE, 413, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addGroup(jPanel1Layout.createSequentialGroup()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGap(22, 22, 22)
.addComponent(jLabel10)
.addGap(64, 64, 64))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
.addContainerGap()
.addComponent(jLabel11)
.addGap(18, 18, 18)))
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(jTextField1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 159, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jTextField2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 159, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 75, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jButton1))))
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGap(18, 18, 18)
.addComponent(jLabel14))
.addGroup(jPanel1Layout.createSequentialGroup()
.addGap(18, 18, 18)
.addComponent(jLabel13))
.addGroup(jPanel1Layout.createSequentialGroup()
.addGap(19, 19, 19)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel9)
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 356, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel12))))
.addContainerGap(70, Short.MAX_VALUE))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
.addGap(0, 0, Short.MAX_VALUE)
.addComponent(jButton3, javax.swing.GroupLayout.PREFERRED_SIZE, 81, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(38, 38, 38))
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addContainerGap()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel9)
.addComponent(jLabel8))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 205, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGroup(jPanel1Layout.createSequentialGroup()
.addComponent(jLabel1)
.addGap(14, 14, 14)
.addComponent(jLabel2)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(jLabel3)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(jLabel4)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(jLabel5)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jLabel6)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(jLabel7)))
.addGap(18, 18, 18)
.addComponent(jLabel12)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGap(19, 19, 19)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jButton1)
.addComponent(jLabel10)))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jLabel13)))
.addGap(18, 18, 18)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel11)
.addComponent(jButton2)
.addComponent(jLabel14))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 70, Short.MAX_VALUE)
.addComponent(jButton3)
.addGap(138, 138, 138))
);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, 880, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(0, 0, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, 590, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap())
);
pack();
}// </editor-fold>
private void jTextField1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
private void jButton1MouseClicked(java.awt.event.MouseEvent evt) {
// TODO add your handling code here:
try{
Integer.parseInt(jTextField1.getText());
}catch(Exception e){
// 不是int
JOptionPane.showMessageDialog(null, "Please enter value between 1 and 7", "Search String", JOptionPane.WARNING_MESSAGE);
jTextField1.requestFocus();
jTextField1.selectAll();
}
int number = Integer.parseInt(jTextField1.getText());
switch(number){
case 1 : {
jTextArea1.setText("This should be a unique 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 JK75. 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 interface you feel should be preserved in any redesign.");
jTextField2.requestFocus();
break;
}
case 2 :{
jTextArea1.setText("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. 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.");
jTextField2.requestFocus();
break;
}
case 3 :{
jTextArea1.setText("This is the objective supporting material that justifies your identifying the aspect as worthy of report. This section needs to contain enough information 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 description), 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 identified (for HE) or what the user was trying to do when the aspect either hindered or facilitated his or her progress.");
jTextField2.requestFocus();
break;
}
case 4 :{
jTextArea1.setText("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.");
jTextField2.requestFocus();
break;
}
case 5 :{
jTextArea1.setText("This is your reasoning about how important it is to either fix this problem or preserve this good feature. This includes how frequently the users will experience this aspect, whether they are likely to learn how it works, whether it will affect new users, casual users, experienced users, etc.");
jTextField2.requestFocus();
break;
}
case 6 :{
jTextArea1.setText("If this aspect is a problem (as opposed to a good feature to be preserved in the next version of the software), this is the place to propose a solution. It is not necessary to have a solution as soon as you identify a problem-you might find after analyzing the whole interface that many problems are related and can all be fixed by making a single broad change instead of making several small changes. However, if you do propose a possible solution, report any potential design trade-offs that you see");
jTextField2.requestFocus();
break;
}
case 7 :{
jTextArea1.setText("It is often the case that UARs are related to each other. This is where you record which UARs this one is related to and a statement about how it is related. Make sure that all the related UARs point to each other. It is a common mistake to enter the pointer into a newly created UAR, but neglect to go back to the previous ones that it relates to and update their UARs.");
jTextField2.requestFocus();
break;
}
default:{
JOptionPane.showMessageDialog(null, "Please enter value between 1 and 7", "Search String", JOptionPane.WARNING_MESSAGE);
jTextField1.requestFocus();
jTextField1.selectAll();
break;
}
}
}
private void jButton3MouseClicked(java.awt.event.MouseEvent evt) {
// TODO add your handling code here:
System.exit(WIDTH);
}
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
private void jButton2MouseClicked(java.awt.event.MouseEvent evt) {
// TODO add your handling code here:
if(jTextArea1.getText().length() == 0 || jTextField1.getText().length() == 0){
JOptionPane.showMessageDialog(null, "Please select text", "Search String", JOptionPane.WARNING_MESSAGE);
jButton1.requestFocus();
}
else if(jTextField2.getText().length() == 0){
JOptionPane.showMessageDialog(null, "Please enter a search String", "Search String", JOptionPane.WARNING_MESSAGE);
jTextField2.requestFocus();
jLabel13.setVisible(false);
jLabel14.setVisible(false);
}
else{
String _sourse = jTextArea1.getText().toLowerCase();
String _search = jTextField2.getText().toLowerCase();
int total = 0;
int first,last;
first = 0;
last = 0;
int countLoop = 0;
for(String temp = _sourse; temp != null && temp.length() >= _search.length(); ){
if(temp.indexOf(_search) == 0){
countLoop += _search.length();
total++;
if(total == 1){
first = countLoop - _search.length() + 1;
}
last = countLoop - _search.length() + 1;
temp = _sourse.substring(countLoop);
}
else{
countLoop += 1;
temp = _sourse.substring(countLoop);
}
}
Object[] options = {"是(Y)","否(N)"};
if(total == 0){
int response = JOptionPane.showOptionDialog(this, "String '"+ _search + "' not found " +total+ "\nSearch same text again?",
"Search String", JOptionPane.YES_OPTION, JOptionPane.WARNING_MESSAGE, null, options, options[0]);
if(response == 0){
jTextField2.requestFocus();
jTextField2.selectAll();
jLabel13.setVisible(false);
jLabel14.setVisible(false);
}
if(response == 1){
jTextField1.setText("");
jTextField2.setText("");
jTextArea1.setText("");
jLabel13.setVisible(false);
jLabel14.setVisible(false);
jTextField1.requestFocus();
}
}
else{
int response = JOptionPane.showOptionDialog(this, "The number of occurences of '"+ _search + "' is: " +total+ "\nSearch same text?",
"Search String", JOptionPane.YES_OPTION, JOptionPane.PLAIN_MESSAGE, null, options, options[0]);
if(response == 0){
jTextField2.requestFocus();
jTextField2.selectAll();
if(total == 1){
jLabel13.setVisible(true);
jLabel13.setText("Occurrence 1: Position: " + first);
}
else{
jLabel13.setVisible(true);
jLabel14.setVisible(true);
jLabel13.setText("Occurrence 1: Position: " + first);
jLabel14.setText("Occurrence " + total + ": Position: " + last);
}
}
if(response == 1){
jTextField1.setText("");
jTextField2.setText("");
jTextArea1.setText("");
jLabel13.setVisible(false);
jLabel14.setVisible(false);
jTextField1.requestFocus();
}
}
}
}
private void jTextField1PropertyChange(java.beans.PropertyChangeEvent evt) {
// TODO add your handling code here:
Document doc = jTextField1.getDocument();
//添加DocumentListener监听器
doc.addDocumentListener(this);
}
private void jTextField2ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
jTextField2.setText(null);
}
private void jTextField2PropertyChange(java.beans.PropertyChangeEvent evt) {
// TODO add your handling code here:
if(jTextField2.isValid()){
jLabel13.setVisible(false);
jLabel14.setVisible(false);
}
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
/* Set the Nimbus look and feel */
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
* For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
*/
try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(SSD4_Program2_GUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(SSD4_Program2_GUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(SSD4_Program2_GUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(SSD4_Program2_GUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
/* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new SSD4_Program2_GUI().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JButton jButton1;
private javax.swing.JButton jButton2;
private javax.swing.JButton jButton3;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel10;
private javax.swing.JLabel jLabel11;
private javax.swing.JLabel jLabel12;
private javax.swing.JLabel jLabel13;
private javax.swing.JLabel jLabel14;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JLabel jLabel4;
private javax.swing.JLabel jLabel5;
private javax.swing.JLabel jLabel6;
private javax.swing.JLabel jLabel7;
private javax.swing.JLabel jLabel8;
private javax.swing.JLabel jLabel9;
private javax.swing.JPanel jPanel1;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JTextArea jTextArea1;
private javax.swing.JTextField jTextField1;
private javax.swing.JTextField jTextField2;
// End of variables declaration
}
标签:java,用户界面,addComponent,GroupLayout,实验,swing,new,javax,SSD4 来源: https://blog.csdn.net/qq_39564555/article/details/98372746