exercise13_7.java

来自「Introduction to java programming 一书中所有编程」· Java 代码 · 共 47 行

JAVA
47
字号
// Exercise13_7.java: Draw a star
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class Exercise13_7 extends JFrame implements ActionListener {
  private JTextField jtfHour = new JTextField(2);
  private JTextField jtfMinute = new JTextField(2);
  private JTextField jtfSecond = new JTextField(2);
  private StillClock clock = new StillClock();

  public Exercise13_7() {
    Container container = getContentPane();
    JPanel p = new JPanel();
    p.add(new JLabel("Hour"));
    p.add(jtfHour);
    p.add(new JLabel("Minute"));
    p.add(jtfMinute);
    p.add(new JLabel("Second"));
    p.add(jtfSecond);

    container.add(p, BorderLayout.SOUTH);
    container.add(clock, BorderLayout.CENTER);

    jtfHour.addActionListener(this);
    jtfMinute.addActionListener(this);
    jtfSecond.addActionListener(this);
  }

  public static void main(String[] args) {
    Exercise13_7 frame = new Exercise13_7();
    frame.setSize(400, 400);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setTitle("Exercise13_7");
    frame.setVisible(true);
  }

  public void actionPerformed(ActionEvent e) {
    if (e.getSource() == jtfHour)
      clock.setHour(Integer.parseInt(jtfHour.getText()));
    else if (e.getSource() == jtfMinute)
      clock.setMinute(Integer.parseInt(jtfMinute.getText()));
    else if (e.getSource() == jtfSecond)
      clock.setSecond(Integer.parseInt(jtfSecond.getText()));
  }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?