Eu compilo isto e dá java.lang.NullpointerException.
vc deverá complilar pelo Exercísio TimeTest3 . appletviewer TimeTest3.html
OK
Me ajudem
//Fig. 8.9
//Definição da classe Time3 com métodos set e get
package com.deitel.jhtp4.ch08;
//Pacotes do núcleo de Java
import java.text.DecimalFormat;
public class Time3 extends Object{
private int hour;
private int minute;
private int second;
public Time3(){
setTime(0, 0, 0);
}
public Time3(int h){
setTime( h, 0, 0 );
}
public Time3( int h, int m){
setTime( h, m, 0);
}
public Time3( int h, int m, int s){
setTime( h, m , s);
}
public Time3(Time3 time){
setTime( time.getHour(), time.getMinute(),
time.getSecond());
}
public void setTime( int h, int m, int s){
setHour( h );
setMinute( m );
setSecond( s );
}
public void setHour( int h ){
hour = ( ( h >= 0 && h < 24) ? h : 0);
}
public void setMinute( int m){
minute = ( ( m >= 0 && m < 60 ) ? m : 0);
}
public void setSecond( int s){
second = ( ( s >= 0 && s < 60 ) ? s : 0);
}
public int getHour(){
return hour;
}
public int getMinute(){
return minute;
}
public int getSecond(){
return second;
}
public String toUniversalString(){
DecimalFormat twoDigits = new DecimalFormat("00");
return twoDigits.format( getHour() ) + ":" +
twoDigits.format( getMinute() ) + ":" +
twoDigits.format( getSecond() );
}
public String toString(){
DecimalFormat twoDigits = new DecimalFormat("00");
return ( ( getHour() == 12 || getHour() == 0) ?
12 : getHour() % 12 ) + ":" +
twoDigits.format( getMinute() ) + ":" +
twoDigits.format( getSecond() ) +
( getHour() < 12 ? " AM" : " PM");
}
}
O outro é
//Fig.8.9
//Demostrando os métodos set e get da classe Time3
//Pacotes do núcleo de Java
import java.awt.<em>;
import java.awt.event.</em>;
//Pacotes de extensão de Java
import javax.swing.*;
//Pacoted Deitel
import com.deitel.jhtp4.ch08.Time3;
public class TimeTest3 extends JApplet
implements ActionListener{
private Time3 time;
private JLabel hourLabel, minuteLabel, secondLabel;
private JTextField hourField, minuteField,
secondField, displayField;
private JButton tickButton;
//cria objeto Time3 e configura GUI
public void init(){
Time3 time = new Time3();
Container container = getContentPane();
container.setLayout( new FlowLayout() );
//configura hourLabel e hourField
hourLabel = new JLabel("Set Hour");
hourField = new JTextField(10);
hourField.addActionListener(this);
container.add( hourLabel);
container.add( hourField);
//configura minuteLabel e minuteField
minuteLabel = new JLabel("Set Minute");
minuteField = new JTextField(10);
minuteField.addActionListener( this );
container.add( minuteLabel);
container.add( minuteField);
//configura secondLabel e secondField
secondLabel = new JLabel("Set Second");
secondField = new JTextField(10);
secondField.addActionListener(this);
container.add(secondLabel);
container.add(secondField);
//configura displayField
displayField = new JTextField(30);
displayField.setEditable(false);
container.add(displayField);
//configura tickButton
tickButton = new JButton("Add 1 to Second");
tickButton.addActionListener(this);
container.add(tickButton);
}
//trata eventos dobotão e do campo de texto
public void actionPerformed( ActionEvent actionEvent){
//processa o evento tickButton
if ( actionEvent.getSource() == tickButton )
tick();
//processa o evento hourField
else if ( actionEvent.getSource() == hourField){
time.setHour(
Integer.parseInt( actionEvent.getActionCommand() ) );
hourField.setText("");
}
//processa o evento minuteField
else if( actionEvent.getSource() == minuteField ){
time.setMinute(
Integer.parseInt( actionEvent.getActionCommand() ) );
minuteField.setText("");
}
//processa o evento secondField
else if( actionEvent.getSource() == secondField){
time.setSecond(
Integer.parseInt( actionEvent.getActionCommand() ) );
secondField.setText("");
}
updateDisplay(); //atualiza displayField e a barra de Status
}
//atuaçiza displayField e a barra de status do contêiner do applet
public void updateDisplay(){
displayField.setText("Hour: " + time.getHour() +
";Minute: " + time.getMinute() +
";Second: " + time.getSecond() );
showStatus("Standard time is: " + time.toString() +
"; Universal time is: " + time.toUniversalString() );
}
//soma um ao segundo e atualiza hora e minuto se necessário
public void tick(){
time.setSecond( ( time.getSecond() + 1) % 60);
if( time.getSecond() == 0){
time.setMinute( ( time.getMinute() + 1) % 60);
if( time.getMinute() == 0)
time.setHour( ( time.getHour() + 1 ) % 24 );
}
}
}//fim da classe TimeTest3


