- 浏览: 50012 次
- 性别:
- 来自: 大同
最新评论
-
javafound:
不错,期待!
神奇的paint方法 -
为爱Debug:
依稀记得,以前为了考试背过!呵呵
java中错误与异常的总结 -
optimism_best:
楼主,你的样子吓到我了,阿门!
java中错误与异常的总结 -
TTNecro:
[size=x-small] 比预想的发表的晚很多啊!![/ ...
ACM赛后感想 -
javafound:
比较细致,呵呵,
java中错误与异常的总结
最近学校留作业,因为用不惯NetBean,还是用JCreator编写代码。写着写着无意中搞出一个继承,不知道这样子是好还是坏。自我感觉在添加组件时挺方便的,希望路过的高手指点:
/** * @(#)MainFrame.java * * * @author * @version 1.00 2010/10/20 */ import javax.swing.*; import javax.swing.event.*; import java.awt.*; import java.awt.event.*; public class MainFrame extends JFrame { private JScrollPane jspForTxtArea; private JLabel[] labels; private JTextArea txtArea; private JTextField txtField1,txtField2; private MyButton[] buttons; private String[] text; private void init() { text = new String[7]; text[0] = "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."; text[1] = "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."; text[2] = "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."; text[3] = "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."; text[4] = "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."; text[5] = "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"; text[6] = "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."; labels = new JLabel[14]; labels[0] = new JLabel("UAR componet names:"); labels[1] = new JLabel("UAR componet description:"); labels[2] = new JLabel("1.UAR Identifier"); labels[3] = new JLabel("2.Succinct Description of the Usability Aspect"); labels[4] = new JLabel("3.Evidence for the Aspect"); labels[5] = new JLabel("4.Explanation of the Aspect"); labels[6] = new JLabel("5.Severity of the Problem or Benefit of the Good Feature"); labels[7] = new JLabel("6.Possible Solutions and Petential Trade-offs"); labels[8] = new JLabel("7.Relationship to Other Usability Aspects"); labels[9] = new JLabel("Enter a number:"); labels[10] = new JLabel("Enter a search string:"); labels[11] = new JLabel("Found at:"); labels[12] = new JLabel(); labels[13] = new JLabel(); for(int i=0; i<2; i++) labels[i].setFont(new Font("Arial", 1, 13)); for(int i=2; i<labels.length; i++) labels[i].setFont(new Font("宋体", 0, 12)); txtArea = new JTextArea(); txtArea.setLineWrap(true); txtArea.setWrapStyleWord(true); jspForTxtArea = new JScrollPane(txtArea); jspForTxtArea.setAutoscrolls(true); txtField1 = new JTextField(6); txtField2 = new JTextField(6); txtField1.getDocument().addDocumentListener( new DocumentListener(){ public void changedUpdate(DocumentEvent e) { insertUpdate(e); } public void insertUpdate(DocumentEvent e) { txtArea.setText(""); } public void removeUpdate(DocumentEvent e) { insertUpdate(e); } }); buttons = new MyButton[3]; buttons[0] = new DisplayButton(); buttons[1] = new SearchButton(); buttons[2] = new ExitButton(); buttons[0].setText("Display"); buttons[1].setText("Search"); buttons[2].setText("Exit"); for(int i=0; i<buttons.length; i++) buttons[i].addActionListener(new ProcessActions()); } /** * 界面上所有按钮的父类,继承了JButton */ private class MyButton extends JButton { public void actionPerformed() { System.out.println("Haven't you overwrite \"actionPerformed\" method?"); } } private class DisplayButton extends MyButton { public void actionPerformed() { String strchosen = txtField1.getText(); int intchosen = 0; try{ intchosen = Integer.parseInt(strchosen); } catch (Exception e) { } if (intchosen > 0 && intchosen < 8) { txtArea.setText(text[intchosen-1]); } else { javax.swing.JOptionPane.showMessageDialog(null, "Please enter value between 1 and 7"); txtField1.setText(""); return; } } } private class SearchButton extends MyButton { public void actionPerformed() { String str = txtArea.getText(); if ( str.equals("") ) { javax.swing.JOptionPane.showMessageDialog (null, "Please select text");return; } String pattern = txtField2.getText(); if ( pattern.equals("") ) { javax.swing.JOptionPane.showMessageDialog (null, "Please enter a search string");return; } int first=0, end=0, index, count=0; boolean flag = true; while(true) { System.out.println("===="+count); index = str.indexOf(pattern); if (index==-1) break; end = index; count++; if ( flag ) { first = end; flag = false; } str = str.substring(index+pattern.length()); } int intconfirm=0; if (count==0) { intconfirm=javax.swing.JOptionPane.showConfirmDialog (null, "String '"+pattern+"' not found\r\nSearch same text again?"); } else if (count==1) { intconfirm=javax.swing.JOptionPane.showConfirmDialog (null, "The number of occurences of '"+pattern+"' is "+count+"\r\nSearch same text?"); labels[12].setText("Occurence "+1+" : Position : " + first); } else { intconfirm=javax.swing.JOptionPane.showConfirmDialog (null, "The number of occurences of '"+pattern+"' is "+count+"\r\nSearch same text?"); labels[12].setText("Occurence "+1+" : Position : " + first); labels[13].setText("Occurence "+count+" : Position : " + end); } if (intconfirm==1) { txtArea.setText(""); txtField1.setText(""); } txtField2.setText(""); } } private class ExitButton extends MyButton { public void actionPerformed() { System.exit(0); } } private class ProcessActions implements ActionListener { public void actionPerformed(ActionEvent e) { MyButton button = (MyButton) e.getSource(); /** * 当添加按钮组件时,不需要修改这部分代码 */ for(int i=0;i<buttons.length;i++) { if(button==buttons[i]) { button.actionPerformed(); } } } } private void setBoundsForAll() { int xl=this.getWidth()/2-20, yl=20, x=20, y=8; labels[0].setBounds(x, y, xl, yl); labels[1].setBounds(xl+36, y, xl, yl); y+=25; for(int i=2; i<9; i++) labels[i].setBounds(x, y+28*(i-2), xl, yl); x=xl+33; jspForTxtArea.setBounds(x, y+3, xl-50, 216); labels[11].setBounds(x, y+230, xl, 20); x=20;xl=166;y=labels[8].getY()+103; labels[9].setBounds(x, y, xl, yl); labels[10].setBounds(x, y+40, xl, yl); x+=xl;y-=2;xl=136;yl+=4; txtField1.setBounds(x, y, xl, yl); txtField2.setBounds(x, y+40, xl, yl); x+=(xl+10);y-=5;xl=80;yl=30; buttons[0].setBounds(x, y, xl, yl); buttons[1].setBounds(x, y+40, xl, yl); xl=this.getWidth()/2-20;x=xl+33;y+=5; labels[12].setBounds(x, y, xl, 20); labels[13].setBounds(x, y+40, xl, 20); buttons[2].setBounds(this.getWidth()-120, this.getHeight()-78, 80, 30); } public MainFrame() { super("UAR Components"); this.init(); this.setSize(880,500); this.setResizable(false); this.setLocationRelativeTo(null); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); this.setContentPane(getContentPane(new JPanel())); this.setVisible(true); } public Container getContentPane(Container pane) { pane.setLayout(null); for(int i=0;i<labels.length;i++) pane.add(labels[i]); for(int i=0;i<buttons.length;i++) pane.add(buttons[i]); pane.add(jspForTxtArea); pane.add(txtField1); pane.add(txtField2); setBoundsForAll(); return pane; } }
发表评论
-
Log4j学习
2012-12-20 18:03 836这不是一篇细致的总结,只是几个零星的知识点。 L ... -
Java异常处理
2012-12-17 14:31 711正确关闭资源的方式: Object src ... -
Java内存回收
2012-12-08 11:07 882基本上,可以把 JVM 内存中的对象引用理 ... -
Java集合框架
2012-12-06 15:27 802Java集合框架 HashMa ... -
Java内存分配
2012-11-30 23:44 769变量可大致分为局部变量和成员变量。局部变量分为形参、方法内的局 ... -
Java数组
2012-11-28 10:00 777小小的数组,知识还真不少! Java数组是静态的,与之 ... -
对云存储的一点认识
2012-05-26 15:28 1052云存储是在云计算概念上延伸和发展出来的一个新的概念。关于云 ... -
标准模板库STL
2012-03-10 23:48 1144STL 的最主要的两个特 ... -
差分法求数据压缩
2011-12-26 07:11 2454课程设计名称:差分法求数据压缩题目:一数据文件中存放着若干个8 ... -
为什么jquery的ajax事件不支持谷歌浏览器
2011-08-21 17:16 4995load方法是jquery中最方便实用的ajax实现,但是遇到 ... -
二分搜索递归实现代码中return的去留问题
2010-10-11 01:52 1285二分搜索有两种常见的实现方法:递归实现、迭代实现。其中递归实现 ... -
类之间的关系
2010-09-08 16:57 829这是本人系统学习设计模式之前的一篇记录类之间的关系的文章。 ... -
条件语句精简代码
2010-08-31 16:18 862<script type="text/java ... -
java中错误与异常的总结
2010-04-13 01:02 1726这里是对java中错误与 ... -
文件存取
2010-04-08 01:46 1005首先说一下文件的概念。文件,是在逻辑上具有完整意义的一组相关的 ...
相关推荐
Java继承例子.doc
非常适合初学者的java继承学习 很经典因为我也是初学者!哈哈
VC++;从已知一个自定义基类继承的实例,这里是将视图类继承自我们准备好的一个基类;让派生类(视图类)拥有了我们的一些描述和操作。
hibenate继承例子
继承窗体的设计C#源码
c++虚拟继承的一个典型例子,通过这个例子可以让初学者从根本体会到虚拟继承是怎么回事
java继承的小例子, java继承 java继承
继承的使用 (1)声明一个人类Person,放入以你的姓名为包名的包中,姓名为private类型属性,性别为protected类型变量,年龄为默认访问类型变量;该类有两个构造方法Person()和Person(姓名,性别,年龄),构造...
对java中继承的练习,一个简单的例子,通过描述大树的性质来进行理解。
只是一个关于公司的继承例子
C++实现的一个继承与多态的例子,内容详细且易懂
c#多态,继承,接口,结构例子
java_中关于_继承_的一个小例子,java_中关于_继承_的一个小例子.rar
使用js模拟类继承小例子,学习js面向对象的朋友可以参考下。
收集的一些Java编程实例集:类和继承,含有丰富的中文注释,内容大致是:定义 Point类、定义形状接口、循环输出下转形状并打英创建自己异常、使用继承 (实例一个父类定义到子类)子类赋值把一个点定义创建圆对象定义...
安老师 的一个例子,c++ 的封装继承多态例子
C++中public继承、private继承、protected继承的例子
Struts2继承ActionSupport例子 这个是我们在上课的时候做的一个小例子,可能其中还掺杂着其他东西,跟我博客是相关联的,如果只看代码看不懂,建议大家去看一下博客。
C# 接口与继承的例子源代码,截图以控制台程序来说明此问题,或许你从截图中能看出程序所表达的意思。
在C#中关于类之间继承的一个例子