abstract class and common code

I have a question about abstract classes and their real purpose. Consider the below scenario: interface A { void execute(); } class AOne implements A { public void execute() { x = getX(); .. functionality specific to A .. y = getY(); .. more funtionality specific to A } private X getX() { .. return x;

抽象类和通用代码

我有一个关于抽象类和他们真正目的的问题。 考虑以下情况: interface A { void execute(); } class AOne implements A { public void execute() { x = getX(); .. functionality specific to A .. y = getY(); .. more funtionality specific to A } private X getX() { .. return x; } private Y getY() { ..

Inheritance of Square method in java

I have a class Rectangle laid out like this: package Inheritance; /** * * @author Jacob */ public class Rectangle { final private int length; final private int width; public Rectangle (int l, int w) { length = l; width = w; } public int getLength () { return length; } public int getWidth () { return width; } @Override public String toString () { return String.format (

java中Square方法的继承

我有一个类矩形布局如下: package Inheritance; /** * * @author Jacob */ public class Rectangle { final private int length; final private int width; public Rectangle (int l, int w) { length = l; width = w; } public int getLength () { return length; } public int getWidth () { return width; } @Override public String toString () { return String.format ("Rectangle (%dX%d)",

Implement a subclass Square that extends the Rectangle class

//Implement a subclass Square that extends the Rectangle class. In the constructor, accept the x- and y-positions of the center and the side length of the square. Call the setLocation and setSize methods of the Rectangle class. Look up these methods in the documentation for the Rectangle class. Also supply a method getArea that computes and returns the area of the square. Write a sample prog

实现扩展Rectangle类的子类Square

//实现扩展Rectangle类的子类Square。 在构造函数中,接受中心的x和y位置以及正方形的边长。 调用Rectangle类的setLocation和setSize方法。 在Rectangle类的文档中查找这些方法。 另外提供一个方法getArea来计算和返回正方形的面积。 写一个示例程序,询问中心和边长,然后打印出正方形(使用从矩形继承的toString方法)和正方形区域。 //好的...所以这是最后一分钟,但我不明白我的代码有什么问题,它给了我方块无法解析

using getX() getY() in a mouseclick

This is a long question. I've tried to make it more concise but I think you need all the info to assist. Here's a summary: I'm trying to capture consecutive clicks as endpoints. I'll draw line2D objects between these points. I have a listener that sends x and y values from click events to a helper class. I'll never have more than two points, so the helper class only has

在鼠标点击中使用getX()getY()

这是一个长期的问题。 我试图让它更简洁,但我认为你需要所有的信息来协助。 以下是一个总结:我试图捕获连续点击作为端点。 我将在这些点之间绘制line2D对象。 我有一个侦听器,它将点击事件的x和y值发送给一个辅助类。 我永远不会超过两点,所以助手类只有firstPoint和secondPoint成员。 我使用evt.getX()和evt.getY()获得点击并将坐标发送给助手类。 帮助者创建点,但是firstPoint以与secondPoint相同的协调角色

Implementing boolean contains(Rectangle2D r) method of Shape interface

here is my Java problem: My Circle class implements the Shape interface and thus it must implement all the methods required. I have a problem with the method boolean contains(Rectangle2D r) that "Tests if the interior of the Shape entirely contains the specified Rectangle2D". Now, Rectangle2D is an abstract class that does not provide (to the best of my poor knowledge) any method to

实现布尔值包含Shape接口的(Rectangle2D r)方法

这是我的Java问题: 我的Circle类实现了Shape接口,因此它必须实现所有需要的方法。 我有一个方法boolean contains(Rectangle2D r)“测试Shape的内部是否完全包含指定的Rectangle2D”。 现在,Rectangle2D是一个抽象类,它没有提供任何方法来获得矩形边角的坐标。 更确切地说:“Rectangle2D类描述了一个由位置(x,y)和维(wxh)定义的矩形,该类只是用于存储2D矩形的所有对象的抽象超类,坐标的实际存储表示留给子类“。

Java Point, difference between getX() and point.x

I am confused to as why the Java Point class takes in two int paramaters and the getX() and getY() methods return doubles. For example I could define a Point Point p = new Point(4,6); If I were to call.. p.getX(); It would return 4.0. and if I were to call p.x; I would get 4. Any reason for this? There are Point2D.Double and Point2D.Float classes that extend Point2D which is a supercl

Java Point,getX()和point.x之间的区别

我很困惑为什么Java Point类需要两个int参数,并且getX()和getY()方法返回双精度。 例如,我可以定义一个Point Point p = new Point(4,6); 如果我打电话给.. p.getX(); 它会返回4.0。 如果我打电话 p.x; 我会得到4。 有什么理由呢? 有Point2D.Double和Point2D.Float类扩展Point2D , Point2D是Point的超类,它们需要能够使用浮点值。 请注意,还有一个setLocation( double, double ) 。 Point2D是一个抽象类

Sending Skype messages in Java, using the java

I need help with my java project. I'm currently trying to send a message in a Skype conversation when a specific action happens. For this, I am using the java-skype API v1.4 by taskan. Here's my code: try { for (Group group : Skype.getContactList().getAllGroups()) { if ((group.getDisplayName()).equals("Nameofthegroup")) { //Whatever the group name is String i

用Java发送Skype消息,使用java

我需要我的Java项目帮助。 我正在尝试在发生特定操作时在Skype对话中发送消息。 为此,我使用taskan的java-skype API v1.4。 这是我的代码: try { for (Group group : Skype.getContactList().getAllGroups()) { if ((group.getDisplayName()).equals("Nameofthegroup")) { //Whatever the group name is String id = group.getId(); Skype.chat(id).send(ep.getDisplayName() + " jo

Replacement for Normalizer.getClass(c) method in Java 6

The getClass(char c) method from Normalizer class seems to be missing from Java 6 onwards. This method is present in our legacy code and is being used as shown below. We need to migrate it to Java 6. Any suggestions on how it can be replaced? import sun.text.Normalizer; /** * Returns an array of strings that have all the possible * permutations of the characters in the input string. * Th

替换Java 6中的Normalizer.getClass(c)方法

Normalizer类中的getClass(char c)方法似乎从Java 6开始就缺少。 这种方法存在于我们的遗留代码中,正在使用,如下所示。 我们需要将它迁移到Java 6.关于如何替换它的任何建议? import sun.text.Normalizer; /** * Returns an array of strings that have all the possible * permutations of the characters in the input string. * This is used to get a list of all possible orderings * of a set of combining m

Overriding default methods for some repositories

I am just staring with spring-data and spring-data-rest and I really want to take advantage of what these tools have to offer. For the most case the base functionality is perfect for my use case however there are some cases where I need to customize the underlying functionality quite a bit, and selectively assign some repositories to inherit the customized functionality I am after. To explain

覆盖某些存储库的默认方法

我只是盯着spring-data和spring-data-rest ,我真的想要利用这些工具必须提供的功能。 在大多数情况下,基本功能对我的用例来说是完美的,但是在某些情况下,我需要定制相当多的底层功能,并选择性地分配一些存储库来继承我之后的自定义功能。 为了更好地解释这个问题,在spring-data有两个可以从CrudRepository或PagingAndSortingRepository继承功能的接口。 我想添加第三个叫let说PesimisticRepository PesimisticReposi

Correct/Optimized way to reschedule a Java task in a ScheduledExecutorService?

Suppose that we have a Java Task (eg: Runnable ) that will be executed if we do not receive an external signal in x seconds. A common way to solve this problem is to use a schedule thread pool (such as ScheduledExecutorService ) to execute this task considering x delay. When we receive that external event, from other part of the system, we need to reschedule this task, that is, to reinsert thi

正确/优化的方式重新安排ScheduledExecutorService中的Java任务?

假设我们有一个Java任务(例如: Runnable ),如果我们在x秒内没有收到外部信号,它将被执行。 解决此问题的常见方法是使用计划线程池(如ScheduledExecutorService )来考虑x延迟来执行此任务。 当我们从系统的其他部分接收到该外部事件时,我们需要重新计划此任务,即以x延迟将此任务重新插入到线程池中。 我的问题是:在ScheduleExecutorService重新安排任务的正确/优化方式是什么? 当前的解决方案通常关注于删除/取