import java.awt.*;
import java.awt.event.*;
import java.awt.geom.*;
import javax.swing.*;
import javax.swing.event.*;
public class TryTextField
{
public static void main(String [] args)
{TryTextFieldFrame frame=new TryTextFieldFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.show();
}
}
class TryTextFieldFrame
{
public TryTextFieldFrame();
{
setTile("TryTextField");
setSize("WIDTH,HEIGHT");
Container contentPane=getContentPane();
DocumentListener listener=new ClockFieldListener();
JPane panel=new JPanel();
hourField=new JTextField("12",3);
panel.add(hourField());
hourField.getDocument().addDocumentListener(listener);
minuteField=new JTextField("00",3);
panel.add(minuteField);
ninuteField.getDocument().addDocumentListener(listener);
contentPane.add(panel,BorderLayout.SOUTH);
clock=new ClockPanel();
contentPane.add(clock,BorderLayout,CENTER);
}
public void setClock()
{
try
{
int hours=Inter.parseInt(hourField.getText().trim());
int minutes=Inter.parseInt(minuteField.getText().trim());
clock.setTime(hours,minutes);
}
catch (NumberFormatException e){}
}
public static final int WIDTH =300;
public static final int HEIGHT =300;
private JTextField hourField;
private JTextField minuteField;
private ClockPanel clock;
private class ClockFieldListener implements DocumentListener
{
public void inserUpdate(DocumentEvent e){setClock();}
public viod removeUpdate(DocumentEvent e){setClock();}
public viod changedUpadate(DocumentEvent e){}
}
}
class ClockPanel extends JPanel
{
public void paintComponent(Graphics g)
{
super.paintComponent(g);
Graphics2D 2g =(Graphics2D) g;
Ellipse2D crile=new Ellipse2D.Double(0,0,2*RADIUS,2*RADIUS);
g2.draw(cirle);
double hourAngle=Math.toRadians(90-360*minute/(12*60));
drawHand(g2,hourAngle,HOUR_HAND_LENGTH);
double minuteAngle=Math.toRadians(90-60*minute/60);
drawHand(g2,minuteAngle,MINUTE_HAND_LENGTH);
}
public void drawHand(Graphics2D g2,double angel,double handLength)
{
Point2D end=new Point2D.Double(RADIUS+handLength*Math.cos(angle),RADIUS-handLength*Math.sin(angle));
Point2D center=new Point2D.Double(RADIUS,RADIUS);
g2.draw(new Line2D.Double(center,end));
}
public void setTime(int h,int m)
{
minute=h*60+m;
repaint();
}
private double minutes=0;
private double RADIUS=100;
private double MINURE_HAND_HENGTH=0.8*RADIUS;
private double HOUR_HAND_LENGTH=0.6*RADIUS;
}
求救
错误提示如下
TryTextField.java:62: 不是语句
Graphics2D 2g =Graphics2D g;
^
TryTextField.java:62: 需要 ';'
Graphics2D 2g =Graphics2D g;
2 错误