帮忙解释一下这段代码 谢谢各位了 要详细点的哈 我是新手 不太懂哦 5
//Javacorepackagesimportjava.awt.*;importjava.awt.event.*;importjava.awt.geom.*;impor...
// Java core packages
import java.awt.*;
import java.awt.event.*;
import java.awt.geom.*;
import java.util.*;
// Java extension packages
import javax.swing.*;
import javax.swing.BorderFactory;
import javax.swing.event.*;
public class Clock extends JFrame implements Runnable {
private Calendar calendar;
private int year, month, day, hour, minute, second;
private JSpinner spinner;
private Thread thread;
public Clock()
{
super( "时钟" );
Container container = getContentPane();
container.setLayout( new BorderLayout() );
JPanel panel = new JPanel();
panel.setBorder( BorderFactory.createTitledBorder( "时间" ) );
SpinnerDateModel model = new SpinnerDateModel();
model.setCalendarField( Calendar.HOUR_OF_DAY );
spinner = new JSpinner( model );
JSpinner.DateEditor editor = new JSpinner.DateEditor( spinner,
"hh:mm:ss" );
editor.getTextField().addMouseListener(
new MouseAdapter() {
public void mouseClicked( MouseEvent e )
{
thread = null;
}
}
);
spinner.setEditor( editor );
model.addChangeListener(
new ChangeListener() {
public void stateChanged( ChangeEvent e )
{
SpinnerDateModel source = ( SpinnerDateModel )e.getSource();
calendar.setTime( source.getDate() );
year = calendar.get( Calendar.YEAR );
month = calendar.get( Calendar.MONTH );
day = calendar.get( Calendar.DAY_OF_MONTH );
hour = calendar.get( Calendar.HOUR_OF_DAY );
minute = calendar.get( Calendar.MINUTE );
second = calendar.get( Calendar.SECOND );
GregorianCalendar gCalendar = new GregorianCalendar( year,
month, day, hour, minute, second );
spinner.setValue( gCalendar.getTime() );
repaint();
}
}
);
container.add( panel, BorderLayout.CENTER );
container.add( spinner, BorderLayout.SOUTH );
setSize( 250, 280 );
setVisible( true );
setResizable( false );
thread = new Thread( this );
thread.start();
} 展开
import java.awt.*;
import java.awt.event.*;
import java.awt.geom.*;
import java.util.*;
// Java extension packages
import javax.swing.*;
import javax.swing.BorderFactory;
import javax.swing.event.*;
public class Clock extends JFrame implements Runnable {
private Calendar calendar;
private int year, month, day, hour, minute, second;
private JSpinner spinner;
private Thread thread;
public Clock()
{
super( "时钟" );
Container container = getContentPane();
container.setLayout( new BorderLayout() );
JPanel panel = new JPanel();
panel.setBorder( BorderFactory.createTitledBorder( "时间" ) );
SpinnerDateModel model = new SpinnerDateModel();
model.setCalendarField( Calendar.HOUR_OF_DAY );
spinner = new JSpinner( model );
JSpinner.DateEditor editor = new JSpinner.DateEditor( spinner,
"hh:mm:ss" );
editor.getTextField().addMouseListener(
new MouseAdapter() {
public void mouseClicked( MouseEvent e )
{
thread = null;
}
}
);
spinner.setEditor( editor );
model.addChangeListener(
new ChangeListener() {
public void stateChanged( ChangeEvent e )
{
SpinnerDateModel source = ( SpinnerDateModel )e.getSource();
calendar.setTime( source.getDate() );
year = calendar.get( Calendar.YEAR );
month = calendar.get( Calendar.MONTH );
day = calendar.get( Calendar.DAY_OF_MONTH );
hour = calendar.get( Calendar.HOUR_OF_DAY );
minute = calendar.get( Calendar.MINUTE );
second = calendar.get( Calendar.SECOND );
GregorianCalendar gCalendar = new GregorianCalendar( year,
month, day, hour, minute, second );
spinner.setValue( gCalendar.getTime() );
repaint();
}
}
);
container.add( panel, BorderLayout.CENTER );
container.add( spinner, BorderLayout.SOUTH );
setSize( 250, 280 );
setVisible( true );
setResizable( false );
thread = new Thread( this );
thread.start();
} 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询