- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我正在使用 Netbeans。这些文件由于某种原因无法运行。我正在尝试导入 Netbeans 选项卡中的其他文件,但它们不起作用。如何使该应用程序也作为 main 方法运行 SimpleDateClient.java
。
这是SimpleDateClient.java
/* A client program to display SimpleDate object values
Anderson, Franceschi
*/
package SimpleDateClient;
import java.awt.*;
import javax.swing.JFrame;
public class SimpleDateClient extends JFrame
{
private String action = "";
private int animationPause = 2; // 2 seconds between animations
private SimpleDate dateObj; // declare SimpleDate object reference
public void workWithDates( )
{
animate( "dateObj reference declared" );
/***** Add your code here *****/
/**** 1. Instantiate dateObj using an empty argument list */
dateObj = new SimpleDate();
animate( "Instantiated dateObj - empty argument list" );
/***** 2. Set the month to the month you were born */
//animate( "Set month to birth month" );
/***** 3. Set the day to the day of the month you were born */
//animate( "Set day to birth day" );
/***** 4. Set the year to the year you were born */
//animate( "Set year to birth year" );
/***** 5. Call the nextDay method */
//animate( "Set the date to the next day" );
/***** 6. Set the day to 32, an illegal value */
//animate( "Set day to 32" );
/***** 7. Set the month to 13, an illegal value */
//animate( "Set month to 13" );
/***** 8. Assign the value null to dateObj */
//animate( "Set object reference to null" );
/***** 9. Attempt to set the month to 1 */
}
public SimpleDateClient( )
{
super( "A SimpleDate Object" );
setSize( 300, 300 );
setVisible( true );
}
public void paint( Graphics g )
{
super.paint( g );
// display action
g.drawString( action, 50, 250 );
// object reference
int sX = 50, sY = 75;
int boxL = 75, boxH = 20;
g.drawRect( sX, sY, boxL, boxH );
g.drawString( "dateObj", sX, sY - 10 );
if ( dateObj != null )
draw( g );
else
g.drawString( "null", sX + 15, sY + 15 );
}
public void draw( Graphics g )
{
int sX = 50, sY = 75;
int boxL = 75, boxH = 20;
// arrow
g.drawLine( sX + boxL, sY + boxH / 2,
sX + boxL + 25, sY + boxH / 2 );
g.drawLine( sX + boxL + 25, sY + boxH / 2,
sX + boxL + 25, sY + boxH * 2 );
g.drawLine( sX + boxL + 25 - 5, sY + boxH * 2 - 5,
sX + boxL + 25, sY + boxH * 2 );
g.drawLine( sX + boxL + 25 + 5, sY + boxH * 2 - 5,
sX + boxL + 25, sY + boxH * 2 );
// month
g.drawString( "month", sX + boxL - 50, sY + 2 * boxH + 15 );
g.drawRect( sX + boxL, sY + 2 * boxH, boxL, boxH );
g.drawString( Integer.toString( dateObj.getMonth( ) ),
sX + boxL + 5, sY + 2 * boxH + 15 );
// day
g.drawString( "day", sX + boxL - 50, sY + 3 * boxH + 15 );
g.drawRect( sX + boxL, sY + 3 * boxH, boxL, boxH );
g.drawString( Integer.toString( dateObj.getDay( ) ),
sX + boxL + 5, sY + 3 * boxH + 15 );
// year
g.drawString( "year", sX + boxL - 50, sY + 4 * boxH + 15 );
g.drawRect( sX + boxL, sY + 4 * boxH, boxL, boxH );
g.drawString( Integer.toString( dateObj.getYear( ) ),
sX + boxL + 5, sY + 4 * boxH + 15 );
}
public void animate( String a )
{
action = a;
repaint( );
Pause.wait( (double) animationPause );
}
public static void main( String [] args )
{
SimpleDateClient app = new SimpleDateClient( );
app.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
app.workWithDates( );
}
}
这是SimpleDate.java
/* A simple date class
Anderson, Franceschi
*/
package SimpleDateClient;
public class SimpleDate
{
private int month;
private int day;
private int year;
/** default constructor
* sets month to 1, day to 1 and year to 2000
*/
public SimpleDate( )
{
setDate( 1, 1, 2000 );
}
/** overloaded constructor
* @param mm initial value for month
* @param dd initial value for day
* @param yyyy initial value for year
*
* passes parameters to set methods
*/
public SimpleDate( int mm, int dd, int yyyy )
{
setMonth( mm );
setYear( yyyy );
setDay( dd );
}
/* accessor methods */
int getMonth( ) { return month; }
int getDay( ) { return day; }
int getYear( ) { return year; }
/** mutator method */
/** setMonth
* @param mm new value for month
* if mm is between 1 and 12, sets month to mm
* otherwise, sets month to 1
*/
public void setMonth( int mm )
{
month = ( mm >= 1 && mm <= 12 ? mm : 1 );
}
/** setDay
* @param dd new value for day
* if dd is legal day for current month, sets day to dd
* otherwise, sets day to 1
*/
public void setDay( int dd )
{
day = ( dd >= 1 && isValidDay( dd ) ? dd : 1 );
}
/** setYear
* @param yyyy new value for year
* sets year to yyyy
*/
public void setYear( int yyyy )
{
year = yyyy;
}
/** sets date to the next day
*/
public void nextDay( )
{
if ( ! isValidDay( ++day ) )
{
day = 1;
if ( ++month > 12 )
{
month = 1;
year++;
}
}
}
private boolean isValidDay( int newDay )
{
int [] daysInMonth = { 0, 31, 28, 31,
30, 31, 30,
31, 31, 30,
31, 30, 31 };
if ( newDay > daysInMonth[month] )
{
if ( month == 2 && isLeapYear( ) && newDay == 29 )
return true;
else
return false;
}
else
return true;
}
private boolean isLeapYear( )
{
return !( year % 4 != 0
||( year % 100 == 0 && year % 400 != 0 ) );
}
/** setDate
* @param mm new value for month
* @param dd new value for day
* @param yyyy new value for year
* passes parameters to setMonth, setDay, and setYear
*/
public void setDate( int mm, int dd, int yyyy )
{
setYear( yyyy ); // set year first (could be leap year)
setMonth( mm ); // set month next
setDay( dd ); // set day
}
/** toString
* @return String
* returns date in mm/dd/yyyy format
*/
public String toString( )
{
return month + "/" + day + "/" + year;
}
/** equals
* @param d Object to compare to this object
* @return true if d is equal to this object
* false, otherwise
*/
public boolean equals( Object d )
{
if ( !( d instanceof SimpleDate ) )
return false;
SimpleDate d1 = (SimpleDate)d;
if ( month == d1.month
&& day == d1.day
&& year == d1.year )
return true;
else
return false;
}
}
这是Pause.java
/* Pause class to pause applications
Anderson, Franceschi
*/
package SimpleDateClient;
public class Pause
{
public static void wait( double seconds )
{
try
{
Thread.sleep( (int) ( seconds * 1000 ) );
}
catch ( InterruptedException e )
{
e.printStackTrace( );
}
}
}
最佳答案
转到文件|新项目
从类别
中选择Java
,从项目
中选择Java应用程序
,单击下一步>
为项目命名并确保设置初始包/类
您的项目现在应该已经开始了。
现在可以选择是否将现有文件复制到项目中(在 Windows 下,您可以简单地从资源管理器复制文件并将其粘贴到项目中(在 src
节点下)),还是在项目中创建空类并简单地复制粘贴原始文件中的内容
关于java - 找不到符号: symbol: class SimpleDate location: class SimpleDateClient,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32575780/
您能否告诉我以下代码是否是线程安全的以及如何测试它: private static final SimpleDateFormat sdf = new SimpleDateFormat("M
在我的应用程序中,我需要将 SimpleDateFormat 设置为允许 null,因为该输入字段很可能为空。 SimpleDateFormat df = new SimpleDateFormat("
我有一组字符串。这个字符串实际上是“年”。例如:“1967”、“1872”、“2012”、... 我想从其中每个创建一个 SimpleDate 实例。有没有办法从年份字符串创建 SimpleDate?
我正在为 Android 开发一个包含十二个不同项目的 XML 解析器,我需要帮助为每个项目创建一个日期。这是我目前所拥有的: TextView detailsPubdate = (TextView)
我有一个 startDate 和一个 endDate 作为输入参数。该参数在查询中使用: SELECT * FROM patientRecords WHERE patientRecords.dateO
我正在使用 python 库 simple-date。我通过使用表示 UTC 日期的字符串进行初始化来创建了一个 SimpleDate 对象。当我尝试使用 timedelta 添加天数时,它似乎工作正
该程序用于转换 ISO 日期(例如:2014-02-15)并能够将其转换为“2014 年 2 月 15 日”,但我在构造函数方面遇到了麻烦,这是迄今为止我所拥有的: public SimpleDate
我正在使用 Netbeans。这些文件由于某种原因无法运行。我正在尝试导入 Netbeans 选项卡中的其他文件,但它们不起作用。如何使该应用程序也作为 main 方法运行 SimpleDateCli
我是一名优秀的程序员,十分优秀!