Java How To Program第12章-GUI控件(上篇)中的一个示例,演示了鼠标事件的监控,包括: 1. 单击(click-按下某个鼠标键(左/中/右键)后松开) 2. 移动(move-不按下任何鼠标键的同时,移动鼠标) 3. 拖(drag-按下左/中/右键后不松开,并移动鼠标) 4. 放(release-拖操作之后,松开左/中/右键)。 程序会监控各种鼠标操作发生的位置,在移动操作中,将鼠标移动到屏幕最右下角,可看到X坐标和Y坐标同时达到最大值(1919,982)。 由于JFrame窗口最大化后并没有遮住Windows任务栏,任务栏的高度并没有加入到Y坐标,由此推出屏幕分辩率为19
日期:2016年07月28日画图向来不是我的强项,如果有了Java的帮忙,或许情况会有所改观。 60条线,对电脑来说就是一瞬间的事,但如果用画图板人工来画的话,呵呵,你试试 代码如下: //Graphics Exercise 4.1 /*Using loops and control statements to draw lines can lead * to many interesting designs Graphics101.java */ //Creating JFrame to display DrawPanel. import javax.swing.JFrame; import java.awt.G
日期:2016年06月15日不知道为什么,这章的内容看起来很吃力。 本来以为自己的英语还不错,前面的几章看的挺顺溜,难道是因为前面几章的知识已经比较熟悉的缘故?-> Summary Section 11.1Introduction • An exception is anindication of a problem that occurs during a program’s execution. • Exception handlingenables programmers to create applications that can resolve exceptions. Section 11.2Example:
日期:2016年07月22日学了几天Swing,觉得应该可以完成课后习题了。 可是,第一个页面就把我给难住了。 题目:创建下图所示GUI 忙活了1个多小时后,我开发的界面如下: 感悟:学艺不精,可悲!等提升实力后再来挑战 代码如下: package exercise; import java.awt.BorderLayout; import java.awt.Container; import javax.swing.JFrame; import javax.swing.JCheckBox; import javax.swing.JTextField; import javax.swing.JPanel; impor
日期:2016年07月27日Section9.1 Introduction • Inheritance (p. 361)reduces program-development time. • The direct superclass(p. 361) of a subclass is the one from which the subclass inherits. An indirect superclass (p. 361) of a subclass is two or more levels up the class hierarchy from that subclass. • In single inheri
日期:2016年07月15日Section10.1 Introduction • Polymorphism (p. 396)enables us to write programs that process objects that share the same superclass as if they were all objects of the superclass; this can simplify programming. • With polymorphism, we can design and implement systems that are easily extensible. The only
日期:2016年07月18日example; //JHTP Exercise 8.11:Complex Numbers //by pandenghuang@163.com /**(Complex Numbers) Create a class called Complex for
日期:2016年07月09日Summary Section 8.2 TimeClass Case Study • The public methods of aclass are also known as the class’s public services or public interface (p.316). They present to the class’s clients a view of the services the classprovides. • A class’s private members arenot accessible to its clients. • String clas
日期:2016年07月08日Java how to program(中文名:Java大学教程)第10版第11章:深入理解异常(Exception Handling: A Deeper Look)中给出了一个整数除法的示例,用户输入除数和被除数时,任何一个出错,就必须重新来过。考虑到这样做不太人性化,决定改写一下。 代码如下: package exercise; //Fig. 11.3: DivideByZeroWithExceptionHandling.java //Handling ArithmeticExceptions and InputMismatchExceptions. import java.util.I
日期:2016年07月20日写Java小程序已有快10年了,一直觉得do...while循环语句没什么用,今天有了新发现:可以使用do...while简化程序 简化前:根据业务需求,一些操作在整个程序中需至少执行一次,于是将这部分代码放在了while循环体之前。但这部分代码和循环体内重复执行的代码基本相同 简化后:使用do...while循环,将需至少执行一次的代码放到循环体内,无需单独列出。 简化的优点:程序更为简洁(代码行数明显减少,便于后期维护) 不简化的优点:可将循环体外的代码作为程序初始化的division,可作一些定制,以区别于循环体内的部分 简化前代码(共94行): //Java how to progra
日期:2016年06月21日9.1Fill in the blanks in each of the following statements: a)Inheritance is a form of software reusability in which new classes acquire the members of existing classes and embellish those classes with new capabilities. b) A superclass’spublic and protected members can be accessed in the superclass d
日期:2016年07月15日题目不多,但不代表容易完成。继续努力! 13.1 Fill in theblanks in each of the following statements: a) In Java 2D, method setStrokeof class Graphics2D sets the characteristics of a stroke used to draw ashape. b) Class GradientPainthelps specify the fill for a shape such that the fill gradually changes from onecolor to
日期:2016年08月03日如果要导出文件夹下的文件目录,可使用DOS的tree命令。 当然,你也可以使用Java程序。 代码如下: package example; //Fig. 15.12: JFileChooserDemo.java //Demonstrating JFileChooser. import java.io.IOException; import java.nio.file.DirectoryStream; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; import javax.s
日期:2016年08月04日很基础的问题,不容得出错;出错只能说明一个问题:基础不牢固。 Self-Review Exercises 7.1 Fill in theblank(s) in each of the following statements: a) Lists and tables ofvalues can be stored in Array and Collections. b) An array is a group ofvariables (called elements or components) containing values that allhave the same type. c) T
日期:2016年07月07日原题要求每个问题提供4个选项,姑且偷个懒,变成1、2二选一。多选时,可用switch语句实现。 代码如下: //JHTP Exercise 5.31: Global Warming Facts Quiz //by pandenghuang@163.com
日期:2016年06月27日 Exercises 5.5 Describe thefour basic elements of counter-controlled repetition. (counter, initial value,increment, loop continuation condition) 5.6 Compare andcontrast the while and for repetition statements. 5.7 Discuss asituation in which it would be more appropriate to use a do…while statement
日期:2016年06月27日除了最后一节有几个方法,如,GeneralPath(), moveTo(), rotate(), closePath()及translate()没有理解外,其他基本都能理解。 不能理解的部分,权当今后的作业了,因为我要继续前行!Keep moving! Section 13.1Introduction • Java’s coordinatesystem (p. 556) is a scheme for identifying every point (p. 567) on the screen. • A coordinate pair (p.556) has an x-coordinate (
日期:2016年08月02日了两种复用方式: 1)调用外部类的方法 2)复制该方法到本测试类 看似一个小功能,实际写起来还挺有意思的! 代码如下: //JHTP Exercise 4.30:Palindromes //by pandenghuang@163.com
日期:2016年06月17日 Summary Section 6.1Introduction • Experience has shownthat the best way to develop and maintain a large program is to construct itfrom small, simple pieces, or modules. This technique is called divide andconquer (p. 201). Section 6.2Program Modules in Java • Methods are declaredwithin classes. Cl
日期:2016年06月27日看源码好处多多,边看边改效果更佳,可以了解每个细枝末节的来龙去脉。 通过修改参数,画笔的粗度已被我改的比较高了,落笔格外给力。 遗留问题:看似简短的画图小程序,还没有完全理解代码为什么这么写,留待日后再察。 代码如下: //Fig. 12.34: PaintPanel.java //Adapter class used to implement event handlers. import java.awt.Point; import java.awt.Graphics; import java.awt.event.MouseEvent; import java.awt.event.Mouse
日期:2016年07月28日